PG如何查看分区表大小
查询分区表
工作中遇到pg分区表增长很快,需要分析分区表大小进行维护,网上搜的和 AI 回答的都不靠谱,这里记录一下。
SELECT
table_schema || '.' || table_name AS partitioned_table,
pg_size_pretty(pg_total_relation_size("'" || table_schema || "." || table_name || "'")) AS total_size
FROM
information_schema.tables
WHERE
table_name like 'your_schema%' -- 替换为你的schema名称,分区后缀适用%匹配
ORDER BY
pg_total_relation_size("'" || table_schema || "." || table_name || "'") DESC;