赞
踩
分享一个脚本,PostgreSQL 查看表段大小(包含分区表)及条目数
select * from (select t.relname, (case when r.relkind = 'p' then 'Y' else 'N' end) as partition_YN, --pg_size_pretty(pg_relation_size(relid)) as "table_size", pg_relation_size(relid)/1024/1024 as "size_Mb", to_char(r.reltuples,'999999999999999999999') as "table_cnt" from pg_stat_user_tables t inner join pg_namespace n on t.schemaname = n.nspname inner join pg_class r on r.relname = t.relname and r.relnamespace = n.oid and r.oid not in (select inhrelid from pg_inherits where inhparent in (select partrelid from pg_partitioned_table)) --排除分区 where t.schemaname='mapr' union all --查看分区表大小 select t1.relname as parent_tab, (case when t1.relkind = 'p' then 'Y' else 'N' end) as partition_YN, sum(pg_table_size(c.oid))/1024/1024 as "size_Mb", --i.inhparent , to_char(sum(c.reltuples),'999999999999999999999') as "table_cnt" FROM pg_class t1 join pg_inherits i on t1.oid = i.inhparent join pg_catalog.pg_class c --for partition on c.oid = i.inhrelid where t1.relnamespace = (select oid from pg_namespace where nspname = 'mapr') and t1.relkind IN ('r','p') group by t1.relname,i.inhparent ,t1.relkind ) tt order by 3 desc ;
效果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。