pvc-ansible/roles/pvc/templates/patroni/pvcdns-vacuum.j2

18 lines
739 B
Plaintext
Raw Normal View History

2023-09-01 15:42:21 -04:00
#!/bin/bash
2023-09-01 15:42:21 -04:00
# Daily vaccuum script for PostgreSQL databases
2023-09-01 15:42:21 -04:00
# {{ ansible_managed }}
2023-09-01 15:42:21 -04:00
# Don't run if we aren't the Patroni primary
2023-09-01 15:42:21 -04:00
HOSTNAME="$( hostname -s )"
2023-09-01 15:42:21 -04:00
PRIMARY="$( patronictl -c /etc/patroni/config.yml -d zookeeper://localhost:2181 list --format json \
| jq -r '.[] | select(.Role == "Leader") | .Member' )"
2023-09-01 15:42:21 -04:00
if [[ $HOSTNAME != $PRIMARY ]]; then
exit 0
fi
# Analyze the database
2023-09-01 15:42:21 -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