Skip to content

Instantly share code, notes, and snippets.

@fervic
Created August 15, 2017 02:44
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 fervic/e9ae3ad07a5856a941ebf3d73ff973c6 to your computer and use it in GitHub Desktop.
Save fervic/e9ae3ad07a5856a941ebf3d73ff973c6 to your computer and use it in GitHub Desktop.
Table sizes in Redshift
-- Get table sizes in Gigabytes sorted by size descending
SELECT name AS "table", substring(datname, 1, 15) AS "database", ROUND((COUNT(*) / 1024.0),2) AS "GB"
FROM stv_blocklist
INNER JOIN (
SELECT DISTINCT id, name, datname, db_id FROM stv_tbl_perm
INNER JOIN pg_database
ON stv_tbl_perm.db_id = pg_database.oid
) AS t
ON t.id = stv_blocklist.tbl
GROUP BY name, datname
ORDER BY "GB" DESC
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment