Add daily Postgres vacuum script

This commit is contained in:
Joshua Boniface 2023-09-01 15:42:21 -04:00
parent 9bac2bac43
commit c0acd3e994
2 changed files with 22 additions and 0 deletions

View File

@ -60,6 +60,12 @@
dest: /usr/lib/check_mk_agent/plugins/postgres dest: /usr/lib/check_mk_agent/plugins/postgres
mode: 0755 mode: 0755
- name: install daily vacuum script
template:
src: patroni/pvcdns-vacuum.j2
dest: /etc/cron.daily/pvcdns-vacuum
mode: 0755
- name: install initial schema files - name: install initial schema files
copy: copy:
src: "{{ item.src }}" src: "{{ item.src }}"

View File

@ -0,0 +1,16 @@
#!/bin/bash
# Daily vaccuum script for PVCDNS database
# {{ ansible_managed }}
# Don't run if we aren't primary
HOSTNAME="$( hostname -s )"
PRIMARY="$( pvc node list | grep primary | awk '{ print $1 }' )"
if [[ $HOSTNAME != $PRIMARY ]]; then
exit 0
fi
# Analyze the database
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