Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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