我来自Oracle的Postgres,并寻找一种方法来找到表和索引大小,以字节/ MB / GB / etc,或甚至更好的所有表的大小。在Oracle中,我有一个讨厌的长查询,查看user_lobs和user_segments回答一个答案。我假设在Postgres有一些我可以在information_schema表中使用,但我没有看到在哪里。提前致谢。
尝试
@L_301_0@.一个例子:
原文链接:https://www.f2er.com/postgresql/193885.htmlSELECT pg_size_pretty(pg_total_relation_size('"schema"."Table"'));
对于所有的表,一些东西沿线:
SELECT table_schema || '.' || table_name AS table_full_name,pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size FROM information_schema.tables ORDER BY pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC
编辑:为方便起见,以下是@phord提交的查询:
SELECT table_name,pg_size_pretty(table_size) AS table_size,pg_size_pretty(indexes_size) AS indexes_size,pg_size_pretty(total_size) AS total_size FROM ( SELECT table_name,pg_table_size(table_name) AS table_size,pg_indexes_size(table_name) AS indexes_size,pg_total_relation_size(table_name) AS total_size FROM ( SELECT ('"' || table_schema || '"."' || table_name || '"') AS table_name FROM information_schema.tables ) AS all_tables ORDER BY total_size DESC ) AS pretty_sizes
我稍微修改它使用pg_table_size()来包含元数据,并使大小相加。