#!/bin/bash # Online recovery 2nd stage script # #MASTER_DATA="{{ psql_data_dir }}" MASTER_DATA="${1}" RECOVERY_TARGET=${2} #RECOVERY_DATA="{{ psql_data_dir }}" RECOVERY_DATA="${3}" port="{{ psql_db_port }}" # PostgreSQL port number archive_dir="{{ psql_wal_archiving_log_dir }}" logger "pgpool_recovery_2: MASTER_DATA=$MASTER_DATA" logger "pgpool_recovery_2: RECOVERY_DATA=$RECOVERY_DATA" logger "pgpool_recovery_2: archive_dir=$archive_dir" # Force to flush current value of sequences to xlog psql -p $port -t -c 'SELECT datname FROM pg_database WHERE NOT datistemplate AND datallowconn' template1| while read i do if [ "$i" != "" ];then psql -p $port -c "SELECT setval(oid, nextval(oid)) FROM pg_class WHERE relkind = 'S'" $i fi done # 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 # Copy over all archive logs at once. rsync -avx --delete $MASTER_DATA/archive_log/ \ $RECOVERY_TARGET:$RECOVERY_DATA/archive_log/ # Delete the flag file to disable WAL archiving again. rm $MASTER_DATA/archive_log/backup_in_progress