Last active
August 29, 2015 14:14
-
-
Save slpsys/0fdd3f831dc33d738335 to your computer and use it in GitHub Desktop.
This file contains 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 | |
cast(use2.usename as varchar(50)) as owner, | |
pgc.oid, | |
trim(pgdb.datname) as Database, | |
trim(pgn.nspname) as Schema, | |
trim(a.name) as Table, | |
(b.mbytes / 1024) gbytes, | |
a.rows, | |
((case when a.rows > 0 then b.mbytes / a.rows::real end) * 1024) kb_per_row, | |
round(b.mbytes / (sum(b.mbytes) over ())::real * 100, 4) pct_of_cluster | |
from | |
(select db_id, id, name, sum(rows) as rows | |
from stv_tbl_perm a | |
group by db_id, id, name | |
) as a | |
join pg_class as pgc on pgc.oid = a.id | |
left join pg_user use2 on (pgc.relowner = use2.usesysid) | |
join pg_namespace as pgn on pgn.oid = pgc.relnamespace | |
and pgn.nspowner > 1 | |
join pg_database as pgdb on pgdb.oid = a.db_id | |
join | |
(select tbl, count(*) as mbytes | |
from stv_blocklist | |
group by tbl | |
) b on a.id = b.tbl | |
order by mbytes desc, a.db_id, a.name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment