From 4344f751413a6d95d4793e333413a7093c38a715 Mon Sep 17 00:00:00 2001 From: souravbiswassanto Date: Mon, 22 Jun 2026 00:44:00 +0600 Subject: [PATCH 1/3] Use env vars for synchronous replication config in all version scripts Replace hardcoded ANY 1 and remote_write with env vars in synchronous_standby_names and synchronous_commit configuration across all version scripts (v9-v18). Shell defaults preserve existing behavior when env vars are absent: - SYNC_REPLICATION_MODE defaults to ANY - NUM_SYNC_REPLICAS defaults to 1 - SYNC_COMMIT_LEVEL defaults to remote_write Signed-off-by: saurov@appscode.com Signed-off-by: souravbiswassanto --- role_scripts/10/primary/start.sh | 4 ++-- role_scripts/10/standby/ha_backup_job.sh | 4 ++-- role_scripts/10/standby/run.sh | 4 ++-- role_scripts/10/standby/warm_stanby.sh | 4 ++-- role_scripts/11/primary/start.sh | 4 ++-- role_scripts/11/standby/ha_backup_job.sh | 4 ++-- role_scripts/11/standby/run.sh | 4 ++-- role_scripts/11/standby/warm_stanby.sh | 4 ++-- role_scripts/12/primary/start.sh | 4 ++-- role_scripts/12/standby/ha_backup_job.sh | 4 ++-- role_scripts/12/standby/run.sh | 4 ++-- role_scripts/12/standby/warm_stanby.sh | 4 ++-- role_scripts/13/primary/start.sh | 4 ++-- role_scripts/13/standby/ha_backup_job.sh | 4 ++-- role_scripts/13/standby/run.sh | 4 ++-- role_scripts/13/standby/warm_stanby.sh | 4 ++-- role_scripts/14/primary/start.sh | 4 ++-- role_scripts/14/standby/ha_backup_job.sh | 4 ++-- role_scripts/14/standby/run.sh | 4 ++-- role_scripts/14/standby/warm_stanby.sh | 4 ++-- role_scripts/15/primary/start.sh | 4 ++-- role_scripts/15/standby/ha_backup_job.sh | 4 ++-- role_scripts/15/standby/run.sh | 4 ++-- role_scripts/15/standby/warm_stanby.sh | 4 ++-- role_scripts/16/primary/start.sh | 4 ++-- role_scripts/16/standby/ha_backup_job.sh | 4 ++-- role_scripts/16/standby/run.sh | 4 ++-- role_scripts/16/standby/warm_stanby.sh | 4 ++-- role_scripts/17/primary/start.sh | 4 ++-- role_scripts/17/standby/ha_backup_job.sh | 4 ++-- role_scripts/17/standby/run.sh | 4 ++-- role_scripts/17/standby/warm_stanby.sh | 4 ++-- role_scripts/18/primary/start.sh | 4 ++-- role_scripts/18/standby/ha_backup_job.sh | 4 ++-- role_scripts/18/standby/run.sh | 4 ++-- role_scripts/18/standby/warm_stanby.sh | 4 ++-- role_scripts/9/primary/start.sh | 4 ++-- role_scripts/9/standby/ha_backup_job.sh | 4 ++-- role_scripts/9/standby/run.sh | 4 ++-- role_scripts/9/standby/warm_stanby.sh | 4 ++-- 40 files changed, 80 insertions(+), 80 deletions(-) diff --git a/role_scripts/10/primary/start.sh b/role_scripts/10/primary/start.sh index 81d7b7c..de906a9 100755 --- a/role_scripts/10/primary/start.sh +++ b/role_scripts/10/primary/start.sh @@ -180,7 +180,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -197,7 +197,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 cat /tmp/postgresql.conf $PGDATA/postgresql.conf >"/tmp/postgresql.conf.tmp" && mv "/tmp/postgresql.conf.tmp" "$PGDATA/postgresql.conf" diff --git a/role_scripts/10/standby/ha_backup_job.sh b/role_scripts/10/standby/ha_backup_job.sh index f38682d..0f63dae 100755 --- a/role_scripts/10/standby/ha_backup_job.sh +++ b/role_scripts/10/standby/ha_backup_job.sh @@ -98,7 +98,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -115,7 +115,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/10/standby/run.sh b/role_scripts/10/standby/run.sh index da7dc4d..dbaeaa5 100755 --- a/role_scripts/10/standby/run.sh +++ b/role_scripts/10/standby/run.sh @@ -163,7 +163,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -180,7 +180,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/10/standby/warm_stanby.sh b/role_scripts/10/standby/warm_stanby.sh index 518c8ed..79930f4 100755 --- a/role_scripts/10/standby/warm_stanby.sh +++ b/role_scripts/10/standby/warm_stanby.sh @@ -39,7 +39,7 @@ echo "hot_standby = off" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -56,7 +56,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/11/primary/start.sh b/role_scripts/11/primary/start.sh index 7327172..f6ca097 100755 --- a/role_scripts/11/primary/start.sh +++ b/role_scripts/11/primary/start.sh @@ -221,7 +221,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -238,7 +238,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 cat /tmp/postgresql.conf $PGDATA/postgresql.conf >"/tmp/postgresql.conf.tmp" && mv "/tmp/postgresql.conf.tmp" "$PGDATA/postgresql.conf" diff --git a/role_scripts/11/standby/ha_backup_job.sh b/role_scripts/11/standby/ha_backup_job.sh index 6ad580a..3acd8b0 100755 --- a/role_scripts/11/standby/ha_backup_job.sh +++ b/role_scripts/11/standby/ha_backup_job.sh @@ -97,7 +97,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -114,7 +114,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/11/standby/run.sh b/role_scripts/11/standby/run.sh index 1f557c8..9eda87e 100755 --- a/role_scripts/11/standby/run.sh +++ b/role_scripts/11/standby/run.sh @@ -166,7 +166,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -183,7 +183,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/11/standby/warm_stanby.sh b/role_scripts/11/standby/warm_stanby.sh index ba5a474..623caf2 100755 --- a/role_scripts/11/standby/warm_stanby.sh +++ b/role_scripts/11/standby/warm_stanby.sh @@ -39,7 +39,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -56,7 +56,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/12/primary/start.sh b/role_scripts/12/primary/start.sh index d78266f..73e969d 100755 --- a/role_scripts/12/primary/start.sh +++ b/role_scripts/12/primary/start.sh @@ -241,7 +241,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -258,7 +258,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/12/standby/ha_backup_job.sh b/role_scripts/12/standby/ha_backup_job.sh index 4d645a9..2d88787 100755 --- a/role_scripts/12/standby/ha_backup_job.sh +++ b/role_scripts/12/standby/ha_backup_job.sh @@ -99,7 +99,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -116,7 +116,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/12/standby/run.sh b/role_scripts/12/standby/run.sh index dbaff6e..bbb6790 100755 --- a/role_scripts/12/standby/run.sh +++ b/role_scripts/12/standby/run.sh @@ -166,7 +166,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -183,7 +183,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/12/standby/warm_stanby.sh b/role_scripts/12/standby/warm_stanby.sh index 20a73ac..3e0d444 100755 --- a/role_scripts/12/standby/warm_stanby.sh +++ b/role_scripts/12/standby/warm_stanby.sh @@ -48,7 +48,7 @@ echo "hot_standby = off" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -65,7 +65,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/13/primary/start.sh b/role_scripts/13/primary/start.sh index c4ab448..7a8ab9d 100755 --- a/role_scripts/13/primary/start.sh +++ b/role_scripts/13/primary/start.sh @@ -251,7 +251,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -268,7 +268,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/13/standby/ha_backup_job.sh b/role_scripts/13/standby/ha_backup_job.sh index b62d3c2..0ff448f 100755 --- a/role_scripts/13/standby/ha_backup_job.sh +++ b/role_scripts/13/standby/ha_backup_job.sh @@ -99,7 +99,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -116,7 +116,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/13/standby/run.sh b/role_scripts/13/standby/run.sh index 17a6a74..5897073 100755 --- a/role_scripts/13/standby/run.sh +++ b/role_scripts/13/standby/run.sh @@ -169,7 +169,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -186,7 +186,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/13/standby/warm_stanby.sh b/role_scripts/13/standby/warm_stanby.sh index 6eb8c8d..c98d822 100755 --- a/role_scripts/13/standby/warm_stanby.sh +++ b/role_scripts/13/standby/warm_stanby.sh @@ -42,7 +42,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -59,7 +59,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/14/primary/start.sh b/role_scripts/14/primary/start.sh index cf42d90..2f47f82 100755 --- a/role_scripts/14/primary/start.sh +++ b/role_scripts/14/primary/start.sh @@ -258,7 +258,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -275,7 +275,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/14/standby/ha_backup_job.sh b/role_scripts/14/standby/ha_backup_job.sh index 28bffd8..49723e8 100755 --- a/role_scripts/14/standby/ha_backup_job.sh +++ b/role_scripts/14/standby/ha_backup_job.sh @@ -99,7 +99,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -116,7 +116,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/14/standby/run.sh b/role_scripts/14/standby/run.sh index 36b7f92..5eb8a95 100755 --- a/role_scripts/14/standby/run.sh +++ b/role_scripts/14/standby/run.sh @@ -169,7 +169,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -187,7 +187,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/14/standby/warm_stanby.sh b/role_scripts/14/standby/warm_stanby.sh index 26e12bf..f6296dc 100755 --- a/role_scripts/14/standby/warm_stanby.sh +++ b/role_scripts/14/standby/warm_stanby.sh @@ -42,7 +42,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -59,7 +59,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/15/primary/start.sh b/role_scripts/15/primary/start.sh index c628a37..0225a4a 100755 --- a/role_scripts/15/primary/start.sh +++ b/role_scripts/15/primary/start.sh @@ -259,7 +259,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -276,7 +276,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/15/standby/ha_backup_job.sh b/role_scripts/15/standby/ha_backup_job.sh index 2480264..5a78ab8 100755 --- a/role_scripts/15/standby/ha_backup_job.sh +++ b/role_scripts/15/standby/ha_backup_job.sh @@ -101,7 +101,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -118,7 +118,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/15/standby/run.sh b/role_scripts/15/standby/run.sh index 92bdf71..f55764c 100755 --- a/role_scripts/15/standby/run.sh +++ b/role_scripts/15/standby/run.sh @@ -168,7 +168,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -186,7 +186,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/15/standby/warm_stanby.sh b/role_scripts/15/standby/warm_stanby.sh index 65bd3d1..4272d62 100755 --- a/role_scripts/15/standby/warm_stanby.sh +++ b/role_scripts/15/standby/warm_stanby.sh @@ -43,7 +43,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -60,7 +60,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/16/primary/start.sh b/role_scripts/16/primary/start.sh index 0d1c333..f76aecc 100755 --- a/role_scripts/16/primary/start.sh +++ b/role_scripts/16/primary/start.sh @@ -257,7 +257,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -274,7 +274,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/16/standby/ha_backup_job.sh b/role_scripts/16/standby/ha_backup_job.sh index fe94164..f8a0004 100755 --- a/role_scripts/16/standby/ha_backup_job.sh +++ b/role_scripts/16/standby/ha_backup_job.sh @@ -101,7 +101,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -118,7 +118,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/16/standby/run.sh b/role_scripts/16/standby/run.sh index 55e420d..8a3fec6 100755 --- a/role_scripts/16/standby/run.sh +++ b/role_scripts/16/standby/run.sh @@ -170,7 +170,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -187,7 +187,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/16/standby/warm_stanby.sh b/role_scripts/16/standby/warm_stanby.sh index 9ad3eeb..01d9392 100755 --- a/role_scripts/16/standby/warm_stanby.sh +++ b/role_scripts/16/standby/warm_stanby.sh @@ -43,7 +43,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -60,7 +60,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/17/primary/start.sh b/role_scripts/17/primary/start.sh index fc05df8..1b64add 100755 --- a/role_scripts/17/primary/start.sh +++ b/role_scripts/17/primary/start.sh @@ -259,7 +259,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -276,7 +276,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/17/standby/ha_backup_job.sh b/role_scripts/17/standby/ha_backup_job.sh index fe94164..f8a0004 100755 --- a/role_scripts/17/standby/ha_backup_job.sh +++ b/role_scripts/17/standby/ha_backup_job.sh @@ -101,7 +101,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -118,7 +118,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/17/standby/run.sh b/role_scripts/17/standby/run.sh index 9e774f2..27ac151 100755 --- a/role_scripts/17/standby/run.sh +++ b/role_scripts/17/standby/run.sh @@ -171,7 +171,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -189,7 +189,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/17/standby/warm_stanby.sh b/role_scripts/17/standby/warm_stanby.sh index 9ad3eeb..01d9392 100755 --- a/role_scripts/17/standby/warm_stanby.sh +++ b/role_scripts/17/standby/warm_stanby.sh @@ -43,7 +43,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -60,7 +60,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/18/primary/start.sh b/role_scripts/18/primary/start.sh index c3ba065..c07f618 100755 --- a/role_scripts/18/primary/start.sh +++ b/role_scripts/18/primary/start.sh @@ -255,7 +255,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -272,7 +272,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/18/standby/ha_backup_job.sh b/role_scripts/18/standby/ha_backup_job.sh index fe94164..f8a0004 100755 --- a/role_scripts/18/standby/ha_backup_job.sh +++ b/role_scripts/18/standby/ha_backup_job.sh @@ -101,7 +101,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -118,7 +118,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then echo "ssl = on" >>/tmp/postgresql.conf diff --git a/role_scripts/18/standby/run.sh b/role_scripts/18/standby/run.sh index 9e774f2..27ac151 100755 --- a/role_scripts/18/standby/run.sh +++ b/role_scripts/18/standby/run.sh @@ -171,7 +171,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -189,7 +189,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/18/standby/warm_stanby.sh b/role_scripts/18/standby/warm_stanby.sh index 9ad3eeb..01d9392 100755 --- a/role_scripts/18/standby/warm_stanby.sh +++ b/role_scripts/18/standby/warm_stanby.sh @@ -43,7 +43,7 @@ echo "shared_preload_libraries = 'pg_stat_statements'" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=${HOSTNAME##*[!0-9]} @@ -60,7 +60,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=${names%,} - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/9/primary/start.sh b/role_scripts/9/primary/start.sh index 7bd5a5b..ada90ca 100755 --- a/role_scripts/9/primary/start.sh +++ b/role_scripts/9/primary/start.sh @@ -175,7 +175,7 @@ fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -192,7 +192,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/9/standby/ha_backup_job.sh b/role_scripts/9/standby/ha_backup_job.sh index 27e68fd..d0ea7af 100755 --- a/role_scripts/9/standby/ha_backup_job.sh +++ b/role_scripts/9/standby/ha_backup_job.sh @@ -99,7 +99,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -116,7 +116,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/9/standby/run.sh b/role_scripts/9/standby/run.sh index d4f8c67..0c11923 100755 --- a/role_scripts/9/standby/run.sh +++ b/role_scripts/9/standby/run.sh @@ -158,7 +158,7 @@ else fi if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -175,7 +175,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/9/standby/warm_stanby.sh b/role_scripts/9/standby/warm_stanby.sh index 32d18e9..e558571 100755 --- a/role_scripts/9/standby/warm_stanby.sh +++ b/role_scripts/9/standby/warm_stanby.sh @@ -40,7 +40,7 @@ echo "hot_standby = off" >>/tmp/postgresql.conf if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication - echo "synchronous_commit = remote_write" >>/tmp/postgresql.conf + echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf # https://stackoverflow.com/a/44092231/244009 self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') @@ -57,7 +57,7 @@ if [[ "$STREAMING" == "synchronous" ]]; then fi done names=$(echo "$names" | rev | cut -c2- | rev) - echo "synchronous_standby_names = 'ANY 1 ("$names")'" >>/tmp/postgresql.conf + echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then From 4b445bb0538d7ec840f97f0a7c26860f139efb41 Mon Sep 17 00:00:00 2001 From: souravbiswassanto Date: Mon, 22 Jun 2026 00:59:44 +0600 Subject: [PATCH 2/3] Support SYNC_STANDBY_NAMES for explicit standby list in sync scripts When SYNC_STANDBY_NAMES is set (comma-separated pod names), use that list directly instead of auto-generating from pod indices. This enables FIRST mode with custom priority ordering and selective exclusion of specific standbys (e.g., cross-region replicas) from the sync quorum. Falls back to auto-generation when SYNC_STANDBY_NAMES is absent, preserving existing behaviour. Signed-off-by: saurov@appscode.com Signed-off-by: souravbiswassanto --- role_scripts/10/primary/start.sh | 39 ++++++++++++++--------- role_scripts/10/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/10/standby/run.sh | 39 ++++++++++++++--------- role_scripts/10/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/11/primary/start.sh | 39 ++++++++++++++--------- role_scripts/11/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/11/standby/run.sh | 39 ++++++++++++++--------- role_scripts/11/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/12/primary/start.sh | 39 ++++++++++++++--------- role_scripts/12/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/12/standby/run.sh | 39 ++++++++++++++--------- role_scripts/12/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/13/primary/start.sh | 39 ++++++++++++++--------- role_scripts/13/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/13/standby/run.sh | 39 ++++++++++++++--------- role_scripts/13/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/14/primary/start.sh | 39 ++++++++++++++--------- role_scripts/14/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/14/standby/run.sh | 40 ++++++++++++++---------- role_scripts/14/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/15/primary/start.sh | 39 ++++++++++++++--------- role_scripts/15/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/15/standby/run.sh | 40 ++++++++++++++---------- role_scripts/15/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/16/primary/start.sh | 39 ++++++++++++++--------- role_scripts/16/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/16/standby/run.sh | 39 ++++++++++++++--------- role_scripts/16/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/17/primary/start.sh | 39 ++++++++++++++--------- role_scripts/17/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/17/standby/run.sh | 40 ++++++++++++++---------- role_scripts/17/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/18/primary/start.sh | 39 ++++++++++++++--------- role_scripts/18/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/18/standby/run.sh | 40 ++++++++++++++---------- role_scripts/18/standby/warm_stanby.sh | 39 ++++++++++++++--------- role_scripts/9/primary/start.sh | 39 ++++++++++++++--------- role_scripts/9/standby/ha_backup_job.sh | 39 ++++++++++++++--------- role_scripts/9/standby/run.sh | 39 ++++++++++++++--------- role_scripts/9/standby/warm_stanby.sh | 39 ++++++++++++++--------- 40 files changed, 960 insertions(+), 604 deletions(-) diff --git a/role_scripts/10/primary/start.sh b/role_scripts/10/primary/start.sh index de906a9..28b984d 100755 --- a/role_scripts/10/primary/start.sh +++ b/role_scripts/10/primary/start.sh @@ -182,21 +182,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/10/standby/ha_backup_job.sh b/role_scripts/10/standby/ha_backup_job.sh index 0f63dae..022bfbe 100755 --- a/role_scripts/10/standby/ha_backup_job.sh +++ b/role_scripts/10/standby/ha_backup_job.sh @@ -100,21 +100,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/10/standby/run.sh b/role_scripts/10/standby/run.sh index dbaeaa5..c5add9a 100755 --- a/role_scripts/10/standby/run.sh +++ b/role_scripts/10/standby/run.sh @@ -165,21 +165,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/10/standby/warm_stanby.sh b/role_scripts/10/standby/warm_stanby.sh index 79930f4..33b69eb 100755 --- a/role_scripts/10/standby/warm_stanby.sh +++ b/role_scripts/10/standby/warm_stanby.sh @@ -41,21 +41,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/11/primary/start.sh b/role_scripts/11/primary/start.sh index f6ca097..0544d6c 100755 --- a/role_scripts/11/primary/start.sh +++ b/role_scripts/11/primary/start.sh @@ -223,21 +223,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi # ref: https://superuser.com/a/246841/985093 diff --git a/role_scripts/11/standby/ha_backup_job.sh b/role_scripts/11/standby/ha_backup_job.sh index 3acd8b0..d68f25c 100755 --- a/role_scripts/11/standby/ha_backup_job.sh +++ b/role_scripts/11/standby/ha_backup_job.sh @@ -99,21 +99,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/11/standby/run.sh b/role_scripts/11/standby/run.sh index 9eda87e..779f216 100755 --- a/role_scripts/11/standby/run.sh +++ b/role_scripts/11/standby/run.sh @@ -168,21 +168,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/11/standby/warm_stanby.sh b/role_scripts/11/standby/warm_stanby.sh index 623caf2..0292004 100755 --- a/role_scripts/11/standby/warm_stanby.sh +++ b/role_scripts/11/standby/warm_stanby.sh @@ -41,21 +41,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/12/primary/start.sh b/role_scripts/12/primary/start.sh index 73e969d..e030ae7 100755 --- a/role_scripts/12/primary/start.sh +++ b/role_scripts/12/primary/start.sh @@ -243,21 +243,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/12/standby/ha_backup_job.sh b/role_scripts/12/standby/ha_backup_job.sh index 2d88787..169300c 100755 --- a/role_scripts/12/standby/ha_backup_job.sh +++ b/role_scripts/12/standby/ha_backup_job.sh @@ -101,21 +101,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/12/standby/run.sh b/role_scripts/12/standby/run.sh index bbb6790..da63842 100755 --- a/role_scripts/12/standby/run.sh +++ b/role_scripts/12/standby/run.sh @@ -168,21 +168,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/12/standby/warm_stanby.sh b/role_scripts/12/standby/warm_stanby.sh index 3e0d444..46de49a 100755 --- a/role_scripts/12/standby/warm_stanby.sh +++ b/role_scripts/12/standby/warm_stanby.sh @@ -50,21 +50,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/13/primary/start.sh b/role_scripts/13/primary/start.sh index 7a8ab9d..cd44c9a 100755 --- a/role_scripts/13/primary/start.sh +++ b/role_scripts/13/primary/start.sh @@ -253,21 +253,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/13/standby/ha_backup_job.sh b/role_scripts/13/standby/ha_backup_job.sh index 0ff448f..7070688 100755 --- a/role_scripts/13/standby/ha_backup_job.sh +++ b/role_scripts/13/standby/ha_backup_job.sh @@ -101,21 +101,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/13/standby/run.sh b/role_scripts/13/standby/run.sh index 5897073..a71708e 100755 --- a/role_scripts/13/standby/run.sh +++ b/role_scripts/13/standby/run.sh @@ -171,21 +171,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/13/standby/warm_stanby.sh b/role_scripts/13/standby/warm_stanby.sh index c98d822..cef8bae 100755 --- a/role_scripts/13/standby/warm_stanby.sh +++ b/role_scripts/13/standby/warm_stanby.sh @@ -44,21 +44,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/14/primary/start.sh b/role_scripts/14/primary/start.sh index 2f47f82..0b552b5 100755 --- a/role_scripts/14/primary/start.sh +++ b/role_scripts/14/primary/start.sh @@ -260,21 +260,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/14/standby/ha_backup_job.sh b/role_scripts/14/standby/ha_backup_job.sh index 49723e8..d306cca 100755 --- a/role_scripts/14/standby/ha_backup_job.sh +++ b/role_scripts/14/standby/ha_backup_job.sh @@ -101,21 +101,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/14/standby/run.sh b/role_scripts/14/standby/run.sh index 5eb8a95..e984a0c 100755 --- a/role_scripts/14/standby/run.sh +++ b/role_scripts/14/standby/run.sh @@ -171,22 +171,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf -# https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - # this needs to be changed for read replicas - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/14/standby/warm_stanby.sh b/role_scripts/14/standby/warm_stanby.sh index f6296dc..f0a11c2 100755 --- a/role_scripts/14/standby/warm_stanby.sh +++ b/role_scripts/14/standby/warm_stanby.sh @@ -44,21 +44,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/15/primary/start.sh b/role_scripts/15/primary/start.sh index 0225a4a..b87a383 100755 --- a/role_scripts/15/primary/start.sh +++ b/role_scripts/15/primary/start.sh @@ -261,21 +261,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/15/standby/ha_backup_job.sh b/role_scripts/15/standby/ha_backup_job.sh index 5a78ab8..4157432 100755 --- a/role_scripts/15/standby/ha_backup_job.sh +++ b/role_scripts/15/standby/ha_backup_job.sh @@ -103,21 +103,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/15/standby/run.sh b/role_scripts/15/standby/run.sh index f55764c..630af43 100755 --- a/role_scripts/15/standby/run.sh +++ b/role_scripts/15/standby/run.sh @@ -170,22 +170,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf -# https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - # this needs to be changed for read replicas - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/15/standby/warm_stanby.sh b/role_scripts/15/standby/warm_stanby.sh index 4272d62..d649ecd 100755 --- a/role_scripts/15/standby/warm_stanby.sh +++ b/role_scripts/15/standby/warm_stanby.sh @@ -45,21 +45,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/16/primary/start.sh b/role_scripts/16/primary/start.sh index f76aecc..1e5174c 100755 --- a/role_scripts/16/primary/start.sh +++ b/role_scripts/16/primary/start.sh @@ -259,21 +259,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/16/standby/ha_backup_job.sh b/role_scripts/16/standby/ha_backup_job.sh index f8a0004..8da687d 100755 --- a/role_scripts/16/standby/ha_backup_job.sh +++ b/role_scripts/16/standby/ha_backup_job.sh @@ -103,21 +103,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/16/standby/run.sh b/role_scripts/16/standby/run.sh index 8a3fec6..079bfab 100755 --- a/role_scripts/16/standby/run.sh +++ b/role_scripts/16/standby/run.sh @@ -172,21 +172,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/16/standby/warm_stanby.sh b/role_scripts/16/standby/warm_stanby.sh index 01d9392..a67f2ec 100755 --- a/role_scripts/16/standby/warm_stanby.sh +++ b/role_scripts/16/standby/warm_stanby.sh @@ -45,21 +45,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/17/primary/start.sh b/role_scripts/17/primary/start.sh index 1b64add..cbe4012 100755 --- a/role_scripts/17/primary/start.sh +++ b/role_scripts/17/primary/start.sh @@ -261,21 +261,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/17/standby/ha_backup_job.sh b/role_scripts/17/standby/ha_backup_job.sh index f8a0004..8da687d 100755 --- a/role_scripts/17/standby/ha_backup_job.sh +++ b/role_scripts/17/standby/ha_backup_job.sh @@ -103,21 +103,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/17/standby/run.sh b/role_scripts/17/standby/run.sh index 27ac151..d6e5c19 100755 --- a/role_scripts/17/standby/run.sh +++ b/role_scripts/17/standby/run.sh @@ -173,22 +173,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - # this needs to be changed for read replicas - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/17/standby/warm_stanby.sh b/role_scripts/17/standby/warm_stanby.sh index 01d9392..a67f2ec 100755 --- a/role_scripts/17/standby/warm_stanby.sh +++ b/role_scripts/17/standby/warm_stanby.sh @@ -45,21 +45,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/18/primary/start.sh b/role_scripts/18/primary/start.sh index c07f618..87ac591 100755 --- a/role_scripts/18/primary/start.sh +++ b/role_scripts/18/primary/start.sh @@ -257,21 +257,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/18/standby/ha_backup_job.sh b/role_scripts/18/standby/ha_backup_job.sh index f8a0004..8da687d 100755 --- a/role_scripts/18/standby/ha_backup_job.sh +++ b/role_scripts/18/standby/ha_backup_job.sh @@ -103,21 +103,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi if [[ "${SSL:-0}" == "ON" ]]; then diff --git a/role_scripts/18/standby/run.sh b/role_scripts/18/standby/run.sh index 27ac151..d6e5c19 100755 --- a/role_scripts/18/standby/run.sh +++ b/role_scripts/18/standby/run.sh @@ -173,22 +173,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - # this needs to be changed for read replicas - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/18/standby/warm_stanby.sh b/role_scripts/18/standby/warm_stanby.sh index 01d9392..a67f2ec 100755 --- a/role_scripts/18/standby/warm_stanby.sh +++ b/role_scripts/18/standby/warm_stanby.sh @@ -45,21 +45,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=${HOSTNAME##*[!0-9]} - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=${names%,} + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/9/primary/start.sh b/role_scripts/9/primary/start.sh index ada90ca..aa4c27c 100755 --- a/role_scripts/9/primary/start.sh +++ b/role_scripts/9/primary/start.sh @@ -177,21 +177,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/9/standby/ha_backup_job.sh b/role_scripts/9/standby/ha_backup_job.sh index d0ea7af..8691783 100755 --- a/role_scripts/9/standby/ha_backup_job.sh +++ b/role_scripts/9/standby/ha_backup_job.sh @@ -101,21 +101,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/9/standby/run.sh b/role_scripts/9/standby/run.sh index 0c11923..7df2718 100755 --- a/role_scripts/9/standby/run.sh +++ b/role_scripts/9/standby/run.sh @@ -160,21 +160,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi diff --git a/role_scripts/9/standby/warm_stanby.sh b/role_scripts/9/standby/warm_stanby.sh index e558571..848c748 100755 --- a/role_scripts/9/standby/warm_stanby.sh +++ b/role_scripts/9/standby/warm_stanby.sh @@ -42,21 +42,30 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - # https://stackoverflow.com/a/44092231/244009 - self_idx=$(echo $HOSTNAME | grep -Eo '[0-9]+$') - echo "$self_idx" - - shopt -s extglob - sts_prefix=${HOSTNAME%%+([0-9])} - names="" - for ((i = 0; i < $REPLICAS; i++)); do - if [[ $self_idx == $i ]]; then - echo "skip $i" - else - names+="\"$sts_prefix$i\"," - fi - done - names=$(echo "$names" | rev | cut -c2- | rev) + if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + names="" + IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" + for _name in "${_standby_list[@]}"; do + names+="\"${_name}\"", + done + names="${names%,}" + else + # https://stackoverflow.com/a/44092231/244009 + self_idx=${HOSTNAME##*[!0-9]} + echo "$self_idx" + + shopt -s extglob + sts_prefix=${HOSTNAME%%+([0-9])} + names="" + for ((i = 0; i < $REPLICAS; i++)); do + if [[ $self_idx == $i ]]; then + echo "skip $i" + else + names+="\"$sts_prefix$i\"", + fi + done + names=${names%,} + fi echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'" >>/tmp/postgresql.conf fi From 6682c1d5a7e7c7e8617837b40f8a1a3ac496a447 Mon Sep 17 00:00:00 2001 From: souravbiswassanto Date: Wed, 24 Jun 2026 18:33:51 +0600 Subject: [PATCH 3/3] Add SYNC_USE_WILDCARD support to sync replication scripts (v9-v18) When the operator sets SYNC_USE_WILDCARD=true, init scripts emit '*' in synchronous_standby_names instead of the explicit pod name list. Useful for external DR replicas whose application_name is not known. Priority: wildcard > explicit SYNC_STANDBY_NAMES > auto-generated list. Signed-off-by: souravbiswassanto --- role_scripts/10/primary/start.sh | 4 +++- role_scripts/10/standby/ha_backup_job.sh | 4 +++- role_scripts/10/standby/run.sh | 4 +++- role_scripts/10/standby/warm_stanby.sh | 4 +++- role_scripts/11/primary/start.sh | 4 +++- role_scripts/11/standby/ha_backup_job.sh | 4 +++- role_scripts/11/standby/run.sh | 4 +++- role_scripts/11/standby/warm_stanby.sh | 4 +++- role_scripts/12/primary/start.sh | 4 +++- role_scripts/12/standby/ha_backup_job.sh | 4 +++- role_scripts/12/standby/run.sh | 4 +++- role_scripts/12/standby/warm_stanby.sh | 4 +++- role_scripts/13/primary/start.sh | 4 +++- role_scripts/13/standby/ha_backup_job.sh | 4 +++- role_scripts/13/standby/run.sh | 4 +++- role_scripts/13/standby/warm_stanby.sh | 4 +++- role_scripts/14/primary/start.sh | 4 +++- role_scripts/14/standby/ha_backup_job.sh | 4 +++- role_scripts/14/standby/run.sh | 4 +++- role_scripts/14/standby/warm_stanby.sh | 4 +++- role_scripts/15/primary/start.sh | 4 +++- role_scripts/15/standby/ha_backup_job.sh | 4 +++- role_scripts/15/standby/run.sh | 4 +++- role_scripts/15/standby/warm_stanby.sh | 4 +++- role_scripts/16/primary/start.sh | 4 +++- role_scripts/16/standby/ha_backup_job.sh | 4 +++- role_scripts/16/standby/run.sh | 4 +++- role_scripts/16/standby/warm_stanby.sh | 4 +++- role_scripts/17/primary/start.sh | 4 +++- role_scripts/17/standby/ha_backup_job.sh | 4 +++- role_scripts/17/standby/run.sh | 4 +++- role_scripts/17/standby/warm_stanby.sh | 4 +++- role_scripts/18/primary/start.sh | 4 +++- role_scripts/18/standby/ha_backup_job.sh | 4 +++- role_scripts/18/standby/run.sh | 4 +++- role_scripts/18/standby/warm_stanby.sh | 4 +++- role_scripts/9/primary/start.sh | 4 +++- role_scripts/9/standby/ha_backup_job.sh | 4 +++- role_scripts/9/standby/run.sh | 4 +++- role_scripts/9/standby/warm_stanby.sh | 4 +++- 40 files changed, 120 insertions(+), 40 deletions(-) diff --git a/role_scripts/10/primary/start.sh b/role_scripts/10/primary/start.sh index 28b984d..62ffbfc 100755 --- a/role_scripts/10/primary/start.sh +++ b/role_scripts/10/primary/start.sh @@ -182,7 +182,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/10/standby/ha_backup_job.sh b/role_scripts/10/standby/ha_backup_job.sh index 022bfbe..d4c1064 100755 --- a/role_scripts/10/standby/ha_backup_job.sh +++ b/role_scripts/10/standby/ha_backup_job.sh @@ -100,7 +100,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/10/standby/run.sh b/role_scripts/10/standby/run.sh index c5add9a..31a441c 100755 --- a/role_scripts/10/standby/run.sh +++ b/role_scripts/10/standby/run.sh @@ -165,7 +165,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/10/standby/warm_stanby.sh b/role_scripts/10/standby/warm_stanby.sh index 33b69eb..aa7a7d4 100755 --- a/role_scripts/10/standby/warm_stanby.sh +++ b/role_scripts/10/standby/warm_stanby.sh @@ -41,7 +41,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/11/primary/start.sh b/role_scripts/11/primary/start.sh index 0544d6c..88639ca 100755 --- a/role_scripts/11/primary/start.sh +++ b/role_scripts/11/primary/start.sh @@ -223,7 +223,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/11/standby/ha_backup_job.sh b/role_scripts/11/standby/ha_backup_job.sh index d68f25c..f5083be 100755 --- a/role_scripts/11/standby/ha_backup_job.sh +++ b/role_scripts/11/standby/ha_backup_job.sh @@ -99,7 +99,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/11/standby/run.sh b/role_scripts/11/standby/run.sh index 779f216..4eb0a72 100755 --- a/role_scripts/11/standby/run.sh +++ b/role_scripts/11/standby/run.sh @@ -168,7 +168,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/11/standby/warm_stanby.sh b/role_scripts/11/standby/warm_stanby.sh index 0292004..006617f 100755 --- a/role_scripts/11/standby/warm_stanby.sh +++ b/role_scripts/11/standby/warm_stanby.sh @@ -41,7 +41,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/12/primary/start.sh b/role_scripts/12/primary/start.sh index e030ae7..d11f018 100755 --- a/role_scripts/12/primary/start.sh +++ b/role_scripts/12/primary/start.sh @@ -243,7 +243,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/12/standby/ha_backup_job.sh b/role_scripts/12/standby/ha_backup_job.sh index 169300c..1ae79cc 100755 --- a/role_scripts/12/standby/ha_backup_job.sh +++ b/role_scripts/12/standby/ha_backup_job.sh @@ -101,7 +101,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/12/standby/run.sh b/role_scripts/12/standby/run.sh index da63842..d60ff98 100755 --- a/role_scripts/12/standby/run.sh +++ b/role_scripts/12/standby/run.sh @@ -168,7 +168,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/12/standby/warm_stanby.sh b/role_scripts/12/standby/warm_stanby.sh index 46de49a..7c182c6 100755 --- a/role_scripts/12/standby/warm_stanby.sh +++ b/role_scripts/12/standby/warm_stanby.sh @@ -50,7 +50,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/13/primary/start.sh b/role_scripts/13/primary/start.sh index cd44c9a..2993ac4 100755 --- a/role_scripts/13/primary/start.sh +++ b/role_scripts/13/primary/start.sh @@ -253,7 +253,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/13/standby/ha_backup_job.sh b/role_scripts/13/standby/ha_backup_job.sh index 7070688..9dbdf52 100755 --- a/role_scripts/13/standby/ha_backup_job.sh +++ b/role_scripts/13/standby/ha_backup_job.sh @@ -101,7 +101,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/13/standby/run.sh b/role_scripts/13/standby/run.sh index a71708e..259d4f7 100755 --- a/role_scripts/13/standby/run.sh +++ b/role_scripts/13/standby/run.sh @@ -171,7 +171,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/13/standby/warm_stanby.sh b/role_scripts/13/standby/warm_stanby.sh index cef8bae..f77be34 100755 --- a/role_scripts/13/standby/warm_stanby.sh +++ b/role_scripts/13/standby/warm_stanby.sh @@ -44,7 +44,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/14/primary/start.sh b/role_scripts/14/primary/start.sh index 0b552b5..d5780be 100755 --- a/role_scripts/14/primary/start.sh +++ b/role_scripts/14/primary/start.sh @@ -260,7 +260,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/14/standby/ha_backup_job.sh b/role_scripts/14/standby/ha_backup_job.sh index d306cca..5038380 100755 --- a/role_scripts/14/standby/ha_backup_job.sh +++ b/role_scripts/14/standby/ha_backup_job.sh @@ -101,7 +101,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/14/standby/run.sh b/role_scripts/14/standby/run.sh index e984a0c..74ea25a 100755 --- a/role_scripts/14/standby/run.sh +++ b/role_scripts/14/standby/run.sh @@ -171,7 +171,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/14/standby/warm_stanby.sh b/role_scripts/14/standby/warm_stanby.sh index f0a11c2..df05ee9 100755 --- a/role_scripts/14/standby/warm_stanby.sh +++ b/role_scripts/14/standby/warm_stanby.sh @@ -44,7 +44,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/15/primary/start.sh b/role_scripts/15/primary/start.sh index b87a383..f9b284a 100755 --- a/role_scripts/15/primary/start.sh +++ b/role_scripts/15/primary/start.sh @@ -261,7 +261,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/15/standby/ha_backup_job.sh b/role_scripts/15/standby/ha_backup_job.sh index 4157432..040a43c 100755 --- a/role_scripts/15/standby/ha_backup_job.sh +++ b/role_scripts/15/standby/ha_backup_job.sh @@ -103,7 +103,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/15/standby/run.sh b/role_scripts/15/standby/run.sh index 630af43..2db653a 100755 --- a/role_scripts/15/standby/run.sh +++ b/role_scripts/15/standby/run.sh @@ -170,7 +170,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/15/standby/warm_stanby.sh b/role_scripts/15/standby/warm_stanby.sh index d649ecd..d6ae859 100755 --- a/role_scripts/15/standby/warm_stanby.sh +++ b/role_scripts/15/standby/warm_stanby.sh @@ -45,7 +45,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/16/primary/start.sh b/role_scripts/16/primary/start.sh index 1e5174c..0e0c0c4 100755 --- a/role_scripts/16/primary/start.sh +++ b/role_scripts/16/primary/start.sh @@ -259,7 +259,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/16/standby/ha_backup_job.sh b/role_scripts/16/standby/ha_backup_job.sh index 8da687d..e9c8003 100755 --- a/role_scripts/16/standby/ha_backup_job.sh +++ b/role_scripts/16/standby/ha_backup_job.sh @@ -103,7 +103,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/16/standby/run.sh b/role_scripts/16/standby/run.sh index 079bfab..7a865db 100755 --- a/role_scripts/16/standby/run.sh +++ b/role_scripts/16/standby/run.sh @@ -172,7 +172,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/16/standby/warm_stanby.sh b/role_scripts/16/standby/warm_stanby.sh index a67f2ec..a1eff58 100755 --- a/role_scripts/16/standby/warm_stanby.sh +++ b/role_scripts/16/standby/warm_stanby.sh @@ -45,7 +45,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/17/primary/start.sh b/role_scripts/17/primary/start.sh index cbe4012..effed0c 100755 --- a/role_scripts/17/primary/start.sh +++ b/role_scripts/17/primary/start.sh @@ -261,7 +261,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/17/standby/ha_backup_job.sh b/role_scripts/17/standby/ha_backup_job.sh index 8da687d..e9c8003 100755 --- a/role_scripts/17/standby/ha_backup_job.sh +++ b/role_scripts/17/standby/ha_backup_job.sh @@ -103,7 +103,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/17/standby/run.sh b/role_scripts/17/standby/run.sh index d6e5c19..5e54fe0 100755 --- a/role_scripts/17/standby/run.sh +++ b/role_scripts/17/standby/run.sh @@ -173,7 +173,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/17/standby/warm_stanby.sh b/role_scripts/17/standby/warm_stanby.sh index a67f2ec..a1eff58 100755 --- a/role_scripts/17/standby/warm_stanby.sh +++ b/role_scripts/17/standby/warm_stanby.sh @@ -45,7 +45,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/18/primary/start.sh b/role_scripts/18/primary/start.sh index 87ac591..60b342c 100755 --- a/role_scripts/18/primary/start.sh +++ b/role_scripts/18/primary/start.sh @@ -257,7 +257,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/18/standby/ha_backup_job.sh b/role_scripts/18/standby/ha_backup_job.sh index 8da687d..e9c8003 100755 --- a/role_scripts/18/standby/ha_backup_job.sh +++ b/role_scripts/18/standby/ha_backup_job.sh @@ -103,7 +103,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/18/standby/run.sh b/role_scripts/18/standby/run.sh index d6e5c19..5e54fe0 100755 --- a/role_scripts/18/standby/run.sh +++ b/role_scripts/18/standby/run.sh @@ -173,7 +173,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/18/standby/warm_stanby.sh b/role_scripts/18/standby/warm_stanby.sh index a67f2ec..a1eff58 100755 --- a/role_scripts/18/standby/warm_stanby.sh +++ b/role_scripts/18/standby/warm_stanby.sh @@ -45,7 +45,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/9/primary/start.sh b/role_scripts/9/primary/start.sh index aa4c27c..9978c85 100755 --- a/role_scripts/9/primary/start.sh +++ b/role_scripts/9/primary/start.sh @@ -177,7 +177,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/9/standby/ha_backup_job.sh b/role_scripts/9/standby/ha_backup_job.sh index 8691783..28c891b 100755 --- a/role_scripts/9/standby/ha_backup_job.sh +++ b/role_scripts/9/standby/ha_backup_job.sh @@ -101,7 +101,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/9/standby/run.sh b/role_scripts/9/standby/run.sh index 7df2718..5b47a9f 100755 --- a/role_scripts/9/standby/run.sh +++ b/role_scripts/9/standby/run.sh @@ -160,7 +160,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do diff --git a/role_scripts/9/standby/warm_stanby.sh b/role_scripts/9/standby/warm_stanby.sh index 848c748..48184af 100755 --- a/role_scripts/9/standby/warm_stanby.sh +++ b/role_scripts/9/standby/warm_stanby.sh @@ -42,7 +42,9 @@ if [[ "$STREAMING" == "synchronous" ]]; then # setup synchronous streaming replication echo "synchronous_commit = ${SYNC_COMMIT_LEVEL:-remote_write}" >>/tmp/postgresql.conf - if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then + if [[ "${SYNC_USE_WILDCARD:-false}" == "true" ]]; then + names="*" + elif [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then names="" IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES" for _name in "${_standby_list[@]}"; do