postgresql 查看表格占用空间

那人,那事,那代码 / 2023-09-05 / 原文

http://www.linuxmysql.com/14/2022/1182.htm

select pg_size_pretty(pg_tablespace_size('pg_default'));
select pg_size_pretty(pg_relation_size('account_move_line'));
select sum(t.size) from (
SELECT table_schema || '.' || table_name AS table_full_name, 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
) t;

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;