Skip to content

Use SYNC_REPLICATION_MODE, NUM_SYNC_REPLICAS, SYNC_COMMIT_LEVEL in sync scripts (v9–v18)#61

Open
souravbiswassanto wants to merge 2 commits into
masterfrom
sync-improve-pg
Open

Use SYNC_REPLICATION_MODE, NUM_SYNC_REPLICAS, SYNC_COMMIT_LEVEL in sync scripts (v9–v18)#61
souravbiswassanto wants to merge 2 commits into
masterfrom
sync-improve-pg

Conversation

@souravbiswassanto

@souravbiswassanto souravbiswassanto commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

Extends the synchronous replication block in all 40 role scripts (v9–v18) to use SYNC_STANDBY_NAMES when set, falling back to the existing auto-generation loop when not.

Logic (all scripts: primary/start.sh, standby/run.sh, standby/warm_stanby.sh, standby/ha_backup_job.sh)

if [[ -n "${SYNC_STANDBY_NAMES:-}" ]]; then
    # Use explicit ordered list from operator
    IFS=',' read -ra _standby_list <<< "$SYNC_STANDBY_NAMES"
    for _name in "${_standby_list[@]}"; do
        names+="\"${_name}\","
    done
    names="${names%,}"
else
    # Auto-generate from pod index (existing behaviour)
    self_idx=${HOSTNAME##*[!0-9]}
    ...
fi
echo "synchronous_standby_names = '${SYNC_REPLICATION_MODE:-ANY} ${NUM_SYNC_REPLICAS:-1} ("$names")'"

What this unlocks

  • Priority ordering (mode: First): FIRST 1 ("postgres-2","postgres-0") — explicit preference
  • Selective exclusion: omit cross-region standbys from the sync set

What is NOT changed

remote-replica.sh files — those use '*' (all standbys), unrelated to this feature.

Backwards compatibility

Shell :- defaults on all three env vars mean scripts behave identically when running against an older operator that doesn't set these vars.

Dependency

https://github.com/kubedb/postgres/pull/904 (operator) / kubedb/apimachinery#1782 (API)

Test plan

  • All 10 versions tested with no env vars — behaviour unchanged
  • SYNC_STANDBY_NAMES=postgres-2,postgres-0 SYNC_REPLICATION_MODE=FIRST NUM_SYNC_REPLICAS=1 — verify synchronous_standby_names = 'FIRST 1 ("postgres-2","postgres-0")'
  • Verify 0 remote-replica.sh files touched

🤖 Generated with Claude Code

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 <sourav.cse4.bu@gmail.com>
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 <sourav.cse4.bu@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant