1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
SELECT pg_size_pretty(pg_relation_size('my_table')); SELECT pg_size_pretty(pg_total_relation_size('my_table')); SELECT pg_size_pretty(pg_indexes_size('my_table')); SELECT relname AS "relation", pg_size_pretty(pg_total_relation_size (C .oid)) AS "total_size" FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) WHERE nspname NOT IN ('pg_catalog', 'information_schema') AND C .relkind <> 'i' AND nspname !~ '^pg_toast' ORDER BY pg_total_relation_size(C.oid) DESC LIMIT 5; SELECT pg_size_pretty(pg_database_size ('my_database')); SELECT pg_database.datname, pg_size_pretty(pg_database_size(pg_database.datname)) AS size FROM pg_database; |
Узнать размер всех таблиц базы данных можно с помощью такого запроса:
1 2 3 4 5 6 7 8 9 10 |
SELECT relname AS name, relfilenode AS oid, (relpages::bigint * 8192 / (1024*1024))::bigint AS size_mb, reltuples AS cnt FROM pg_class WHERE relname IN ( SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = 'public' ) ORDER BY cnt DESC; |