Skip to content

Instantly share code, notes, and snippets.

@62mkv
Created November 22, 2023 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 62mkv/6bd0967d6050cbd000d70f37b3f698dd to your computer and use it in GitHub Desktop.
Save 62mkv/6bd0967d6050cbd000d70f37b3f698dd to your computer and use it in GitHub Desktop.
Postgre recipes

Show table size in bytes with a percentage of all tables size

with t as (select * from pg_catalog.pg_tables
where schemaname = 'public'), 
sizes as (
select t.tablename, pg_total_relation_size(t.tablename::regclass) _size from t
order by 2 desc),
total as (select sum(_size) _size from sizes)
select sizes.tablename, sizes._size, to_char(sizes._size / total._size * 100.0,'999D99%') from sizes, total;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment