Created
November 16, 2013 01:07
-
-
Save drob/7494488 to your computer and use it in GitHub Desktop.
A truly disgusting script to compute the total amount of space used in all tables in a postgres database.
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
# How much space, in bytes, is used by the tables in this database? | |
psql -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public'" | sed -r "s/(.*)/\"SELECT * FROM pg_total_relation_size('\1')\"/g" | xargs -n 1 psql -c | egrep "\s+[0-9]+" | tr -d ' ' | awk '{total = total + $1}END{print total}' | |
# How much space, in bytes, is used by the indexes in this database? | |
psql -c "SELECT tablename FROM pg_tables WHERE schemaname = 'public'" | sed -r "s/(.*)/\"SELECT * FROM pg_indexes_size('\1')\"/g" | xargs -n 1 psql -c | egrep "\s+[0-9]+" | tr -d ' ' | awk '{total = total + $1}END{print total}' | |
# This is not a proud gist. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment