Skip to content

Instantly share code, notes, and snippets.

@elliotcm
Created September 16, 2024 09:11
Show Gist options
  • Save elliotcm/000a3d092a158902c9c4f07624ea8eae to your computer and use it in GitHub Desktop.
Save elliotcm/000a3d092a158902c9c4f07624ea8eae to your computer and use it in GitHub Desktop.
PostgreSQL: 10 biggest tables by disk size, plus a row count estimate
with row_counts as (SELECT reltuples, relname FROM pg_class)
select
table_name,
pg_size_pretty(pg_total_relation_size(quote_ident(table_name))) as total_size,
row_counts.reltuples::decimal(38,0) as row_count
from information_schema.tables
join row_counts on table_name = row_counts.relname
where table_schema = 'public'
order by pg_total_relation_size(quote_ident(table_name)) desc
limit 10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment