Skip to content

fix(instance): enforce hot standby sensitive parameters removed from the Cluster spec - #11236

Merged
leonardoce merged 5 commits into
cloudnative-pg:mainfrom
ichibahn:dev/10395
Oct 28, 2026
Merged

leonardoce merged 5 commits into
cloudnative-pg:mainfrom
ichibahn:dev/10395

Conversation

@ichibahn

@ichibahn ichibahn commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10395

What this fixes

When a hot standby sensitive parameter (e.g. max_connections) is removed from spec.postgresql.parameters, verifyParametersForFollower skips it entirely (the !found → continue branch), so the protective value from pg_controldata is never written to the local configuration. Any follower that restarts after that point — pod eviction, drain, node restart — comes up with the PostgreSQL default and aborts recovery:

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 200.

and stays in CrashLoopBackOff.

In my tests the window stays open with primaryUpdateStrategy: supervised, where the primary keeps running with the old (higher) value. With unsupervised a plain removal converged cleanly in my environment, but the original report shows the same window can open there too when a failover lands mid-rollout — same root cause, different trigger.

Note on the trigger: since #11130 the rollout no longer restarts replicas immediately after the change, so on current main the cluster sits in Waiting for user action with the mismatch armed, and the crash fires on the next ordinary follower restart. Reproduced on unpatched main (4e57365d5): a deleted replica pod went into CrashLoopBackOff within seconds.

The fix

For parameters missing from the cluster spec, resolve the value the server is actually going to start with by asking PostgreSQL itself via postgres -C <name>. This works while the server is down, and returns the built-in default when no configuration file sets the parameter. The pg_controldata value is then enforced only when it is higher — the same comparison the issue proposes, but resolving the default dynamically instead of maintaining a hard-coded per-version map.

I deliberately did not enforce the pg_controldata value unconditionally: I tried that first, and it makes the written configuration permanently diverge from the cluster spec. The operator reconciles custom.conf back, PostgreSQL flags the restart-required GUCs as pending_restart (a file-entry change counts even when the value is unchanged), and the operator recreates the follower in an endless recreate loop (~14 s period). The postgres -C fallback writes nothing in the common case, so no such loop can start.

The decision logic is extracted into a pure function (enforcedParametersToAlign) with unit tests; behaviour for parameters that are present in the spec is unchanged. Happy to add an e2e test for the removal scenario if you'd like one.

How I verified it (kind, 3-instance cluster, PG 18.4, supervised)

Scenario Unpatched 4e57365d5 With this fix
remove max_connections: "200" from spec, then delete a replica pod CrashLoopBackOff in ~9s Ready in ~13s, no crash; instance manager writes only max_connections = 200 as the floor
observed for 3 more minutes in the armed state n/a (crashed) 0 pod recreations
control: same removal with default unsupervised no crash (converges) unchanged — full rolling convergence to 100, 0 recreations

make lint and make test pass, make generate manifests produces no diff.

Relationship to #10716 / #10856

#10716 is the sibling issue on the demotion path (old primary after a supervised switchover); #10856 fixes that by re-aligning parameters right after Demote(). This PR addresses a different trigger — the parameter being absent from the spec — which #10856 does not change (the skip remains inside the extracted alignEnforcedParametersForFollower). I test-merged #10856 into this branch: no conflicts, and the two fixes compose (their new function ends up calling the fallback introduced here). Happy to rebase in whichever order is easier to review.

@ichibahn
ichibahn requested a review from a team July 21, 2026 09:07
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🐛 Something isn't working release-1.28 release-1.29 release-1.30 labels Jul 21, 2026
@cnpg-bot cnpg-bot added the backport-requested ◀️ This pull request should be backported to all supported releases label Jul 21, 2026
@github-actions

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

@mnencia

mnencia commented Jul 21, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Jul 21, 2026
@armru
armru requested review from a team, NiccoloFei and litaocdl as code owners October 15, 2026 10:43
@armru

armru commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thanks for this! I pushed a couple of commits on top, let me know what you think. I inlined the postgres -C fallback where the loop used to continue, which made the helper and its unit tests unnecessary. I also added an e2e test for the supervised case: it fails on main with the "insufficient parameter settings" crash and passes with your fix.

If you're fine with the changes, could you update the PR description accordingly? Happy to revisit anything you disagree with.

@armru

armru commented Oct 15, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Oct 16, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Oct 16, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

ichibahn and others added 5 commits October 28, 2026 15:10
When a hot standby sensitive parameter (e.g. max_connections) is removed
from the Cluster spec, verifyParametersForFollower used to skip it
entirely: the protective value from pg_controldata was never written to
the local configuration, so a follower restarting after the change came
up with the PostgreSQL default and aborted recovery with:

    FATAL: recovery aborted because of insufficient parameter settings

ending up in CrashLoopBackOff. This surfaces with
primaryUpdateStrategy: supervised, where the primary keeps running with
the old (higher) value while a follower can be restarted at any time by
ordinary events (eviction, drain, node restart).

For parameters missing from the spec, resolve the value the server is
actually going to start with by asking PostgreSQL itself
(postgres -C <name>), and enforce the pg_controldata value only when it
is higher. Unconditionally enforcing the pg_controldata value would make
the local configuration permanently diverge from the cluster spec,
putting the follower into an endless restart loop.

Closes cloudnative-pg#10395

Assisted-by: Claude Fable 5
Signed-off-by: Jihyun Bahn <[email protected]>
Look up the startup value of a parameter missing from the cluster spec
directly in the comparison loop, where the old code skipped it. After
the lookup every parameter has a value to compare against, so the
extracted helper and its "missing counts as zero" rule never applied
in production, and its unit tests only exercised the comparison.

Signed-off-by: Armando Ruocco <[email protected]>
With primaryUpdateStrategy set to supervised, removing max_connections
from the spec leaves the primary running with the old, higher value
until the user acts. A replica restarted in that window has to keep the
value recorded in pg_controldata, or it aborts recovery with
"insufficient parameter settings". Cover that window, then restart the
primary in place and check that every instance converges to the
PostgreSQL default without a switchover.

Signed-off-by: Armando Ruocco <[email protected]>
When the configuration files change while PostgreSQL is still starting
up, the reconciliation loop ends before reloading it, and the following
loops find the files already updated, so the reload is lost and
PostgreSQL keeps the values it read at startup. A follower restarted
with a hot standby sensitive parameter enforced from pg_controldata is
exposed to this, because the next loop removes the enforced value right
after PostgreSQL has been started: the decrease is never detected, and
the follower is not restarted after the primary.

Keep the reload pending across loops until PostgreSQL is reloaded, or
until a restart loads the configuration files. For the same reason, a
refresh of the configuration files that fails now still reports the
files it already changed.

Signed-off-by: Armando Ruocco <[email protected]>
…re.go

The helpers that read the hot standby sensitive parameters from
pg_controldata, from the Cluster spec and from the PostgreSQL startup
configuration are used well beyond the restore path: by the instance
manager when a follower starts and by the readiness probe. Group them in
parameters.go, together with their tests, so they are easy to find.

Signed-off-by: Leonardo Cecchi <[email protected]>
@leonardoce
leonardoce merged commit c9b06b3 into cloudnative-pg:main Oct 28, 2026
29 checks passed
cnpg-bot pushed a commit that referenced this pull request Oct 28, 2026
…standby parameter (#11236)

Removing a hot standby sensitive parameter (e.g. max_connections) from
the Cluster spec could leave a replica unable to restart. With
`primaryUpdateStrategy: supervised`, the primary keeps running with the old,
higher value until you act. A replica restarted in that window (eviction,
drain, node restart) came up with the PostgreSQL default and aborted
recovery with:

    FATAL: recovery aborted because of insufficient parameter settings

It then ended up in CrashLoopBackOff.

A replica now keeps the value recorded in pg_controldata for such a
parameter while it is higher than the value PostgreSQL would start with.
Once the primary is restarted, every instance converges to the PostgreSQL
default without a switchover.

A related issue is also fixed. If the configuration files changed while
PostgreSQL was still starting up, the reload was lost and PostgreSQL kept
the values it read at startup. A replica could then miss the decrease
and not be restarted after the primary. The reload now stays pending
until it runs, or until a restart loads the new configuration.

Closes #10395

Assisted-by: Claude Fable 5

Signed-off-by: Jihyun Bahn <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Leonardo Cecchi <[email protected]>
(cherry picked from commit c9b06b3)
leonardoce added a commit that referenced this pull request Oct 28, 2026
…standby parameter (#11236)

Removing a hot standby sensitive parameter (e.g. max_connections) from
the Cluster spec could leave a replica unable to restart. With
`primaryUpdateStrategy: supervised`, the primary keeps running with the old,
higher value until you act. A replica restarted in that window (eviction,
drain, node restart) came up with the PostgreSQL default and aborted
recovery with:

    FATAL: recovery aborted because of insufficient parameter settings

It then ended up in CrashLoopBackOff.

A replica now keeps the value recorded in pg_controldata for such a
parameter while it is higher than the value PostgreSQL would start with.
Once the primary is restarted, every instance converges to the PostgreSQL
default without a switchover.

A related issue is also fixed. If the configuration files changed while
PostgreSQL was still starting up, the reload was lost and PostgreSQL kept
the values it read at startup. A replica could then miss the decrease
and not be restarted after the primary. The reload now stays pending
until it runs, or until a restart loads the new configuration.

Closes #10395

Assisted-by: Claude Fable 5

Signed-off-by: Jihyun Bahn <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Leonardo Cecchi <[email protected]>
(cherry picked from commit c9b06b3)
(cherry picked from commit f197e13)
@iambilotta

Copy link
Copy Markdown

For anyone searching for this symptom: we hit what looks like the same lost reload on 1.30.1, showing up differently. A single-instance cluster with synchronizeLogicalDecoding and sync_replication_slots = on (PostgreSQL 18.6-based image) sometimes came up with its own HA slot still in the running synchronized_standby_slots, although custom.conf didn't contain it. Every failover logical slot then waited, logging

WARNING:  replication slot "_cnpg_anima_b_1" specified in parameter "synchronized_standby_slots" does not exist

until a pg_reload_conf() or a pod restart. On kind, 1.30.1 did this in 2 of 3 fresh bootstraps; the release-1.30 testing image (1.30.1-dev114, ca59f4b) in none of 5, and the failover slot decoded normally. Small sample, but it matches the pending reload added here. Thanks!

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 ok to merge 👌 This PR can be merged 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]: Replica CrashLoopBackOff when replication-sensitive parameter is removed from Cluster spec

6 participants