Skip to content

Instantly share code, notes, and snippets.

@benjaminoakes
Created April 21, 2016 20:38
Show Gist options
  • Save benjaminoakes/9c5de0b25a943b33a0aed28aed561894 to your computer and use it in GitHub Desktop.
Save benjaminoakes/9c5de0b25a943b33a0aed28aed561894 to your computer and use it in GitHub Desktop.
Calculate size of PostgreSQL tables
dbname=# SELECT
dbname-#    relname as "Table",
dbname-#    pg_size_pretty(pg_total_relation_size(relid)) As "Size",
dbname-#    pg_size_pretty(pg_total_relation_size(relid) - pg_relation_size(relid)) as "External Size"
dbname-#    FROM pg_catalog.pg_statio_user_tables ORDER BY pg_total_relation_size(relid) DESC;
                      Table                       |    Size    | External Size
--------------------------------------------------+------------+---------------
table1                           | 19 GB      | 1665 MB
table2                           | 12 GB      | 9720 MB
table3                           | 10 GB      | 5903 MB
table4                           | 9096 MB    | 6179 MB
table5                           | 5961 MB    | 1642 MB
table7                           | 5260 MB    | 2239 MB
table8                           | 4522 MB    | 1254 MB
table9                           | 4211 MB    | 2336 MB
table10                           | 3617 MB    | 1190 MB
table11                           | 3558 MB    | 1978 MB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment