From 9f188f044a2fcf9f31e1b8b530a7262b4f2e5a57 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Thu, 8 Apr 2021 14:57:07 +0200 Subject: [PATCH] Added logging to the recovery scripts. --- templates/pgpool_recovery_stage_1.j2 | 13 ++++++++++++- templates/pgpool_recovery_stage_2.j2 | 8 ++++++++ templates/pgpool_remote_start.j2 | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/templates/pgpool_recovery_stage_1.j2 b/templates/pgpool_recovery_stage_1.j2 index 7f79784..44c5ed6 100644 --- a/templates/pgpool_recovery_stage_1.j2 +++ b/templates/pgpool_recovery_stage_1.j2 @@ -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 we’ll 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" diff --git a/templates/pgpool_recovery_stage_2.j2 b/templates/pgpool_recovery_stage_2.j2 index 4c22bed..3460d38 100644 --- a/templates/pgpool_recovery_stage_2.j2 +++ b/templates/pgpool_recovery_stage_2.j2 @@ -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" diff --git a/templates/pgpool_remote_start.j2 b/templates/pgpool_remote_start.j2 index 397c491..0fc0700 100644 --- a/templates/pgpool_remote_start.j2 +++ b/templates/pgpool_remote_start.j2 @@ -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