--数据库中单个表的大小(不包含索引)@H_404_2@
select@H_404_2@ pg_size_pretty(pg_relation_size('表名'@H_404_2@));@H_404_2@
--查出所有表(包含索引)并排序@H_404_2@
SELECT@H_404_2@ table_schema || '.'@H_404_2@ || table_name AS@H_404_2@ table_full_name,pg_size_pretty(pg_total_relation_size('"'@H_404_2@ || table_schema || '"."'@H_404_2@ || table_name || '"'@H_404_2@)) AS@H_404_2@ size@H_404_2@ FROM@H_404_2@ information_schema.tables ORDER@H_404_2@ BY@H_404_2@ pg_total_relation_size('"'@H_404_2@ || table_schema || '"."'@H_404_2@ || table_name || '"'@H_404_2@) DESC@H_404_2@ limit 20@H_404_2@ --查出表大小按大小排序并分离data与index SELECT@H_404_2@ table_name,pg_size_pretty(table_size) AS@H_404_2@ table_size,pg_size_pretty(indexes_size) AS@H_404_2@ indexes_size,pg_size_pretty(total_size) AS@H_404_2@ total_size FROM@H_404_2@ ( SELECT@H_404_2@ table_name,pg_table_size(table_name) AS@H_404_2@ table_size,pg_indexes_size(table_name) AS@H_404_2@ indexes_size,pg_total_relation_size(table_name) AS@H_404_2@ total_size FROM@H_404_2@ ( SELECT@H_404_2@ ('"'@H_404_2@ || table_schema || '"."'@H_404_2@ || table_name || '"'@H_404_2@) AS@H_404_2@ table_name FROM@H_404_2@ information_schema.tables ) AS@H_404_2@ all_tables ORDER@H_404_2@ BY@H_404_2@ total_size DESC@H_404_2@ ) AS@H_404_2@ pretty_sizes@H_404_2@
原文链接:https://www.f2er.com/postgresql/193222.html