查看库大小
select
d."oid" as "对象ID", d."datname" as "实例名", d."owner" as "所属者",
pg_catalog.pg_size_pretty(d."size") as "大小"
from (
select
oid, datname,
pg_catalog.pg_get_userbyid(datdba) as "owner",
pg_catalog.pg_database_size(datname) as "size"
from pg_catalog.pg_database
where pg_catalog.has_database_privilege(datname, 'CONNECT')
order by "size" desc
) as d
执行结果:
查看表大小
select
table_full_name as "表名",
pg_catalog.pg_size_pretty(table_size) as "大小"
from (
select
table_schema || '.' || table_name as table_full_name,
pg_catalog.pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') as table_size
from information_schema.tables
) as t
order by table_size desc, table_full_name
执行结果: