Improve daily vacuum script
This commit is contained in:
parent
7f5a7e48f8
commit
0336cd998f
|
@ -1,10 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Daily vaccuum script for PVCDNS database
|
# Daily vaccuum script for PostgreSQL databases
|
||||||
# {{ ansible_managed }}
|
# {{ ansible_managed }}
|
||||||
|
|
||||||
# Don't run if we aren't primary
|
# Don't run if we aren't the Patroni primary
|
||||||
HOSTNAME="$( hostname -s )"
|
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
|
if [[ $HOSTNAME != $PRIMARY ]]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -13,4 +14,4 @@ fi
|
||||||
echo -e "----------------------------" &>>/var/log/pvc/pdns/vacuum.log
|
echo -e "----------------------------" &>>/var/log/pvc/pdns/vacuum.log
|
||||||
echo -e "$( date )" &>>/var/log/pvc/pdns/vacuum.log
|
echo -e "$( date )" &>>/var/log/pvc/pdns/vacuum.log
|
||||||
echo -e "----------------------------" &>>/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
|
||||||
|
|
Loading…
Reference in New Issue