赞
踩
select pg_size_pretty (pg_database_size(‘test_database’);
select datname, pg_size_pretty (pg_database_size(datname)) AS size from pg_database;
select pg_size_pretty(pg_relation_size(‘mytab’)) as size;
select pg_size_pretty(pg_total_relation_size(‘tab’)) as size;
select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables order by pg_relation_size(relid) desc;
– 查询分区表有哪些子表,partition_table_name是主表,还可能会查出来主键,唯一键等;需要再加reltype>0筛选出表名
SELECT * FROM pg_class
where relname like ‘partition_table_name_%’ and reltype>0;
– 查询每个子表标名,表的大小,及包括索引的总大小,并按总大小倒序排列;
SELECT relname,pg_size_pretty(pg_relation_size(relname::text)) as tableSize,pg_size_pretty(pg_total_relation_size(relname::text)) as tableTotalSize,pg_total_relation_size(relname::text) as total, FROM pg_class
where relname like ‘partition_table_name_%’ and reltype>0 order by total desc;
– 查询分区表总大小
select sum(total),pg_size_pretty(sum(total)) from (SELECT relname,pg_size_pretty(pg_relation_size(relname::text)) as tableSize,pg_size_pretty(pg_total_relation_size(relname::text)) as tableTotalSize,pg_total_relation_size(relname::text) as total, FROM pg_class
where relname like ‘partition_table_name_%’ and reltype>0 order by total desc) t
select relname as TABLE_NAME, reltuples as rowCounts from pg_class where relkind = ‘r’ order by rowCounts desc
SELECT table_name, pg_size_pretty(table_size) AS table_size, pg_size_pretty(indexes_size) AS indexes_size, pg_size_pretty(total_size) AS total_size FROM ( SELECT table_name, pg_table_size(table_name) AS table_size, pg_indexes_size(table_name) AS indexes_size, pg_total_relation_size(table_name) AS total_size FROM ( SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name FROM information_schema.tables ) AS all_tables ORDER BY total_size DESC ) AS pretty_sizes;
select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。