Skip to content

Instantly share code, notes, and snippets.

@evilz
Created January 30, 2023 10:16
Show Gist options
  • Save evilz/9216eb30c527c152c69c5b19cb8e0822 to your computer and use it in GitHub Desktop.
Save evilz/9216eb30c527c152c69c5b19cb8e0822 to your computer and use it in GitHub Desktop.
PG table Size
select current_database() as database,
pg_size_pretty(total_database_size) as total_database_size,
schema_name,
table_name,
pg_size_pretty(total_table_size) as total_table_size,
pg_size_pretty(table_size) as table_size,
pg_size_pretty(index_size) as index_size
from ( select table_name,
table_schema as schema_name,
pg_database_size(current_database()) as total_database_size,
pg_total_relation_size(table_name) as total_table_size,
pg_relation_size(table_name) as table_size,
pg_indexes_size(table_name) as index_size
from information_schema.tables
where table_schema=current_schema()
order by total_table_size
) as sizes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment