Skip to content

Instantly share code, notes, and snippets.

@camallen
Created November 21, 2017 13:27
Show Gist options
  • Save camallen/d7a48ed67d0d3334a44640dad9c5c2f9 to your computer and use it in GitHub Desktop.
Save camallen/d7a48ed67d0d3334a44640dad9c5c2f9 to your computer and use it in GitHub Desktop.
List top 10 table sizes and report the index usage
select relation, pg_size_pretty(total_size), pg_size_pretty(size), pg_size_pretty(total_size - size) as index_size from
(SELECT relname AS "relation", pg_total_relation_size(C.oid) AS "total_size", pg_relation_size(C.oid) AS "size"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
) as derived
LIMIT 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment