Created
April 3, 2021 17:02
-
-
Save doctaphred/b6d3d2b80d8caad66049a10ade084d8f to your computer and use it in GitHub Desktop.
Postgres table sizes
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 table_schema, | |
TABLE_NAME, | |
pg_size_pretty(SIZE) AS SIZE, | |
pg_size_pretty(total_size) AS total_size | |
FROM | |
(SELECT table_schema, | |
TABLE_NAME, | |
pg_relation_size(quote_ident(table_schema) || '.' || quote_ident(TABLE_NAME)) AS SIZE, | |
pg_total_relation_size(quote_ident(table_schema) || '.' || quote_ident(TABLE_NAME)) AS total_size | |
FROM information_schema.tables | |
WHERE table_type = 'BASE TABLE' | |
AND table_schema NOT IN ('information_schema', | |
'pg_catalog') | |
ORDER BY pg_relation_size(quote_ident(table_schema) || '.' || quote_ident(TABLE_NAME)) DESC, table_schema, | |
TABLE_NAME) x | |
ORDER BY x.SIZE DESC, x.total_size DESC, | |
table_schema, | |
TABLE_NAME; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment