Added logging to the recovery scripts.

This commit is contained in:
Andrea Dell'Amico 2021-04-08 14:57:07 +02:00
parent f9e859a98b
commit 9f188f044a
3 changed files with 21 additions and 2 deletions

View File

@ -15,26 +15,37 @@ logger "pgpool_recovery_1: MASTER_DATA=$MASTER_DATA"
logger "pgpool_recovery_1: RECOVERY_DATA=$RECOVERY_DATA"
# Ensure that postgres is shut down on the target node
ssh -T $RECOVERY_TARGET sudo /etc/init.d/postgresql stop
ssh -T $RECOVERY_TARGET sudo /bin/systemctl stop postgresql
logger "pgpool_recovery_1: stopped postgresql"
# Move the PostgreSQL data directory out of our way.
ssh -T $RECOVERY_TARGET \
"[ -d $RECOVERY_DATA ] && mv $RECOVERY_DATA $RECOVERY_DATA.$TS"
logger "pgpool_recovery_1: moved the old data directory on $RECOVERY_TARGET"
# We only use archived WAL logs during recoveries, so delete all
# logs from the last recovery to limit the growth.
rm $MASTER_DATA/archive_log/*
logger "pgpool_recovery_1: removed archive log"
# With this file present, our archive_command will actually
# archive WAL files.
touch $MASTER_DATA/archive_log/backup_in_progress
logger "pgpool_recovery_1: touched the backup_in_progress file"
# Perform a backup of the database.
ssh -T $RECOVERY_TARGET \
"pg_basebackup -h $MASTER_HOST -D $RECOVERY_DATA"
logger "pgpool_recovery_1: backup of the database from $MASTER_HOST to $RECOVERY_TARGET"
# Configure the restore_command to use the archive_log WALs well copy
# over in 2nd_stage.sh.
echo "restore_command = 'cp $RECOVERY_DATA/archive_log/%f %p'" | \
ssh -T $RECOVERY_TARGET "cat > $RECOVERY_DATA/recovery.conf"
logger "pgpool_recovery_1: create the restore command on $RECOVERY_TARGET"

View File

@ -24,14 +24,22 @@ do
fi
done
logger "pgpool_recovery_2: flushed the current value of sequences to xlog"
# Flush all transactions to disk. Since pgpool stopped all connections,
# there cannot be any data that does not reside on disk until the
# to-be-recovered host is back on line.
psql -p $port -c "SELECT pgpool_switch_xlog('$MASTER_DATA/archive_log')" template1
logger "pgpool_recovery_2: flushed the transactions"
# Copy over all archive logs at once.
rsync -avx --delete $MASTER_DATA/archive_log/ \
$RECOVERY_TARGET:$RECOVERY_DATA/archive_log/
logger "pgpool_recovery_2: rsynced the archive logs from $MASTER_DATA to $RECOVERY_TARGET"
# Delete the flag file to disable WAL archiving again.
rm $MASTER_DATA/archive_log/backup_in_progress
logger "pgpool_recovery_2: removed the backup_in_progress file"

View File

@ -5,4 +5,4 @@ DESTDIR=$2
# Deploy a base backup
ssh -T $DEST 'cd {{ psql_data_root_dir }}; tar zxf pgsql.tar.gz' 2>/dev/null 1>/dev/null < /dev/null
# Startup PostgreSQL server
ssh -T $DEST sudo /etc/init.d/postgresql start 2>/dev/null 1>/dev/null < /dev/null
ssh -T $DEST sudo /bin/systemctl start postgresql 2>/dev/null 1>/dev/null < /dev/null