Skip to content

[Bug]: "Cluster in healthy state" despite replica errors #7895

Closed as not planned

Description

@Denton-L

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.26 (latest patch)

What version of Kubernetes are you using?

1.32

What is your Kubernetes environment?

Cloud: Amazon EKS

How did you install the operator?

Helm

What happened?

Due to some circumstance or another (possibly #3680), it's possible for a replica to not be able to catch up to the primary due to missing WALs. In this case, the Cluster still reports "Cluster in healthy state" despite one of the replicas being unhealthy.

In particular, we were bringing up a new replica but since our WAL archive was missing a log, it was unable to catch up.

In the case where a replica encounters an error is unable to catch up, the state of the Cluster should reflect that it's no longer healthy.

The circumstances behind the WAL becoming missing: #3680 (comment)

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  annotations:
    meta.helm.sh/release-name: vestadb
    meta.helm.sh/release-namespace: database
  creationTimestamp: "2025-05-10T00:01:16Z"
  finalizers:
  - vesta.com/deletionProtection
  generation: 12
  labels:
    app: vestadb
    app.kubernetes.io/managed-by: Helm
    helm.toolkit.fluxcd.io/name: vestadb
    helm.toolkit.fluxcd.io/namespace: database
  name: vestadb-1
  namespace: database
  resourceVersion: "129638056"
  uid: 51f592ba-c0e1-4bd4-ad31-d53f16c5953d
spec:
  affinity:
    additionalPodAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: app
            operator: In
            values:
            - vestadb
        topologyKey: kubernetes.io/hostname
    nodeSelector:
      karpenter.sh/nodepool: database
      kubernetes.io/arch: amd64
    podAntiAffinityType: required
    tolerations:
    - effect: NoSchedule
      key: vesta.com/specialNode
      operator: Equal
      value: database
  backup:
    barmanObjectStore:
      data:
        compression: gzip
        jobs: 2
      destinationPath: s3://citus-backups-beta
      s3Credentials:
        inheritFromIAMRole: true
      wal:
        compression: gzip
        maxParallel: 1
    retentionPolicy: 30d
    target: primary
    volumeSnapshot:
      className: vestadb-database
      online: true
      onlineConfiguration:
        immediateCheckpoint: false
        waitForArchive: true
      snapshotOwnerReference: backup
  bootstrap:
    recovery:
      database: vesta
      owner: vestadb_beta
      secret:
        name: vestadb-secret
      source: vestadb-1
      volumeSnapshots:
        storage:
          apiGroup: snapshot.storage.k8s.io
          kind: VolumeSnapshot
          name: vestadb-1-volume-20250624163000
        walStorage:
          apiGroup: snapshot.storage.k8s.io
          kind: VolumeSnapshot
          name: vestadb-1-volume-20250624163000-wal
  enablePDB: true
  enableSuperuserAccess: true
  externalClusters:
  - barmanObjectStore:
      destinationPath: s3://citus-backups-beta
      s3Credentials:
        inheritFromIAMRole: true
      wal:
        maxParallel: 12
    name: vestadb-1
  failoverDelay: 0
  imageName: <AWS ACCOUNT>.dkr.ecr.us-east-2.amazonaws.com/citus-beta:17-4b113eee655fb2d515904524fc84736a5a29fd48
  imagePullPolicy: IfNotPresent
  instances: 2
  logLevel: info
  managed:
    roles:
    - connectionLimit: -1
      ensure: present
      inRoles:
      - pg_monitor
      inherit: true
      login: true
      name: datadog
      passwordSecret:
        name: vestadb-datadog-secret
    - connectionLimit: -1
      ensure: present
      inherit: true
      login: true
      name: vestadb_beta_oncall
      passwordSecret:
        name: vestadb-vestadb-oncall-secret
    - connectionLimit: -1
      ensure: present
      inherit: true
      login: true
      name: vestadb_beta_ro
      passwordSecret:
        name: vestadb-vestadb-ro-secret
    services:
      additional:
      - selectorType: rw
        serviceTemplate:
          metadata:
            annotations:
              ad.datadoghq.com/service.checks: |
                {
                  "postgres": {
                    "init_config": {},
                    "instances": [
                      {
                        "reported_hostname": "vestadb-1-beta",
                        "host": "%%host%%",
                        "port": 5432,
                        "username": "ENC[k8s_secret@datadog/vestadb-datadog-secret/username]",
                        "password": "ENC[k8s_secret@datadog/vestadb-datadog-secret/password]",
                        "dbname": "vesta",
                        "dbm": true,
                        "ssl": "prefer",
                        "collect_schemas": {
                          "enabled": true
                        },
                        "relations": [
                          {
                            "relation_regex": ".*"
                          }
                        ]
                      }
                    ]
                  }
                }
            name: vestadb-1-datadog
          spec: {}
        updateStrategy: patch
  maxSyncReplicas: 0
  minSyncReplicas: 0
  monitoring:
    customQueriesConfigMap:
    - key: queries
      name: cnpg-default-monitoring
    disableDefaultQueries: false
    enablePodMonitor: false
  postgresGID: 26
  postgresUID: 26
  postgresql:
    parameters:
      archive_mode: "on"
      archive_timeout: 5min
      auto_explain.log_min_duration: "5000"
      checkpoint_completion_target: "0.9"
      citus.allow_unsafe_constraints: "on"
      citus.enable_change_data_capture: "on"
      citus.executor_slow_start_interval: "1"
      citus.explain_all_tasks: "on"
      citus.local_table_join_policy: prefer-distributed
      citus.max_adaptive_executor_pool_size: "36"
      citus.max_background_task_executors_per_node: "4"
      citus.max_cached_conns_per_worker: "4"
      citus.multi_shard_modify_mode: parallel
      citus.multi_task_query_log_level: warning
      citus.propagate_set_commands: local
      citus.stat_statements_track: all
      default_statistics_target: "100"
      dynamic_shared_memory_type: posix
      effective_cache_size: 48GB
      effective_io_concurrency: "200"
      full_page_writes: "on"
      huge_pages: try
      idle_in_transaction_session_timeout: 1h
      log_destination: csvlog
      log_directory: /controller/log
      log_filename: postgres
      log_rotation_age: "0"
      log_rotation_size: "0"
      log_truncate_on_rotation: "false"
      logging_collector: "on"
      maintenance_work_mem: 2GB
      max_connections: "3000"
      max_locks_per_transaction: "1024"
      max_parallel_maintenance_workers: "4"
      max_parallel_workers: "14"
      max_parallel_workers_per_gather: "4"
      max_replication_slots: "4"
      max_wal_size: 8GB
      max_worker_processes: "14"
      min_wal_size: 2GB
      pg_stat_statements.max: "10000"
      pg_stat_statements.track: all
      pglogical.conflict_resolution: error
      pglogical.use_spi: "on"
      random_page_cost: "1.1"
      shared_buffers: 16GB
      shared_memory_type: mmap
      shared_preload_libraries: ""
      ssl_max_protocol_version: TLSv1.3
      ssl_min_protocol_version: TLSv1.2
      track_activity_query_size: "262144"
      track_commit_timestamp: "on"
      wal_buffers: 16MB
      wal_keep_size: 512MB
      wal_level: logical
      wal_log_hints: "on"
      wal_receiver_timeout: 5s
      wal_sender_timeout: 5s
      work_mem: 64MB
    shared_preload_libraries:
    - citus
    - auto_explain
    - pg_stat_statements
    - pglogical
    syncReplicaElectionConstraint:
      enabled: false
  primaryUpdateMethod: switchover
  primaryUpdateStrategy: supervised
  replicationSlots:
    highAvailability:
      enabled: true
      slotPrefix: _cnpg_
    synchronizeReplicas:
      enabled: true
    updateInterval: 30
  resources:
    limits:
      memory: 113Gi
    requests:
      cpu: 14250m
      memory: 113Gi
  smartShutdownTimeout: 180
  startDelay: 3600
  stopDelay: 1800
  storage:
    resizeInUseVolumes: true
    size: 1100Gi
    storageClass: vestadb-database
  superuserSecret:
    name: vestadb-superuser-secret
  switchoverDelay: 3600
  walStorage:
    resizeInUseVolumes: true
    size: 650Gi
    storageClass: vestadb-database

Relevant log output

Restored WAL file
started streaming WAL from primary at 8DD/6A000000 on timeline 43
could not receive data from WAL stream: ERROR: requested WAL segment 0000002B000008DD0000006A has already been removed
WAL file not found in the recovery object store
Restored WAL file
WAL restore command completed (parallel)
could not receive data from WAL stream: ERROR: requested WAL segment 0000002B000008DD0000006A has already been removed
started streaming WAL from primary at 8DD/6A000000 on timeline 43
WAL file not found in the recovery object store
waiting for WAL to become available at 8DD/6A0002A5

Code of Conduct

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

Activity

  1. added
    triage
    on Jun 26, 2025
  2. dosubot commented on Jun 26, 2025

    @dosubot

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

    This is a known limitation in CloudNativePG: the cluster health status ("Cluster in healthy state") is determined by controller logic that aggregates the status of all instances, but it does not currently mark the cluster as unhealthy if a replica cannot catch up due to missing WALs. This behavior has been discussed in issues like #7465 and #3680, and is a result of design choices that prioritize overall cluster availability. The health check logic mainly ensures the expected number of pods are running and ready, but does not downgrade cluster health for a single degraded replica in this scenario source.

    There are no configuration options to change this behavior as of 1.26. If you need to monitor for this condition, consider setting up external monitoring or alerts on replica lag or WAL restore errors at the pod level. The maintainers have discussed more aggressive health reporting and fencing, but these are not yet implemented due to the trade-offs involved discussion.

    If you need more granular health reporting, you may want to track the status of individual replicas using custom monitoring or by watching the relevant pod logs and conditions.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

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

  3. removed
    triage
    on Jul 11, 2025
  4. github-actions commented on Sep 29, 2025

    @github-actions
    Contributor

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

  5. github-actions commented on Oct 25, 2025

    @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

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions