Last active
November 27, 2018 14:35
-
-
Save konjoot/ad7b7b55fc5a4a8a89b2370ae989bea8 to your computer and use it in GitHub Desktop.
List tables sorted by size with rows count by schema (PostgreSQL only)
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_name, | |
pg_relation_size(quote_ident(table_name)) AS size, | |
n_live_tup AS rows | |
FROM information_schema.tables AS it | |
JOIN pg_stat_user_tables AS ut | |
ON it.table_name = ut.relname | |
AND it.table_schema = ut.schemaname | |
WHERE table_schema = 'public' | |
ORDER BY 2 DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment