Created
March 28, 2021 15:19
-
-
Save fitnr/63c14489d5c07c548ac644e19db3aab1 to your computer and use it in GitHub Desktop.
get table and index sizes in postgresql
This file contains hidden or 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, | |
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