Last active
December 11, 2020 09:55
-
-
Save eusonlito/cc510af9c671fe883a8b9f8f40433809 to your computer and use it in GitHub Desktop.
List all postgresql tables with rows, contents size, index size and total size
This file contains 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 N.nspname || '.' || C.relname AS "relation", | |
S.n_live_tup AS "rows", | |
pg_size_pretty(pg_relation_size(C.oid)) AS "data_size", | |
pg_size_pretty(pg_indexes_size(C.oid)) AS "index_size", | |
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size" | |
FROM pg_class C | |
LEFT JOIN pg_namespace AS N ON (N.oid = C.relnamespace) | |
LEFT JOIN pg_stat_user_tables S ON (S.relname = C.relname) | |
WHERE ( | |
N.nspname NOT IN ('pg_catalog', 'information_schema') | |
AND N.nspname !~ '^pg_toast' | |
AND C.relkind <> 'i' | |
) | |
ORDER BY pg_total_relation_size(C.oid) DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment