当前位置:   article > 正文

pg统计磁盘占用大小_pg查询表空间使用率

pg查询表空间使用率

目录

一、查看所有表所占磁盘空间大小

二、查看每个表所占用磁盘空间大小

三、查看数据库大小

四、查看表大小

五、查看索引所占磁盘空间大小

六、查看表空间大小


一、查看所有表所占磁盘空间大小

  1. select 
  2.     sum(t.size) 
  3. from (
  4.     SELECT 
  5.           table_schema || '.' || table_name AS table_full_name
  6.         , pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')AS size
  7.     FROM information_schema.tables
  8.     ORDER by pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
  9.     ) t
  10. ;

二、查看每个表所占用磁盘空间大小

  1. SELECT 
  2.       table_schema || '.' || table_name AS table_full_name
  3.     , pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') AS size_bytes
  4.     , pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')/1024/1024 as size_mb
  5.     , pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')/1024/1024/1024 as size_gb
  6. FROM information_schema.tables
  7. ORDER by pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
  8. ;

三、查看数据库大小

--查看xx数据库大小

select pg_database_size('xx');

--查看所有数据库大小

  1. select
  2. pg_database.datname
  3. ,pg_database_size(pg_database.datname) AS size
  4. from pg_database;

四、查看表大小

--查看表大小

select pg_relation_size('table_name');   --bytes

--以KB\MB\GB方式查看表大小

select pg_size_pretty(pg_relation_size('table_name'));  

--查看表的总大小,包括索引大小

select pg_size_pretty(pg_total_relation_size('table_name'));  

五、查看索引所占磁盘空间大小

select pg_size_pretty(pg_relation_size('table_pkey')); 

六、查看表空间大小

--查看表空间

select spcname from pg_tablespace; 

--查看表空间大小

select pg_size_pretty(pg_tablespace_size('pg_default')); 

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

闽ICP备14008679号