我正在运行PostgreSQL 9.4.6,我有一个运行
的78GB数据库SELECT pg_size_pretty(pg_database_size('<db name>')) As fulldbsize;
为了追踪我的数据库如此之大的原因,我尝试了以下方法: -
SELECT relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
但是在将结果表格加起来时,我得到了大约15GB。
在我的数据库中使用我的空间是什么?我还可以运行哪些命令?
答案 0 :(得分:1)
您还可以获取有关所有对象及其各自尺寸的信息
SELECT
relname AS objectname,
relkind AS objecttype,
reltuples AS "#entries", pg_size_pretty(relpages::bigint*8*1024) AS size
FROM pg_class
WHERE relpages >= 8
ORDER BY relpages DESC;
这应该详细说明:
答案 1 :(得分:1)
这将列出所有对象的大小:
SELECT relname, pg_total_relation_size(oid)
FROM pg_class
ORDER BY 2 DESC;
这应该有助于您考虑数据库大小。