Improve daily vacuum script

This commit is contained in:
Joshua Boniface 2023-09-01 15:42:21 -04:00
parent 94ef3490ab
commit 2e0d5c9d44
1 changed files with 8 additions and 7 deletions

View File

@ -1,10 +1,11 @@
#!/bin/bash
# Daily vaccuum script for PVCDNS database
# Daily vaccuum script for PostgreSQL databases
# {{ ansible_managed }}
# Don't run if we aren't primary
# Don't run if we aren't the Patroni primary
HOSTNAME="$( hostname -s )"
PRIMARY="$( pvc node list | grep primary | awk '{ print $1 }' )"
PRIMARY="$( patronictl -c /etc/patroni/config.yml -d zookeeper://localhost:2181 list --format json \
| jq -r '.[] | select(.Role == "Leader") | .Member' )"
if [[ $HOSTNAME != $PRIMARY ]]; then
exit 0
fi
@ -13,4 +14,4 @@ fi
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 'psql pvcdns -c "VACUUM (VERBOSE, ANALYZE);"' &>>/var/log/pvc/pdns/vacuum.log
su postgres -c 'vacuumdb --verbose --analyze --all' &>>/var/log/pvc/pdns/vacuum.log