【KingbaseES】数据库如何查询数据库,模式及表大小

新建数据kingbase及kingbase模式

CREATE DATABASE kingbase OWNER kingbase;
CREATE SCHEMA kingbase AUTHORIZATION "kingbase";

在数据库kingbase的kingbase模式下新建两张测试表test_size,test_size1并插入数据

CREATE TABLE "kingbase"."test_szie" (
	"id" integer AUTO_INCREMENT,
	"name" character varying(8 char) NOT NULL,
	"create_time" timestamp without time zone NOT NULL,
	"update_time" timestamp without time zone NOT NULL,
	"in_number" integer NULL,
	"number" integer NULL,
	CONSTRAINT "con_kingbase_test_szie_id" PRIMARY KEY (id)
);

ALTER TABLE "kingbase".test_szie SET
TABLESPACE "sys_default";

INSERT INTO "kingbase"."test_szie" ("number","name", "create_time", "update_time", "in_number")
VALUES(generate_series(1,99999), '张三',  now(), now(), random());

CREATE TABLE "kingbase"."test_szie1" (
	"id" integer AUTO_INCREMENT,
	"name" character varying(8 char) NOT NULL,
	"create_time" timestamp without time zone NOT NULL,
	"update_time" timestamp without time zone NOT NULL,
	"in_number" integer NULL,
	"number" integer NULL,
	CONSTRAINT "con_kingbase_test_szie_id" PRIMARY KEY (id)
);

ALTER TABLE "kingbase".test_szie1 SET
TABLESPACE "sys_default";


ALTER TABLE "kingbase".test_szie1 SET
TABLESPACE "sys_default";

INSERT INTO "kingbase"."test_szie1" ("number","name", "create_time", "update_time", "in_number")
VALUES(generate_series(1,99999), '张三',  now(), now(), random());

查询数据库大小

select sys_database_size('kingbase')

在这里插入图片描述

select sys_size_pretty(sys_database_size('kingbase'));

在这里插入图片描述

查询所有数据库大小

select sys_database.datname, sys_database_size(sys_database.datname) as size from sys_database order by size desc;

在这里插入图片描述

查询kingbase模式大小

SELECT 
    sys_size_pretty(sum(table_size)::bigint) as "disk space",
    sum(table_size)::bigint as "total size"
FROM (
     SELECT sys_catalog.sys_namespace.nspname as schema_name,
         sys_total_relation_size(sys_catalog.sys_class.oid) as table_size
     FROM  sys_catalog.sys_class 
         JOIN sys_catalog.sys_namespace 
             ON relnamespace = sys_catalog.sys_namespace.oid
     WHERE sys_catalog.sys_namespace.nspname = 'kingbase'
) t

在这里插入图片描述

查询库下所有模式大小

SELECT schema_name, 
    sys_size_pretty(sum(table_size)::bigint) as "disk space",
    sum(table_size)::bigint as "total size"
FROM (
     SELECT sys_catalog.sys_namespace.nspname as schema_name,
         sys_total_relation_size(sys_catalog.sys_class.oid) as table_size
     FROM  sys_catalog.sys_class 
         JOIN sys_catalog.sys_namespace 
             ON relnamespace = sys_catalog.sys_namespace.oid
     WHERE sys_catalog.sys_namespace.nspname NOT IN ('information_schema','src_restrict','anon','dbms_sql','xlog_record_read','pg_catalog','pg_bitmapindex','sys_catalog','sysaudit','sysmac','sys')
) t
GROUP BY schema_name

在这里插入图片描述

查询单表大小

select sys_size_pretty(sys_relation_size('kingbase.test_szie'));

在这里插入图片描述

查询模式下所有表大小

SELECT
table_name,
sys_size_pretty(table_size) AS table_size,
sys_size_pretty(indexes_size) AS indexes_size,
sys_size_pretty(total_size) AS total_size
FROM (
SELECT
table_name,
sys_table_size(table_name) AS table_size,
sys_indexes_size(table_name) AS indexes_size,
sys_total_relation_size(table_name) AS total_size
FROM (
SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name
FROM information_schema.TABLES WHERE table_schema ='kingbase'
) AS all_tables
ORDER BY total_size DESC
) AS pretty_sizes

在这里插入图片描述文章来源地址https://uudwc.com/A/OmrxN

原文地址:https://blog.csdn.net/sinat_36528886/article/details/131636496

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年07月14日 10:38
STM32驱动ADS1256串口输出-AD转换
下一篇 2023年07月14日 10:43