Created
March 16, 2017 20:19
-
-
Save tylerpearson/1d57da99429845d245b241d64be9922a to your computer and use it in GitHub Desktop.
redshift vacuuming
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 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