Skip to content

[Bug]: Instance is never ready due to dataDurability preferred + failoverQuorum interaction #10547

Closed as not planned

Description

@augustoribeiro

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.35

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

This can be recreated in the CNPG kind cluster test setup by doing: ./hack/setup-cluster.sh create load deploy and applying the cluster configuration provided.

The problem happens if you have a cluster with dataDurability: preferred and failoverQuorum: true and also have a streaming startup probe. In this case the cluster never becomes ready since the replica instance cannot connect to the primary.

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:  
  name: cluster-example
spec:
  imageName: ghcr.io/cloudnative-pg/postgresql:15.15-202512080807-system-bullseye
  storage:
    size: 1Gi
  instances: 2
  replicationSlots:
    highAvailability:
      enabled: true
      slotPrefix: _cnpg_
      synchronizeLogicalDecoding: true
    synchronizeReplicas:
      enabled: true
    updateInterval: 30
  postgresql:
    parameters:
      pg_failover_slots.synchronize_slot_names: "name_like:%"
      hot_standby_feedback: "on"
    shared_preload_libraries:
      - pg_failover_slots
    synchronous:
      method: any
      number: 1
      dataDurability: preferred
      failoverQuorum: true
    syncReplicaElectionConstraint:
      enabled: false
  primaryUpdateMethod: switchover
  primaryUpdateStrategy: unsupervised
  probes:
    liveness:
      isolationCheck:
        connectionTimeout: 1000
        enabled: true
        requestTimeout: 1000
    startup:
      maximumLag: 64Mi
      type: streaming

Relevant log output

postgres {"level":"info","ts":"2026-04-24T07:10:04.753762899Z","logger":"postgres","msg":"record","logging_pod":"cluster-example-1","record":{"log_time":"2026-04-24 07:10:04.753 UTC","user_name":"postgres","database_name":"postgres","process_id":"84","connection_from":"[local]","session_id":"69eb174c.54","session_line_num":"1","command_tag":"PARSE","session_start_time":"2026-04-24 07:10:04 UTC","virtual_transaction_id":"21/2","transaction_id":"0","error_severity":"ERROR","sql_state_code":"42704","message":"unrecognized configuration parameter \"cnpg.synchronous_standby_names_metadata\"","query":"SHOW cnpg.synchronous_standby_names_metadata","application_name":"cnpg-instance-manager","backend_type":"client backend","query_id":"0"}}
postgres {"level":"error","ts":"2026-04-24T07:10:04.753789025Z","msg":"Reconciler error","logger":"instance-manager","logging_pod":"cluster-example-1","controller":"instance-cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"cluster-example","namespace":"default"},"namespace":"default","name":"cluster-example","reconcileID":"b22574d4-5601-4ddc-970a-c1b93ee02ddf","error":"ERROR: unrecognized configuration parameter \"cnpg.synchronous_standby_names_metadata\" (SQLSTATE 42704)","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...[]).reconcileHandler\n\t/Users/augusto.ribeiro/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:495\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...[]).processNextWorkItem\n\t/Users/augusto.ribeiro/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:438\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func1.1\n\t/Users/augusto.ribeiro/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:313"}

Code of Conduct

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

Activity

  1. dosubot commented on Apr 24, 2026

    @dosubot

    Hi @augustoribeiro! I'm Dosu and I’m helping the cloudnative-pg team.

    @augustoribeiro, this looks like a timing/race condition bug. The cnpg.synchronous_standby_names_metadata custom parameter is written to PostgreSQL's custom.conf only when there are actual synchronous standby names to configure [1]. However, when failoverQuorum: true is set, the instance manager on the primary tries to read this parameter via SHOW cnpg.synchronous_standby_names_metadata regardless of whether it has been written yet [2] [3].

    In your 2-instance cluster with dataDurability: preferred, here's the likely sequence:

    1. The primary starts up
    2. No replicas are streaming yet, so synchronous_standby_names is empty (as designed by dataDurability: preferred — it disables sync replication when no replicas are available) [4]
    3. Since synchronous_standby_names is empty, cnpg.synchronous_standby_names_metadata is never written to custom.conf
    4. The failover quorum reconciler runs and tries to SHOW cnpg.synchronous_standby_names_metadata → PostgreSQL returns the "unrecognized configuration parameter" error
    5. This error prevents the instance from becoming ready, which in turn prevents the replica from connecting, creating a deadlock

    This appears to be a genuine bug — the failover quorum code path doesn't handle the case where the metadata parameter hasn't been written yet because there are no synchronous standbys.

    As a workaround, you could try temporarily removing failoverQuorum: true to let the cluster bootstrap, and then re-enable it once all instances are streaming. Alternatively, removing the streaming startup probe should also break the deadlock cycle.

    There are several related issues worth referencing: #8371 covers a similar parameter recognition problem during upgrades [5], and #8790 tracks a race condition where synchronous_standby_names is applied before replicas are ready [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. added
    bug 🐛
    and removed on Jun 21, 2026
  3. drybalka-s commented on Aug 12, 2026

    @drybalka-s

    We hit this on CloudNativePG 1.29.1 and can add a bit of detail on the mechanism,
    because the visible symptom ("instance is never ready") is a consequence of something
    that also blocks HA replication slot management.

    What we observed

    Fresh cluster bootstrap, 3 instances, replicationSlots.highAvailability.enabled: true,
    synchronous: {method: any, number: 1, dataDurability: preferred, failoverQuorum: true},
    probes.startup.type: streaming.

    Primary comes up, the replica clones successfully, and then loops forever:

    FATAL could not start WAL streaming: ERROR: replication slot "_cnpg_platform_2" does not exist
    LOG waiting for WAL to become available at 0/4000018
    info startup probe failing err="replica not connected via streaming replication"

    On the primary, SELECT count(*) FROM pg_replication_slots returns 0 — the operator
    never created the HA slot. The instance manager errors out on every reconcile loop:

    {"level":"error","logger":"instance-manager","controller":"instance-cluster",
    "error":"ERROR: unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata" (SQLSTATE 42704)"}

    Why it is a deadlock, not just a noisy error

    1. pkg/postgres/configuration.go writes cnpg.synchronous_standby_names_metadata only
      when synchronous_standby_names is non-empty.
    2. With dataDurability: preferred, synchronous_standby_names is derived from healthy
      replicas only. On a fresh cluster there are none, so neither GUC is written — we
      confirmed custom.conf contains only cnpg.config_sha256.
    3. updateFailoverQuorumObject runs at internal/management/controller/instance_controller.go:275
      and calls GetSynchronousReplicationMetadata, which does
      SHOW cnpg.synchronous_standby_names_metadata and returns the 42704 error verbatim
      (pkg/management/postgres/instance.go:1156; the len(metadata) == 0 → nil, nil branch
      only covers "parameter exists but empty").
    4. The reconcile loop returns at line 275, so ReconcileReplicationSlots at line 289 is
      never reached — no _cnpg_* slots are ever created.
    5. The replica is started with primary_slot_name, the slot does not exist, so it can
      never stream, so synchronous_standby_names stays empty, so the GUC is never written.

    The cluster cannot recover on its own.

    Manual workaround, and what it proves

    Running on the primary:

    SELECT pg_create_physical_replication_slot('_cnpg_platform_2');
    
    unblocks everything. Within ~25s the replica streams, the operator then writes
    
    synchronous_standby_names = 'ANY 1 ("platform-2")'
    cnpg.synchronous_standby_names_metadata = '{"method":"ANY","number":1,"standbyNames":[
    
    the 42704 errors stop, and from that point the operator creates the slot for the third
    instance (_cnpg_platform_3) automatically, before the pod starts. Cluster reaches
    Cluster in healthy state 3/3. So a single manual slot is enough to unblock the whole
    reconciler — which matches the analysis above: PostgreSQL is fine, the reconcile loop is
    the only thing that is stuck.
    
    Control experiments (same chart, same values, one field changed)
    
    ┌────────────────┬────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    │ failoverQuorum │ dataDurability │                                                            Result                                                             │
    ├────────────────┼────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │ true           │ preferred      │ HA slot never created, replica never streams, bootstrap hangs                                                                 │
    ├────────────────┼────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │ false          │ preferred      │ slot created by the operator before the replica pomin, no 42704                                     │
    ├────────────────┼────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │ true           │ required       │ slot created automatically, healthy; GUC present from the start: {"method":"ANY","number":1,"standbyNames":["req-2","req-1"]} │
    └────────────────┴────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────┘
    
    So either of the two triggers alone is harmless; the combination is what deadlocks.
    
    Affected versions
    
    Reproduced on 1.29.1. Checking the sources on 2026-08-12, the three code paths involved
    are identical in release-1.28, release-1.29, release-1.30 and main:
    
    - the if len(syncStandbyNames) > 0 guard in pkg/postgres/configuration.go,
    - GetSynchronousReplicationMetadata returning the error instead of nil for an
    unrecognized parameter in pkg/management/postgres/instance.go,
    - updateFailoverQuorumObject being called before ReconcileReplicationSlots in
    internal/management/controller/instance_controller.go (lines 276/290 on 1.28,
    275/289 on 1.29, 299/313 on 1.30 and main).
    
    That is, all three currently supported minors (latest patches 1.28.4, 1.29.2, 1.30.0) are
    affected, unless something outside these paths changes the behaviour. PR #10549 has be
    open since 2026-04-24 — is there anything blocking it that we could help with?
    
    Impact
    
    Beyond "the instance is never ready": any situation where the primary has zero streaming
    standbys and a HA slot has to be created is affected. In our fleet that means:
    
    - initial cluster bootstrap;
    - restore from a backup (same "primary up, no replicas yet" phase);
    - adding an instance to a cluster that is left without replicas;
    - **declarative PostgreSQL major upgrades (16 → 17, 17 → 18)**. During the upgrade the
      operator removes the replicas and re-clones them from the already-upgraded primary, so
      the cluster necessarily goes through a single-instance, zero-streaming-standby phase —
      exactly the state in which `cnpg.synchronous_standby_names_metadata` is absent and slot
      reconciliation never runs. The replicas then cannot re-join after the upgrade until a
      slot is created manually on the primary. This is the most painful case for us: it turns
      a routine maintenance operation into an unattended-upgrade trap, and it happens while
      the cluster is running with no redundancy at all.
    
    Operator intervention with `pg_create_physical_replication_slot` is required to get out
    of any of these.
  4. mzwettler2 commented on Aug 20, 2026

    @mzwettler2

    I ran into the same bug. However, I only changed probes.readiness

        synchronous:
          method: any
          number: 1
          dataDurability: preferred
          failoverQuorum: true
    ...
      probes:
        readiness:
          type: streaming
          maximumLag: 1Mi
          failureThreshold: 6
          periodSeconds: 10
    

    Same issue. The deployment gets stuck with an error message when the two instances are joined:

    2026-08-20T16:14:25.531 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:14:25.725 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:14:43.901 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:14:44.237 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:14:44.311 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:15:38.607 ERROR    smpg-pg-eng002-2 postgres         could not start WAL streaming: ERROR:  replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:15:43.597 ERROR    smpg-pg-eng002-2 postgres         could not start WAL streaming: ERROR:  replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:14:56.926 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:14:58.185 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:14:58.644 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:14:59.191 ERROR    smpg-pg-eng002-1 postgres         unrecognized configuration parameter "cnpg.synchronous_standby_names_metadata"
    2026-08-20T16:15:03.592 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:15:08.604 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:15:13.666 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    2026-08-20T16:15:18.589 ERROR    smpg-pg-eng002-1 postgres         replication slot "_cnpg_smpg_pg_eng002_2" does not exist
    

    Running SELECT pg_create_physical_replication_slot('_cnpg_smpg_pg_eng002_2'); manually unblocks everything.

    This is for CNPG 1.30.0

    Cluster.yaml

  5. github-actions commented on Oct 21, 2026

    @github-actions
    Contributor

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

  6. github-actions commented on Nov 5, 2026

    @github-actions
    Contributor

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

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

Metadata

Metadata

Assignees

Labels

Stalebug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions