Skip to content

Instantly share code, notes, and snippets.

@tylerpearson
Created March 16, 2017 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerpearson/1d57da99429845d245b241d64be9922a to your computer and use it in GitHub Desktop.
Save tylerpearson/1d57da99429845d245b241d64be9922a to your computer and use it in GitHub Desktop.
redshift vacuuming
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