Created
March 11, 2019 11:17
-
-
Save Barathchander/9f4d14b54b18b069640097141e7c4a73 to your computer and use it in GitHub Desktop.
query to get table level size sort by space used
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select trim(pgdb.datname) as Database, trim(pgns.nspname) as Schema, trim(a.name) as Table, | |
c.rows, ((b.mbytes/part.total::decimal)*100)::decimal(5,3) as pct_of_total, b.mbytes, b.unsorted_mbytes | |
from stv_tbl_perm a | |
join pg_class as pgtbl on pgtbl.oid = a.id | |
join pg_namespace as pgns on pgns.oid = pgtbl.relnamespace | |
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 id, sum(rows) as rows from stv_tbl_perm group by id) c on a.id=c.id | |
join (select sum(capacity) as total from stv_partitions where part_begin=0) as part on 1=1 | |
where a.slice=0 | |
order by 6 desc, db_id, name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment