Postgresql相关数据库、表占用磁盘大小统计

1. 统计数据库大小

  • 单个数据库的大小

select pg_size_pretty (pg_database_size(‘test_database’);

  • 所有数据库的大小

select datname, pg_size_pretty (pg_database_size(datname)) AS size from pg_database;

2. 统计数据表大小

  • 单个表大小

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;

3. 所有表的记录数

select relname as TABLE_NAME, reltuples as rowCounts from pg_class where relkind = ‘r’ order by rowCounts desc

参考

  • https://www.cnblogs.com/liqiu/p/3922288.html
  • https://www.cnblogs.com/telwanggs/p/13645310.html
  • https://blog.csdn.net/leo_qi/article/details/84804644

你可能感兴趣的:(JAVA,数据库,新星计划,数据库,postgre,postgresql)