Skip to content

Instantly share code, notes, and snippets.

@michaeltansg
Last active February 9, 2025 16:39
Show Gist options
  • Save michaeltansg/4e177f0cb56cd78fdfc058c11a320135 to your computer and use it in GitHub Desktop.
Save michaeltansg/4e177f0cb56cd78fdfc058c11a320135 to your computer and use it in GitHub Desktop.
SELECT
schemaname || '.' || tablename AS table_name,
pg_size_pretty(pg_total_relation_size(format('%I.%I', schemaname, tablename))) AS total_size,
pg_size_pretty(pg_relation_size(format('%I.%I', schemaname, tablename))) AS table_size,
pg_size_pretty(pg_indexes_size(format('%I.%I', schemaname, tablename))) AS index_size
FROM pg_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size(format('%I.%I', schemaname, tablename)) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment