Created
July 17, 2019 19:02
-
-
Save ilyaevseev/69e1cc1b1ff93db46bbb2ebab0df5b33 to your computer and use it in GitHub Desktop.
This file contains 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_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", | |
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 2 DESC LIMIT 10 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment