Skip to content

Instantly share code, notes, and snippets.

@fitnr
Created March 28, 2021 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fitnr/63c14489d5c07c548ac644e19db3aab1 to your computer and use it in GitHub Desktop.
Save fitnr/63c14489d5c07c548ac644e19db3aab1 to your computer and use it in GitHub Desktop.
get table and index sizes in postgresql
SELECT
nspname,
relname,
relkind,
to_char(round(reltuples::numeric, -2), '999,999,999,999,999') as est_row_count,
pg_size_pretty(pg_indexes_size(c.oid)) index_size,
pg_size_pretty(pg_relation_size(c.oid)) table_size
FROM pg_class c
LEFT JOIN pg_namespace n ON c.relnamespace = n.oid
WHERE (nspname <> ALL (ARRAY['pg_catalog', 'information_schema']::name[]))
AND n.nspname !~ '^pg_toast'
AND c.relkind = 'r';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment