Repository navigation
Description
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I have read the troubleshooting guide and I think this is a new bug.
Contact Details
Version
1.28 (latest patch)
What version of Kubernetes are you using?
1.33
What is your Kubernetes environment?
Cloud: Amazon EKS
How did you install the operator?
Helm
What happened?
What happened
Removing a replication-sensitive parameter (e.g. max_connections) from spec.postgresql.parameters causes replicas that need WAL replay to enter CrashLoopBackOff with:
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.
How to reproduce
- Create a 3-instance Cluster with
max_connections: "200"inspec.postgresql.parameters. - Wait for all instances to be healthy.
- Remove
max_connectionsfrom the spec (or remove theparametersmap entirely). - The operator updates
custom.confon all instances, removing themax_connectionsline. Running instances keep 200 (restart-required param). - Trigger a failover. The new primary restarts and picks up the PG default of 100.
- A replica whose last checkpoint was written with
max_connections=200inpg_controldatatries to start with 100 → FATAL → CrashLoopBackOff.
Root cause
The safety mechanism in verifyParametersForFollower is designed to catch exactly this kind of mismatch, but it silently skips parameters that are absent from the Cluster spec.
LoadEnforcedParametersFromCluster (pkg/management/postgres/restore.go:785):
for _, param := range pgControldataSettingsToParamsMap {
value, found := clusterParams[param]
if !found {
continue // param removed from spec → not returned at all
}
// ...
}verifyParametersForFollower (internal/management/controller/instance_controller.go:557):
for key, enforcedparam := range controldataParams {
clusterparam, found := clusterParams[key]
if !found {
continue // pg_controldata says 200, spec says nothing → skip the safety check
}
if enforcedparam > clusterparam {
options[key] = strconv.Itoa(enforcedparam)
}
}When a parameter is present in pg_controldata (e.g. max_connections = 200) but absent from the Cluster spec, the !found branch skips it. The safety write to custom.conf never happens, and PostgreSQL crashes during recovery.
Proposed fix
When a replication-sensitive parameter is absent from the Cluster spec, LoadEnforcedParametersFromCluster (or verifyParametersForFollower directly) should fall back to the PostgreSQL default value for that parameter instead of skipping it.
For example, in verifyParametersForFollower:
for key, enforcedparam := range controldataParams {
clusterparam, found := clusterParams[key]
if !found {
clusterparam = postgresDefaultFor(key) // e.g. 100 for max_connections
}
if enforcedparam > clusterparam {
options[key] = strconv.Itoa(enforcedparam)
}
}This way, if pg_controldata records max_connections = 200 and the spec doesn't set it (defaulting to 100), the function would write max_connections = 200 into custom.conf before starting PostgreSQL — preventing the crash.
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg
namespace: utilities
spec:
instances: 3
imageName: ghcr.io/cloudnative-pg/postgresql:16
bootstrap:
initdb:
database: admin
owner: admin
enablePDB: false
plugins:
- isWALArchiver: true
name: barman-cloud.cloudnative-pg.io
parameters:
barmanObjectName: pg-backup
postgresql:
synchronous:
dataDurability: required
failoverQuorum: true
method: any
number: 1
# NOTE: max_connections was previously set to "200" here
# and then removed, which triggered the bug
resources:
limits:
cpu: "4"
memory: 16Gi
requests:
cpu: 1200m
memory: 16Gi
storage:
size: 300Gi
storageClass: gp3-dbRelevant log output
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.
HINT: You can restart the server after making the necessary configuration changes.
LOG: startup process (PID 29) exited with exit code 1
LOG: aborting startup due to startup process failure
LOG: database system is shut down
# pg_controldata shows:
# max_connections setting: 200
# Latest checkpoint's TimeLineID: 25
# Database cluster state: in archive recoveryCode of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
dosubot commentedon Mar 31, 2026
Hi @gmautner! I'm Dosu and I’m helping the cloudnative-pg team.
Your root cause analysis looks spot-on. I verified it against the code — the bug is a double-skip across two functions:
LoadEnforcedParametersFromClusterinrestore.gosilently omits any parameter not present in the Cluster spec [1].verifyParametersForFollowerininstance_controller.gothen skips parameters missing from theclusterParamsmap, so the protective write tocustom.confnever happens [2].The five tracked parameters (
max_connections,max_wal_senders,max_worker_processes,max_prepared_transactions,max_locks_per_transaction) are all defined inpgControldataSettingsToParamsMap[3].One thing worth noting for the fix approach: there's an existing pattern in
GetDecreasedSensibleSettings(inprobes.go) that already handles this gracefully for running instances — it uses SQLcoalesce(new_setting, default_setting)to get the effective value even when a parameter is removed from the spec [4]. TheverifyParametersForFollowerpath could adopt a similar fallback-to-default strategy, which is essentially what your proposed fix does.A related but distinct issue for replica clusters was fixed in PR #9952, but that didn't address this parameter-removal scenario.
One design consideration: rather than maintaining a hardcoded map of PostgreSQL defaults (which can vary across major versions), an alternative approach might be to simply use the
pg_controldatavalue directly when the spec is silent — since the goal is to ensure replicas can start, writing thepg_controldatavalue tocustom.confis always safe regardless of what the default is.It looks like you also filed this as issue #10393 [5] — you may want to close one as a duplicate.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
ichibahn commentedon Jul 1, 2026
I took a look at this and reproduced it on the current
main. Before doing anything I'd like to check the direction with you, since it looks related to #10716 / #10856 (please correct me if I'm misreading the overlap).Reproduced on
mainbuilt from025a9be5(operator1.30.0-rc1-dev59, unmodified) — PG 18.4, k8s v1.36.1 (kind). The!foundskip is still present on currentmain(cc82f2a7).One thing worth flagging: the trigger seems to hinge on
primaryUpdateStrategy.unsupervised, the operator gracefully rolls every instance down to the new value (each re-checkpoints, sopg_controldatafollows), nocontroldata=200 / config=100window is left open, and in my repro I did not observe the crash.supervised, the primary stays at200, so removing the parameter restarts a follower at the default100while its ownpg_controldata(and the primary) still say200— which is the exact mismatch. This looks like thesupervisedpath discussed in [Bug]: Old primary CrashLoopBackOff after supervised switchover when an enforced parameter is decreased #10716 / fix(instance): align enforced parameters on the demotion path (#10716) #10856, though I may be misreading how those overlap.Reproduction (3 steps) + evidence
Cluster: 3 instances,
primaryUpdateStrategy: supervised,postgresql.parameters.max_connections: "200"→ all instances healthy at200.kubectl patch cluster cluster-10395 --type=json \ -p '[{"op":"remove","path":"/spec/postgresql/parameters/max_connections"}]'A replica immediately enters
CrashLoopBackOff(no manual switchover needed). Its PostgreSQL log:pg_controldataof that same instance at startup still shows the old value while it is being started with100:Root cause (as already noted in the issue): in
verifyParametersForFollower(internal/management/controller/instance_controller.go) andLoadEnforcedParametersFromCluster(pkg/management/postgres/restore.go), when an enforced parameter is absent from the Cluster spec the codecontinues (skips), so the protective floor is never written and the follower comes up at the PostgreSQL default.Proposed direction: in the
!foundbranch, instead of skipping, use the value already reported by the follower'spg_controldataas the floor (write it tocustom.conf, same as theenforcedparam > clusterparamcase). Writing thepg_controldatavalue is always safe to let the follower start and avoids maintaining a hard-coded map of per-version PostgreSQL defaults.Questions before I open anything:
!found) case be handled there, or as a small independent PR against this issue? Happy to go whichever way keeps it easiest to review.Thanks!
ichibahn commentedon Jul 21, 2026
Following up on my comment above — to make the discussion concrete, I opened #11236 with the fix and the verification I ran (kind, supervised, PG 18.4: reproduced the crash on unpatched
mainfirst, then confirmed it no longer happens with the patch, plus anunsupervisedcontrol run).One correction to my earlier comment: I first implemented what I suggested there — always writing the
pg_controldatavalue when the parameter is absent from the spec — and in my tests it put followers into an endless restart loop (the operator reconcilescustom.confback to the spec, the restart-required GUCs get flaggedpending_restart, and the pod is recreated over and over). So the PR follows the fallback-to-default direction from the issue description instead, resolved dynamically by asking PostgreSQL what it would actually start with (postgres -C) — which also avoids a hardcoded per-version table of defaults. Details and evidence are in the PR description.@gbartolini this is still assigned to you — if you were already on it or prefer a different shape (e.g. folding it into the #10856 work), happy to adjust or step back. "Allow edits by maintainers" is enabled on the PR.
ichibahn commentedon Jul 28, 2026
Small status update after a quiet week — flagging in case this one slipped past the review queue.
Nothing has changed since @mnencia ran
/teston 21 July:same head commit (
eee242d4), kind matrix green on all 12 combinations.The red
Require labelscheck is stale — it ran before theok to mergelabel existed. Adding the label re-triggered the workflow (run 29840420654), but that run is waiting for maintainer approval and hasn't executed yet. It should pass once approved.I've intentionally held off on rebasing, since a push from me would reset the workflows to "waiting for approval" and invalidate the green e2e run above. Happy to rebase, or add an e2e test covering the parameter-removal scenario, if either would help move this along.
github-actions commentedon Sep 26, 2026
This issue is stale because it has been open for 60 days with no activity.
github-actions commentedon Oct 10, 2026
This issue was closed because it has been inactive for 14 days since being marked as stale.
1 remaining item
fix(instance): keep replicas from crash-looping after removing a hot …
fix(instance): keep replicas from crash-looping after removing a hot …
fix(instance): keep replicas from crash-looping after removing a hot …