Skip to content

Instantly share code, notes, and snippets.

@mykwillis
Created September 30, 2015 14:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mykwillis/e5ce0a9808154270dcfb to your computer and use it in GitHub Desktop.
Save mykwillis/e5ce0a9808154270dcfb to your computer and use it in GitHub Desktop.
Get the size on disk of Redshift tables
select trim(pgdb.datname) as Database,
trim(a.name) as Table, ((b.mbytes/part.total::decimal)*100)::decimal(5,2) as pct_of_total, b.mbytes, b.unsorted_mbytes
from stv_tbl_perm a
join pg_database as pgdb on pgdb.oid = a.db_id
join (select tbl, sum(decode(unsorted, 1, 1, 0)) as unsorted_mbytes, count(*) as mbytes
from stv_blocklist group by tbl) b on a.id=b.tbl
join ( select sum(capacity) as total
from stv_partitions where part_begin=0 ) as part on 1=1
where a.slice=0
order by 3 desc, db_id, name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment