当前位置:   article > 正文

分享一个脚本,PostgreSQL 查看表段大小(包含分区表)及条目数_pgsql查看每个分片的大小

pgsql查看每个分片的大小

分享一个脚本,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 ;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

效果如下:
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/266632
推荐阅读
相关标签
  

闽ICP备14008679号