Created
February 12, 2013 10:22
-
-
Save hannesstruss/4761410 to your computer and use it in GitHub Desktop.
get a list of postgres table and index sizes
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
DBNAME= | |
QUERY="select tablename from pg_catalog.pg_tables where tablename not like 'sql_%' and tablename not like 'pg_%';" | |
for table in `psql $DBNAME -t -c "$QUERY"`; do | |
TABLE_QUERY="select pg_size_pretty(pg_relation_size('$table'));" | |
TABLE_SIZE=`psql $DBNAME -t -c "$TABLE_QUERY"` | |
TOTAL_QUERY="select pg_total_relation_size('$table');" | |
TOTAL=`psql $DBNAME -t -c "$TOTAL_QUERY"` | |
INDEX_QUERY="select pg_size_pretty(pg_total_relation_size('$table') - pg_relation_size('$table'));" | |
INDEX=`psql $DBNAME -t -c "$INDEX_QUERY"` | |
echo $TOTAL $table index: $INDEX table: $TABLE_SIZE | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment