Skip to content

[Bug]: Old primary CrashLoopBackOff after supervised switchover when an enforced parameter is decreased #10716

Open

Description

@ermakov-oleg

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything.

I have read the troubleshooting guide

  • Yes.

I am running a supported version of CloudNativePG

  • Yes.

Version

1.29.0

What version of Kubernetes are you using?

1.30

What is your Kubernetes environment?

Yandex Cloud Managed Kubernetes

How did you install the operator?

Helm

What happened?

After a supervised switchover the old primary ends up in CrashLoopBackOff with FATAL: recovery aborted because of insufficient parameter settings whenever an enforced parameter (max_connections etc.) was decreased in the spec before the switchover.

Related to #10395, but a distinct code path: there the parameter is removed from the spec; here it is present but decreased, and verifyParametersForFollower is skipped for a different reason — it short-circuits on IsPrimary(), and on the demoting pod IsPrimary() is still true when initialize() runs.

Reproduce

Reproduced cleanly on 1.29.0; the old primary loops every ~13 seconds with the FATAL below.

  1. Two-instance Cluster with max_connections: "150" and primaryUpdateStrategy: supervised.
  2. Wait until both instances report max_connections setting: 150 in pg_controldata.
  3. Decrease spec to max_connections: "100". Replica restarts and picks up the new value; primary stays on 150, cluster goes to phase=Waiting for user action.
  4. Trigger a supervised switchover.
  5. Old primary tries to rejoin as a standby and enters CrashLoopBackOff:
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 150.

Root cause

initialize() (internal/management/controller/instance_controller.go) calls verifyParametersForFollower first and verifyPgDataCoherenceForPrimary second. The follower check short-circuits on the demoting pod:

if isPrimary, _ := r.instance.IsPrimary(); isPrimary {
    return nil
}

IsPrimary() is still true at this point — standby.signal hasn't been written yet. The check is skipped.

verifyPgDataCoherenceForPrimary (instance_startup.go) then runs the switchover branch: WaitForPrimaryAvailable → pg_rewind → Demote(). Demote() only writes standby.signal and primary_conninfo; it does not align the enforced parameters. initialize() returns and PostgreSQL starts with the lower value, hits XLOG_PARAMETER_CHANGE from its own previous WAL, and aborts startup.

Proposed fix

Either re-run verifyParametersForFollower after Demote(), or call the same alignment from Demote() itself before writing standby.signal. The underlying check already does the right thing — it just isn't reached on this path.

Relevant log output

{"level":"info","msg":"Starting up pg_rewind","logger":"instance-manager"}
{"level":"info","logger":"pg_controldata","msg":"... max_connections setting: 150 ..."}
LOG: entering standby mode
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 150.

The old primary keeps looping; only deleting its PVC and letting CNPG re-bootstrap it via pg_basebackup from the new primary unblocks the cluster.

Code of Conduct

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

