-
-
Save kenvac/52d952b73f4cc048abaa9da860966c94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Vacuum, analyze and re-index all non-template postgres databases | |
# Should be run as root to avoid any permissions issues | |
db_list_sql="SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn ORDER BY datname" | |
for db in $(su - postgres -c "psql -At -c '$db_list_sql'"); do | |
su - postgres -c "vacuumdb --analyze --quiet $db" | |
su - postgres -c "PGOPTIONS='--client-min-messages=warning' reindexdb --quiet $db" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment