1. 查询数据库大小
-
-- 查询单个数据库大小
-
select pg_size_pretty(pg_database_size('postgres')) as size;
-
-
-- 查询所有数据库大小
-
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 relname, pg_size_pretty(pg_relation_size(relid)) as size from pg_stat_user_tables;
-
-
-- 查询单个表的总大小,包括该表的索引大小
-
select pg_size_pretty(pg_total_relation_size('tab')) as size;
-
-
-- 查询所有表的总大小,包括其索引大小
-
select relname, pg_size_pretty(pg_total_relation_size(relid)) as size from pg_stat_user_tables;
3. 查询索引大小(暂时没有一次性查询所有索引大小的函数)
-
-- 查询单个索引大小
-
select pg_size_pretty(pg_relation_size('myindex')) as size;
4. 查询表空间大小
-
-- 查询单个表空间大小
-
select pg_size_pretty(pg_tablespace_size('pg_default')) as size;
-
-
-- 查询所有表空间大小
-
select spcname, pg_size_pretty(pg_tablespace_size(spcname)) as size from pg_tablespace;
-
-- 或
-
select spcname, pg_size_pretty(pg_tablespace_size(oid)) as size from pg_tablespace;