Activity

  1. dosubot commented on May 18, 2026

    @dosubot

    Your root cause analysis is accurate and well-documented. I verified it against the code:

    1. The IsPrimary() short-circuit — verifyParametersForFollower bails out early because IsPrimary() is still true when the demoting pod's initialize() runs [1]. The status only flips to false after Demote() writes standby.signal [2], which happens later in verifyPgDataCoherenceForPrimary [3].

    2. The ordering in initialize() — verifyParametersForFollower is called before verifyPgDataCoherenceForPrimary [4], so the parameter safety check runs before Demote() is invoked — hence the gap.

    This is indeed distinct from #10395 [5], which covers the "parameter removed from spec" case (a double-skip in LoadEnforcedParametersFromCluster and verifyParametersForFollower). Your scenario hits the same FATAL error but through the IsPrimary() timing path on the demoting pod specifically.

    The related PR #9952 fixed a parameter validation issue for replica clusters but doesn't address this standard-cluster supervised switchover path.

    Your proposed fix of re-running verifyParametersForFollower after Demote() (or aligning enforced parameters within Demote() itself) looks like the right approach — Demote() currently only writes standby.signal and primary_conninfo without touching the enforced parameters [6].

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about cloudnative-pg with Dosu Add Dosu to your team

  2. ardentperf commented on May 28, 2026

    @ardentperf
    Contributor

    this is straightforward. repro script that worked on my machine:

    ubuntu@cnpg1:~$ cat projects/cloudnative-pg/hack/reproduce-10716.sh

    #!/usr/bin/env bash
    # Reproduces https://github.com/cloudnative-pg/cloudnative-pg/issues/10716
    #
    # Usage:
    #   bash hack/reproduce-10716.sh           # build from local source and run
    #   bash hack/reproduce-10716.sh --cleanup # tear down the kind cluster and registry
    
    set -euo pipefail
    
    export PATH="${PATH}:/usr/local/go/bin"
    
    ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
    
    export CLUSTER_NAME="${CLUSTER_NAME:-cnpg-10716}"
    export TEST_UPGRADE_TO_V1="false"
    export NODES="1"
    export CNPG_DEPLOYMENT_METHOD="helm"
    
    PG_NAMESPACE="default"
    PG_IMAGE="ghcr.io/cloudnative-pg/postgresql:18.4-system-trixie"
    
    if [[ "${1:-}" == "--cleanup" ]]; then
      "${ROOT_DIR}/hack/setup-cluster.sh" teardown
      exit 0
    elif [[ -n "${1:-}" ]]; then
      echo "Usage: $0 [--cleanup]"; exit 1
    fi
    
    trap 'echo "FAILED at line $LINENO. To cleanup, run: $0 --cleanup"; exit 1' ERR
    
    "${ROOT_DIR}/hack/setup-cluster.sh" create load deploy
    make -C "${ROOT_DIR}" build-plugin
    CNPG_PLUGIN="${ROOT_DIR}/bin/kubectl-cnpg"
    
    kubectl apply -f - <<EOF
    apiVersion: postgresql.cnpg.io/v1
    kind: Cluster
    metadata:
      name: cluster-10716
      namespace: ${PG_NAMESPACE}
    spec:
      instances: 2
      imageName: ${PG_IMAGE}
      primaryUpdateStrategy: supervised
      postgresql:
        parameters:
          max_connections: "150"
      storage:
        size: 1Gi
    EOF
    
    kubectl wait cluster/cluster-10716 --for=condition=Ready --timeout=300s -n "${PG_NAMESPACE}"
    
    kubectl patch cluster cluster-10716 -n "${PG_NAMESPACE}" --type=merge \
      -p '{"spec":{"postgresql":{"parameters":{"max_connections":"100"}}}}'
    
    for i in $(seq 1 60); do
      phase=$(kubectl get cluster cluster-10716 -n "${PG_NAMESPACE}" -o jsonpath='{.status.phase}' 2>/dev/null || echo "")
      echo "[${i}/60] phase: ${phase}"
      [[ "${phase}" == *"Waiting for user action"* ]] && break
      [[ "${i}" -eq 60 ]] && { echo "ERROR: timed out waiting for 'Waiting for user action'"; exit 1; }
      sleep 5
    done
    
    PRIMARY=$(kubectl get cluster cluster-10716 -n "${PG_NAMESPACE}" -o jsonpath='{.status.currentPrimary}')
    NEW_PRIMARY=$([[ "${PRIMARY}" == "cluster-10716-1" ]] && echo "cluster-10716-2" || echo "cluster-10716-1")
    
    "${CNPG_PLUGIN}" promote cluster-10716 "${NEW_PRIMARY}" -n "${PG_NAMESPACE}"
    
    CRASH_POD=""
    for i in $(seq 1 36); do
      sleep 5
      kubectl get pods -n "${PG_NAMESPACE}" -l cnpg.io/cluster=cluster-10716 \
        -o custom-columns='NAME:.metadata.name,READY:.status.containerStatuses[0].ready,RESTARTS:.status.containerStatuses[0].restartCount,WAITING:.status.containerStatuses[0].state.waiting.reason' \
        2>/dev/null || true
      CRASH_POD=$(kubectl get pods -n "${PG_NAMESPACE}" -l cnpg.io/cluster=cluster-10716 \
        -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.containerStatuses[0].state.waiting.reason}{"\n"}{end}' 2>/dev/null \
        | awk '/CrashLoopBackOff/{print $1}' || true)
      [[ -n "${CRASH_POD}" ]] && break
    done
    
    if [[ -n "${CRASH_POD}" ]]; then
      kubectl logs -n "${PG_NAMESPACE}" "${CRASH_POD}" --previous 2>/dev/null \
        | grep -E "FATAL|DETAIL|recovery aborted|insufficient parameter|max_connections" | head -10 || true
      echo "RESULT: BUG REPRODUCED (issue #10716) — ${CRASH_POD} is in CrashLoopBackOff"
      echo "To clean up: bash hack/reproduce-10716.sh --cleanup"
      exit 0
    else
      echo "RESULT: bug not reproduced within timeout"
      echo "To clean up: bash hack/reproduce-10716.sh --cleanup"
      exit 1
    fi
    
  3. github-actions commented on Jul 28, 2026

    @github-actions
    Contributor

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

  4. ermakov-oleg commented on Jul 28, 2026

    @ermakov-oleg
    ContributorAuthor

    still relevant

  5. github-actions commented on Oct 11, 2026

    @github-actions
    Contributor

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

  6. ardentperf commented on Oct 12, 2026

    @ardentperf
    Contributor

    i think this might still repro on 1.30.1

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