Skip to content

Instantly share code, notes, and snippets.

@pingles
Created January 20, 2015 10:39
Show Gist options
  • Save pingles/453d0f62561e4e89be6f to your computer and use it in GitHub Desktop.
Save pingles/453d0f62561e4e89be6f to your computer and use it in GitHub Desktop.
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,
a.rows
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