Skip to content

Instantly share code, notes, and snippets.

@mrsarm
Created November 22, 2022 15:38
Show Gist options
  • Save mrsarm/bb0f96141853a2c1c97b6fedb07eb8a3 to your computer and use it in GitHub Desktop.
Save mrsarm/bb0f96141853a2c1c97b6fedb07eb8a3 to your computer and use it in GitHub Desktop.
Postgres DB utils SQL scripts
-- DB size in bytes
SELECT pg_size_pretty( pg_database_size('dbname') );
-- Table size in bytes
SELECT pg_size_pretty( pg_total_relation_size('tablename') );
-- All table sizes sorted by size desc
SELECT table_name, pg_size_pretty( pg_relation_size(quote_ident(table_name)) )
FROM information_schema.tables
WHERE table_schema = 'public'
ORDER BY pg_relation_size(quote_ident(table_name)) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment