Skip to content

Instantly share code, notes, and snippets.

@t0mdicks0n
Last active February 28, 2019 09:19
Show Gist options
  • Save t0mdicks0n/75057151eccaed9eff20431ff9ae80f0 to your computer and use it in GitHub Desktop.
Save t0mdicks0n/75057151eccaed9eff20431ff9ae80f0 to your computer and use it in GitHub Desktop.
List disk usage of PSQL instance per table in the schema public
SELECT
table_name,
pg_size_pretty(t_size) AS size_pretty
FROM (
SELECT
table_name,
pg_relation_size(quote_ident(table_name)) AS t_size
FROM information_schema.tables
WHERE table_schema = 'public'
UNION ALL
SELECT
'--ALL TABLES--'::text AS table_name,
SUM(pg_relation_size(quote_ident(table_name))) AS t_size
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY t_size DESC
) C;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment