Created
October 15, 2023 06:03
-
-
Save theY4Kman/52b3abd7cc44ae2d55f9db19f5f9e9ec to your computer and use it in GitHub Desktop.
Show sizes of all tables in the public schema, itemized for tablespace alone, indexes size, and TOAST 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
-- Sizes of all tables in the public schema | |
SELECT | |
table_name AS "Table", | |
pg_size_pretty(table_size) AS "Table Size", | |
pg_size_pretty(indexes_size) AS "Indexes Size", | |
pg_size_pretty(toast_size) AS "Toast Size", | |
pg_size_pretty(total_size) AS "Total Size" | |
FROM ( | |
SELECT | |
table_name, | |
pg_relation_size(table_identifier) AS table_size, | |
pg_indexes_size(table_identifier) AS indexes_size, | |
pg_table_size(table_identifier) - pg_relation_size(table_identifier) AS toast_size, | |
pg_total_relation_size(table_identifier) AS total_size | |
FROM ( | |
SELECT | |
table_name::text AS table_name, | |
('"' || table_schema || '"."' || table_name || '"') AS table_identifier | |
FROM information_schema.tables | |
WHERE table_schema = 'public' | |
) AS all_tables | |
ORDER BY total_size DESC | |
) AS pretty_sizes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment