Created
April 26, 2023 08:33
-
-
Save monosoul/0564d20949f80fdd60aa35ebbf781fcd to your computer and use it in GitHub Desktop.
Get all table/partition sizes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT nspname || '.' || 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) | |
LEFT OUTER JOIN pg_inherits I ON (C.relfilenode = I.inhrelid OR C.relfilenode = I.inhparent) | |
WHERE nspname NOT IN ('pg_catalog', 'information_schema') | |
AND C.relkind <> 'i' | |
AND nspname !~ '^pg_toast' | |
AND I.inhrelid is null | |
UNION ALL | |
select nspname || '.' || relname AS "relation", | |
pg_size_pretty(sum(pg_relation_size(inhrelid))) AS "total_size" | |
FROM pg_inherits I | |
LEFT JOIN pg_class C ON (C.oid = I.inhparent) | |
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) | |
GROUP BY nspname,relname | |
ORDER BY 1,2 | |
-- https://dba.stackexchange.com/a/134574 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment