Skip to content

[Bug]: Replica CrashLoopBackOff when replication-sensitive parameter is removed from Cluster spec #10395

Description

@gmautner

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

[email protected]

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

  1. Create a 3-instance Cluster with max_connections: "200" in spec.postgresql.parameters.
  2. Wait for all instances to be healthy.
  3. Remove max_connections from the spec (or remove the parameters map entirely).
  4. The operator updates custom.conf on all instances, removing the max_connections line. Running instances keep 200 (restart-required param).
  5. Trigger a failover. The new primary restarts and picks up the PG default of 100.
  6. A replica whose last checkpoint was written with max_connections=200 in pg_controldata tries 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-db

Relevant 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 recovery

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    triage
    on Mar 31, 2026
  2. dosubot commented on Mar 31, 2026

    @dosubot

    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:

    1. LoadEnforcedParametersFromCluster in restore.go silently omits any parameter not present in the Cluster spec [1].
    2. verifyParametersForFollower in instance_controller.go then skips parameters missing from the clusterParams map, so the protective write to custom.conf never happens [2].

    The five tracked parameters (max_connections, max_wal_senders, max_worker_processes, max_prepared_transactions, max_locks_per_transaction) are all defined in pgControldataSettingsToParamsMap [3].

    One thing worth noting for the fix approach: there's an existing pattern in GetDecreasedSensibleSettings (in probes.go) that already handles this gracefully for running instances — it uses SQL coalesce(new_setting, default_setting) to get the effective value even when a parameter is removed from the spec [4]. The verifyParametersForFollower path 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_controldata value directly when the spec is silent — since the goal is to ensure replicas can start, writing the pg_controldata value to custom.conf is 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.

    Leave Feedback Ask Dosu about cloudnative-pg Share Dosu with your team

  3. added
    bug 🐛
    and removed on Jun 21, 2026
  4. ichibahn commented on Jul 1, 2026

    @ichibahn
    Contributor

    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 main built from 025a9be5 (operator 1.30.0-rc1-dev59, unmodified) — PG 18.4, k8s v1.36.1 (kind). The !found skip is still present on current main (cc82f2a7).

    One thing worth flagging: the trigger seems to hinge on primaryUpdateStrategy.

    Reproduction (3 steps) + evidence

    Cluster: 3 instances, primaryUpdateStrategy: supervised, postgresql.parameters.max_connections: "200" → all instances healthy at 200.

    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:

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

    pg_controldata of that same instance at startup still shows the old value while it is being started with 100:

    Database cluster state:  in archive recovery
    max_connections setting: 200
    

    Root cause (as already noted in the issue): in verifyParametersForFollower (internal/management/controller/instance_controller.go) and LoadEnforcedParametersFromCluster (pkg/management/postgres/restore.go), when an enforced parameter is absent from the Cluster spec the code continues (skips), so the protective floor is never written and the follower comes up at the PostgreSQL default.

    Proposed direction: in the !found branch, instead of skipping, use the value already reported by the follower's pg_controldata as the floor (write it to custom.conf, same as the enforcedparam > clusterparam case). Writing the pg_controldata value 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:

    1. This is currently assigned to @gbartolini — is this open for me to pick up, or are you already on it?
    2. Since fix(instance): align enforced parameters on the demotion path (#10716) #10856 looks like it may already be reworking the follower parameter-alignment path, would you prefer the "removed from spec" (!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!

  5. ichibahn commented on Jul 21, 2026

    @ichibahn
    Contributor

    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 main first, then confirmed it no longer happens with the patch, plus an unsupervised control run).

    One correction to my earlier comment: I first implemented what I suggested there — always writing the pg_controldata value when the parameter is absent from the spec — and in my tests it put followers into an endless restart loop (the operator reconciles custom.conf back to the spec, the restart-required GUCs get flagged pending_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.

  6. ichibahn commented on Jul 28, 2026

    @ichibahn
    Contributor

    Small status update after a quiet week — flagging in case this one slipped past the review queue.

    Nothing has changed since @mnencia ran /test on 21 July:
    same head commit (eee242d4), kind matrix green on all 12 combinations.

    The red Require labels check is stale — it ran before the ok to merge label 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.

  7. github-actions commented on Sep 26, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

  8. github-actions commented on Oct 10, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

  9. 1 remaining item

  10. added this to the 1.31.0 milestone on Oct 20, 2026
  11. added theissue type on Oct 20, 2026
  12. moved this from Ready to Waiting for Second Review in CloudNativePG operator developmenton Oct 20, 2026
  13. moved this from Waiting for Second Review to Done in CloudNativePG operator developmenton Oct 28, 2026
  14. added a commit that references this issue on Oct 28, 2026
    f197e13
  15. added 2 commits that reference this issue on Oct 28, 2026
    bac7e5f
    c9b06b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛no-stale

Type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions