Skip to content

Instantly share code, notes, and snippets.

@franciscocpg
Created January 18, 2021 01:10
Show Gist options
  • Save franciscocpg/9b97f6e5e166fe8a55a472caf65ce803 to your computer and use it in GitHub Desktop.
Save franciscocpg/9b97f6e5e166fe8a55a472caf65ce803 to your computer and use it in GitHub Desktop.
Postgres utils
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size",
indexrelname AS "Index",
pg_size_pretty(pg_total_relation_size(indexrelid)) As "Size",
pg_size_pretty(pg_total_relation_size(indexrelid) - pg_relation_size(indexrelid)) as "External Size"
FROM pg_catalog.pg_statio_user_indexes ORDER BY pg_total_relation_size(relid) DESC;
SELECT
relname as "Table",
pg_size_pretty(pg_total_relation_size(relid)) As "Size",
pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment