Repository navigation
fix(instance): enforce hot standby sensitive parameters removed from the Cluster spec - #11236
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
/test |
|
@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/29830079606 |
|
Thanks for this! I pushed a couple of commits on top, let me know what you think. I inlined the If you're fine with the changes, could you update the PR description accordingly? Happy to revisit anything you disagree with. |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/38722625573 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/38901761837 |
|
/test |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/38902284003 |
|
/test |
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/40533252136 |
|
/test |
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/40660201604 |
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]>
…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)
…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)
|
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 until a |
Closes #10395
What this fixes
When a hot standby sensitive parameter (e.g.
max_connections) is removed fromspec.postgresql.parameters,verifyParametersForFollowerskips it entirely (the!found → continuebranch), so the protective value frompg_controldatais 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:and stays in
CrashLoopBackOff.In my tests the window stays open with
primaryUpdateStrategy: supervised, where the primary keeps running with the old (higher) value. Withunsuperviseda 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
mainthe cluster sits inWaiting for user actionwith the mismatch armed, and the crash fires on the next ordinary follower restart. Reproduced on unpatchedmain(4e57365d5): a deleted replica pod went intoCrashLoopBackOffwithin 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. Thepg_controldatavalue 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_controldatavalue unconditionally: I tried that first, and it makes the written configuration permanently diverge from the cluster spec. The operator reconcilescustom.confback, PostgreSQL flags the restart-required GUCs aspending_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). Thepostgres -Cfallback 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)
4e57365d5max_connections: "200"from spec, then delete a replica podCrashLoopBackOffin ~9smax_connections = 200as the floorunsupervisedmake lintandmake testpass,make generate manifestsproduces 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 extractedalignEnforcedParametersForFollower). 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.