Skip to content

Instantly share code, notes, and snippets.

@cesarmiquel
Last active August 16, 2016 22:15
Show Gist options
  • Save cesarmiquel/0c162cdcc714ee5ad77c91ddd661d008 to your computer and use it in GitHub Desktop.
Save cesarmiquel/0c162cdcc714ee5ad77c91ddd661d008 to your computer and use it in GitHub Desktop.
View used table space in Postgres database.
--
-- Source: https://wiki-bsse.ethz.ch/display/ITDOC/Check+size+of+tables+and+objects+in+PostgreSQL+database
--
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