Skip to content

Instantly share code, notes, and snippets.

@nomeyer
Created February 12, 2016 15:26
Show Gist options
  • Save nomeyer/ff847703ac7a7f7fb5e0 to your computer and use it in GitHub Desktop.
Save nomeyer/ff847703ac7a7f7fb5e0 to your computer and use it in GitHub Desktop.
Query to get the size of a PostgreSQL database (public schema)
select
schemaname,
tablename,
pg_size_pretty(size) as size_pretty,
pg_size_pretty(total_size) as total_size_pretty
from (
select
*,
pg_relation_size(schemaname ||'.'|| tablename) as size,
pg_total_relation_size(schemaname ||'.'|| tablename) as total_size
from pg_tables
) as tables
where schemaname='public'
order by total_size desc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment