PG对象查看
查看表对象大小
SELECT pg_size_pretty(pg_relation_size('mhrordhu_shk.mut_kharedi_audit')); pg_size_pretty ---------------- 238 MB (1 row) SELECT pg_size_pretty(pg_total_relation_size('mhrordhu_shk.mut_kharedi_audit')); pg_size_pretty ---------------- 268 MB (1 row)
获取 Postgres 中所有数据库的列表及其大小(以 GB 为单位),按最大大小排序
SELECT pg_database.datname as "database_name", pg_database_size(pg_database.datname)/1024/1024/1024 AS size_in_GB FROM pg_database ORDER by size_in_GB DESC; database_name | size_in_gb ---------------+------------ mumbai | 422 template1 | 0 template0 | 0 (3 rows)
使用元命令获取 Postgres 中所有数据库及其大小的列表
nellore=# \l+
查找当前数据库中所有表大小的脚本。
SELECT table_schema || '.' || table_name AS TableName, pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize FROM information_schema.tables ORDER BY pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC