2019-08-11 15:29:00 -04:00
|
|
|
#!/bin/bash
|
2019-08-12 13:18:42 -04:00
|
|
|
# Daily vaccuum script for PostgreSQL databases
|
2019-08-11 15:29:00 -04:00
|
|
|
# {{ ansible_managed }}
|
|
|
|
|
2019-08-12 13:18:42 -04:00
|
|
|
# Don't run if we aren't the Patroni primary
|
2019-08-11 15:29:00 -04:00
|
|
|
HOSTNAME="$( hostname -s )"
|
2019-08-12 13:18:42 -04:00
|
|
|
PRIMARY="$( patronictl -c /etc/patroni/config.yml -d zookeeper://localhost:2181 list --format json \
|
|
|
|
| jq -r '.[] | select(.Role == "Leader") | .Member' )"
|
2019-08-11 15:29:00 -04:00
|
|
|
if [[ $HOSTNAME != $PRIMARY ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Analyze the database
|
2019-08-12 13:18:42 -04:00
|
|
|
echo -e "----------------------------" &>>/var/log/pvc/pdns/vacuum.log
|
|
|
|
echo -e "$( date )" &>>/var/log/pvc/pdns/vacuum.log
|
|
|
|
echo -e "----------------------------" &>>/var/log/pvc/pdns/vacuum.log
|
|
|
|
su postgres -c 'vacuumdb --verbose --analyze --all' &>>/var/log/pvc/pdns/vacuum.log
|