Last active
April 11, 2020 06:48
-
-
Save Raidus/6a457faec38281dcaed6ca7fa438367c to your computer and use it in GitHub Desktop.
[How to find size of Database and Table in PostgreSQL] DBA Scripts #postgres
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
# Resource: https://www.dbrnd.com/2015/05/how-to-find-size-of-database-and-table-in-postgresql/ | |
# Find all the table size in the current database. | |
SELECT | |
table_schema || '.' || table_name AS TableName, | |
pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize | |
FROM information_schema.tables | |
ORDER BY | |
pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC; | |
# Find all the table and index size in the current database. | |
SELECT | |
TableName | |
,pg_size_pretty(pg_table_size(TableName)) AS TableSize | |
,pg_size_pretty(pg_indexes_size(TableName)) AS IndexSize | |
,pg_size_pretty(pg_total_relation_size(TableName)) AS TotalSize | |
FROM | |
( | |
SELECT ('"' || table_schema || '"."' || table_name || '"') AS TableName | |
FROM information_schema.tables | |
) AS Tables | |
ORDER BY 4 DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment