Created
October 22, 2013 13:20
-
-
Save andrefsp/7100649 to your computer and use it in GitHub Desktop.
Shell script to get per database stats
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
#!/bin/bash | |
case $1 in | |
pg_stat_activity) | |
sudo -u postgres psql -t -c "select $3 from pg_stat_activity where datname='$2' ;" | head -1 | sed s/\ \\+//g | |
;; | |
pg_stat_database) | |
sudo -u postgres psql -t -c "select $3 from pg_stat_database where datname='$2' ;" | head -1 | sed s/\ \\+//g | |
;; | |
pg_database_size) | |
sudo -u postgres psql -t -c "select pg_database_size('$2');" | head -1 | sed s/\ \\+//g | |
;; | |
*) | |
exit 1; | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment