Created
March 14, 2017 16:29
-
-
Save tylerpearson/3db71338d37806b8aca923d4f1829a4c to your computer and use it in GitHub Desktop.
sizes of tables in redshift
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(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 ) AS 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 4 desc, db_id, name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment