Skip to content

fix(instance): align enforced parameters on the demotion path (#10716) - #10856

Open
ermakov-oleg wants to merge 2 commits into
cloudnative-pg:mainfrom
ermakov-oleg:dev/10716
Open

ermakov-oleg wants to merge 2 commits into
cloudnative-pg:mainfrom
ermakov-oleg:dev/10716

Conversation

@ermakov-oleg

Copy link
Copy Markdown
Contributor

When a hot-standby-sensitive ("enforced") parameter such as max_connections is decreased in the spec under primaryUpdateStrategy: supervised and a switchover then happens, the demoted old primary cannot rejoin: it starts as a standby with the lower value while pg_controldata still holds the higher one, and PostgreSQL aborts recovery. The pod stays in CrashLoopBackOff and the only way out is to wipe its PVC and let CNPG re-bootstrap it.

FATAL:  recovery aborted because of insufficient parameter settings
DETAIL: max_connections = 100 is a lower setting than on the primary server, where its value was 150.

Root cause. initialize() runs verifyParametersForFollower before verifyPgDataCoherenceForPrimary. On the demoting pod IsPrimary() is still true at that point (standby.signal is written later, inside Demote()), so the follower parameter alignment short-circuits and never runs. Demote() only writes standby.signal/primary_conninfo and does not touch the enforced parameters, so the standby comes up with the decreased value and aborts recovery.

Fix.

  • Align the enforced parameters from pg_controldata right after Demote() (both demotion branches of verifyPgDataCoherenceForPrimary), through a dedicated alignEnforcedParametersForFollower. It intentionally bypasses the cnpg_initialized startup-flag guard used by verifyParametersForFollower: a former primary that was never a follower has no such flag, so merely re-running verifyParametersForFollower after Demote() would short-circuit again and silently skip the alignment. Calling the alignment directly makes it run on the first standby start, before recovery begins.
  • For a decrease under the supervised strategy, the PhaseWaitingForUser reason now points to an in-place primary restart instead of a switchover: a switchover does not converge a decrease (the promoted replica still carries the higher value, since followers are kept aligned upward), an in-place restart of the primary does.

Covered by a new e2e suite (supervised_switchover_param_test.go).

Closes #10716

@ermakov-oleg
ermakov-oleg requested a review from a team June 9, 2026 14:45
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.28 labels Jun 9, 2026
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working E2E tests E2E tests tickets for easy triage on release process release-1.28 release-1.30 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Old primary CrashLoopBackOff after supervised switchover when an enforced parameter is decreased

3 participants