Created
April 18, 2014 17:39
-
-
Save subelsky/11055667 to your computer and use it in GitHub Desktop.
Quick SQL command to find large tables in redshift
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
-- based on http://stackoverflow.com/questions/21767780/how-to-find-size-of-database-schema-table-in-redshift | |
SELECT name AS table_name, ROUND((COUNT(*) / 1024.0),2) as "Size in Gigabytes" | |
FROM stv_blocklist | |
INNER JOIN | |
(SELECT DISTINCT id, name FROM stv_tbl_perm) names | |
ON names.id = stv_blocklist.tbl | |
GROUP BY name | |
ORDER BY "Size in Gigabytes" DESC |
Show the database name
SELECT name AS table_name, datname, ROUND((COUNT(*) / 1024.0),2) as "Size in Gigabytes"
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
) names
ON names.id = stv_blocklist.tbl
GROUP BY name, datname
ORDER BY "Size in Gigabytes" DESC
Very useful!! Thanks @subelsky
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
forget ~ , ^_^,your sql is very useful,thank !