Debian Linux 服务器中的 Postgres 13 集群包含 30 个数据库。数据库包含许多模式。如何找到占用磁盘空间最多的最大文件?我试过了
select
relname::char(25),
pg_size_pretty(pg_total_relation_size(c.oid))::char(10) as totalsize,
n.nspname::char(12),
case
when c.relkind='i' then 'index'
when c.relkind='t' then 'toast'
when c.relkind='r' then 'table'
when c.relkind='v' then 'view'
when c.relkind='c' then 'composite type'
when c.relkind='S' then 'sequence'
else c.relkind::text
end ::char(14) as "type"
from
pg_class c
left join pg_namespace n on n.oid = c.relnamespace
left join pg_tablespace t on t.oid = c.reltablespace
where
(pg_total_relation_size(c.oid)>>21)>0 order by
pg_total_relation_size(c.oid) desc
但它只返回当前数据库的大小。如何在整个集群中运行?一些 plpgsql 脚本可以用于此。输出应包括数据库名称列。
客户端应用程序使用 psqlODBC 获取数据,因此最好避免使用 psql 或 shell 脚本。