Skip to content

Instantly share code, notes, and snippets.

@belsrc
Last active January 12, 2016 15:47
Show Gist options
  • Save belsrc/ce45581a06e4f05446e0 to your computer and use it in GitHub Desktop.
Save belsrc/ce45581a06e4f05446e0 to your computer and use it in GitHub Desktop.
Show relation size in Postgres
-- Relations, as in, tables and indexes
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_relation_size(PC.oid)) AS "size"
FROM pg_class PC
LEFT JOIN pg_namespace NS ON (NS.oid = PC.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND nspname !~ '^pg_toast'
ORDER BY pg_relation_size(PC.oid) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment