PostgreSQL查看数据库,表和索引的大小

时间:2022-10-01 12:22:21
1. 查看数据库大小。    select pg_size_pretty(pg_database_size('db_name'));    通过 pgAdmin 我们可以看到,在 PostgreSQL(pg_catalog) 下有如下两个视图:  pg_stat_user_tables,pg_stat_user_indexes。可以通过它们来查看表及索引的大小。    2. 查看所有索引的大小。    select indexrelname,         pg_size_pretty(pg_relation_size(indexrelname))  from pg_stat_user_indexes  where schemaname = 'public'  order by pg_relation_size(indexrelname) desc;    3. 查所有表的大小。    select relname,         pg_size_pretty(pg_relation_size(relname))  from pg_stat_user_tables  where schemaname = 'public'  order by pg_relation_size(relname) desc;    4. 查看单个表的大小。    select pg_size_pretty(pg_relation_size('table_name'));