Skip to content

Replica CrashLoopBackOff when replication-sensitive parameter is removed from Cluster spec #10393

Closed as duplicate

Description

@gmautner

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.

Environment

  • CNPG operator: 1.28.0 (also verified the code is identical on current main)
  • PostgreSQL: 16
  • Kubernetes: EKS

Activity

  1. gmautner commented on Mar 31, 2026

    @gmautner
    Author

    Duplicate — re-filed using the repository's bug report form.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions