Skip to content

Instantly share code, notes, and snippets.

@Jeetah
Last active September 11, 2023 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeetah/e7e5a4cfc412d04346c5b41a1729b7a5 to your computer and use it in GitHub Desktop.
Save Jeetah/e7e5a4cfc412d04346c5b41a1729b7a5 to your computer and use it in GitHub Desktop.
Postgres table sizes sorted
SELECT table_name,
pg_size_pretty(total_size) AS size
FROM (
SELECT table_name,
pg_total_relation_size(table_schema || '.' || table_name) AS total_size
FROM information_schema.tables
WHERE table_schema = 'public' -- Replace with your schema name if needed
) AS table_sizes
ORDER BY total_size DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment