diff --git a/scripts/restore.sh b/scripts/restore.sh index b60d62c..ff88eec 100755 --- a/scripts/restore.sh +++ b/scripts/restore.sh @@ -10,44 +10,53 @@ if [[ "${WALG_BASE_BACKUP_NAME:-0}" != "0" ]]; then wal-g backup-fetch $PGDATA $WALG_BASE_BACKUP_NAME fi -## ****************** Recovery config 11 ************************** -#touch /tmp/recovery.conf -#echo "restore_command = 'wal-g wal-fetch %f %p'" >>/tmp/recovery.conf -#echo "standby_mode = on" >>/tmp/recovery.conf -#echo "trigger_file = '/run_scripts/tmp/pg-failover-trigger'" >>/tmp/recovery.conf # [ name whose presence ends recovery] -##echo "recovery_target_timeline = 'latest'" >>/tmp/recovery.conf -##echo "recovery_target = 'immediate'" >>/tmp/recovery.conf -#echo "recovery_target_action = 'promote'" >>/tmp/recovery.conf -#mv /tmp/recovery.conf "$PGDATA/recovery.conf" -# -## setup postgresql.conf -#touch /tmp/postgresql.conf -#echo "wal_level = replica" >>/tmp/postgresql.conf -#echo "max_wal_senders = 90" >>/tmp/postgresql.conf # default is 10. value must be less than max_connections minus superuser_reserved_connections. ref: https://www.postgresql.org/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS -# -#echo "wal_keep_segments = 64" >>/tmp/postgresql.conf -# -#echo "wal_log_hints = on" >>/tmp/postgresql.conf - -# ****************** Recovery config 12, 13, 14 ************************** -touch $PGDATA/recovery.signal - -# setup postgresql.conf -touch /tmp/postgresql.conf -echo "restore_command = 'wal-g wal-fetch %f %p'" >>/tmp/postgresql.conf -#echo "recovery_target_timeline = 'latest'" >>/tmp/postgresql.conf -if [[ "${PITR_TIME:-0}" != "latest" ]]; then - echo "recovery_target_time = '$PITR_TIME'" >>/tmp/postgresql.conf +# check postgresql veriosn + +if [[ "$PG_MAJOR" == "11" ]]; then + + # ****************** Recovery config 11 ************************** + touch /tmp/recovery.conf + echo "restore_command = 'wal-g wal-fetch %f %p'" >>/tmp/recovery.conf + echo "standby_mode = on" >>/tmp/recovery.conf + echo "trigger_file = '/run_scripts/tmp/pg-failover-trigger'" >>/tmp/recovery.conf # [ name whose presence ends recovery] + if [[ "${PITR_TIME:-0}" != "latest" ]]; then + echo "recovery_target_time = '$PITR_TIME'" >>/tmp/recovery.conf + else + echo "recovery_target_timeline = 'latest'" >>/tmp/recovery.conf + fi + echo "recovery_target_action = 'promote'" >>/tmp/recovery.conf + mv /tmp/recovery.conf "$PGDATA/recovery.conf" + + # setup postgresql.conf + touch /tmp/postgresql.conf + echo "wal_level = replica" >>/tmp/postgresql.conf + echo "max_wal_senders = 90" >>/tmp/postgresql.conf # default is 10. value must be less than max_connections minus superuser_reserved_connections. ref: https://www.postgresql.org/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS + + echo "wal_keep_segments = 64" >>/tmp/postgresql.conf + + echo "wal_log_hints = on" >>/tmp/postgresql.conf else - echo "recovery_target_timeline = 'latest'" >>/tmp/postgresql.conf -fi -echo "recovery_target_action = 'promote'" >>/tmp/postgresql.conf -echo "wal_level = replica" >>/tmp/postgresql.conf -echo "max_wal_senders = 90" >>/tmp/postgresql.conf # default is 10. value must be less than max_connections minus superuser_reserved_connections. ref: https://www.postgresql.org/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS + # ****************** Recovery config 12, 13, 14 ************************** + touch $PGDATA/recovery.signal + + # setup postgresql.conf + touch /tmp/postgresql.conf + echo "restore_command = 'wal-g wal-fetch %f %p'" >>/tmp/postgresql.conf + #echo "recovery_target_timeline = 'latest'" >>/tmp/postgresql.conf + if [[ "${PITR_TIME:-0}" != "latest" ]]; then + echo "recovery_target_time = '$PITR_TIME'" >>/tmp/postgresql.conf + else + echo "recovery_target_timeline = 'latest'" >>/tmp/postgresql.conf + fi + echo "recovery_target_action = 'promote'" >>/tmp/postgresql.conf + echo "wal_level = replica" >>/tmp/postgresql.conf + echo "max_wal_senders = 90" >>/tmp/postgresql.conf # default is 10. value must be less than max_connections minus superuser_reserved_connections. ref: https://www.postgresql.org/docs/11/runtime-config-replication.html#GUC-MAX-WAL-SENDERS -echo "wal_keep_size = 64" >>/tmp/postgresql.conf -echo "hot_standby = on" >>/tmp/postgresql.conf -echo "wal_log_hints = on" >>/tmp/postgresql.conf + echo "wal_keep_size = 64" >>/tmp/postgresql.conf + echo "hot_standby = on" >>/tmp/postgresql.conf + echo "wal_log_hints = on" >>/tmp/postgresql.conf + +fi # ****************** Recovery config 12 ************************** # we are not doing any archiving by default but it's better to have this config in our postgresql.conf file in case of customization.