Skip to content

[Bug]: Database becomes inaccessible after 2nd failed scheduled backup #3934

Closed as not planned

Description

@localbubble

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

What version of Kubernetes are you using?

1.27

What is your Kubernetes environment?

Cloud: Azure AKS

How did you install the operator?

Helm

What happened?

I was trying cloudnative-pg (helm chart version 0.20.1 with default values.yaml) and I've deployed a single postgresql instance on AKS. And I have managed to render the DB inaccessible because of a failed scheduled backup, therefore I wanted to report it here.

On Friday, I was trying the backups, and so I've set up the volumeSnapshot backup with misconfiguration (incorrect storage class driver), and I've tried to take a manual backup, and obviously it failed because the misconfiguration and I wrapped the day to continue on Monday, but I've left scheduled backups enabled, knowing that they would fail.

On Monday when I checked the database, I see that the DB pod is not ready state, therefore inaccessible.
I start troubleshootingand there is nothing wrong in the DB logs. And in the operator logs, I see that after the 2nd failed scheduled backup attempt, the readiness probe of the database have stopped responding, therefore rendering the DB inaccessible.

Interestingly, the pod was never restarted even though the liveness probe seems to be enabled by default. Suggesting that the failed scheduled backup only affected the /readyz endpoint and not the /healthz endpoint.

Note: I didn't encounter the issue when I tried to take a manual backup, and the issue also didn't happen after the 1st failed scheduled backup attempt, but it happened after the 2nd failed "scheduled" volumeSnapshot backup attempt as it thought the backup is already running, as you can also see from the logs.

Finally, the database pod was kept in "unready" state until I've manually intervened and deleted the pod with force flag.

I would have expected that the failing backup attempts should not affect the readiness of the database. So in my opinion the readiness probe shouldn't have affected to begin with, or if needs to be affected, liveness probe should also be affected, so the DB pod will be restarted automatically over the liveness probe, but maybe I am missing something here.

Cluster resource

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: demo-postgresql-db
  namespace: demo
spec:
  imageName: ghcr.io/cloudnative-pg/postgis:13-3.3-16
  imagePullPolicy: IfNotPresent 
  instances: 1
  affinity:
    tolerations:
    - key: "dedicated"
      operator: "Equal"
      value: "demo"
      effect: "NoSchedule"

  storage:
    storageClass: managed-csi
    size: 250Gi
  walStorage:
    storageClass: managed-csi
    size: 50Gi

  backup:
    barmanObjectStore:
      destinationPath: "https://redacted.blob.core.windows.net/redacted/backup"
      azureCredentials:
        connectionString:
          name: redacted-creds
          key: redacted_STORAGE_CONNECTION_STRING
    volumeSnapshot:
      className: managed-csi #(misconfiguration is this!!)
      walClassName: managed-csi #(misconfiguration is this!!)
      online: true
      onlineConfiguration:
        waitForArchive: true
        immediateCheckpoint: false

  enableSuperuserAccess: true
  superuserSecret:
    name: redacted-secret

  managed:
    roles:
    - name: redacted
      ensure: present
      comment: DB owner
      login: true
      passwordSecret:
        name: redacted-secret
      superuser: true
      createdb: true
      createrole: true
      replication: true
    - name: redacted
      ensure: present
      comment: Read only role
      login: false
      superuser: false
    - name: redacted
      ensure: present
      comment: User for redacted
      login: true
      passwordSecret:
        name: redacted-secret
      superuser: false
      inRoles:
        - redacted
  bootstrap:
    initdb:
      database: redacted
      owner: redacted
      secret:
        name: redacted-secret
      encoding: UTF8 # this is the default, just leaving it here for transparency
      localeCollate: 'en_US.utf8'
      localeCType: 'en_US.utf8'
      postInitApplicationSQL:
        - CREATE EXTENSION IF NOT EXISTS postgis VERSION '3.3.1';
        - CREATE EXTENSION IF NOT EXISTS dblink VERSION '1.2';
        - CREATE EXTENSION IF NOT EXISTS hstore VERSION '1.7';
        - CREATE EXTENSION IF NOT EXISTS ltree VERSION '1.2';
        - CREATE EXTENSION IF NOT EXISTS pg_stat_statements VERSION '1.8';
        - CREATE EXTENSION IF NOT EXISTS pgstattuple VERSION '1.5';
        - CREATE EXTENSION IF NOT EXISTS "uuid-ossp" VERSION '1.1';

  postgresql:
    parameters:
      autovacuum_max_workers: "10" # max number of autovacuum subprocesses
      autovacuum_naptime: "10" # time between autovacuum runs
      checkpoint_completion_target: "0.9" # checkpoint target duration, 0.0 - 1.0
      default_statistics_target: "500" # range 1-10000
      effective_cache_size: "48000MB"
      effective_io_concurrency: "256" # 1-1000; 0 disables prefetching
      maintenance_work_mem: "2047MB"
      max_locks_per_transaction: "512"
      max_parallel_workers: "12" # maximum number of max_worker_processes
      max_parallel_workers_per_gather: "6"
      max_replication_slots: "10"
      max_worker_processes: "23"
      min_wal_size: "512MB"
      pg_stat_statements.track: "all"
      random_page_cost: "1.1"
      shared_buffers: "16000MB"
      work_mem: "27459kB"
---
apiVersion: postgresql.cnpg.io/v1
kind: Backup
metadata:
  name: demo-postgres-backup
  namespace: demo
spec:
  cluster:
    name: demo-postgresql-db
---
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
  name: demo-postgres-scheduled-snapshot-backup
  namespace: demo
spec:
  method: volumeSnapshot 
  schedule: "0 0 0 * * *"
  backupOwnerReference: self
  cluster:
    name: demo-postgresql-db

Relevant log output

full db logs .txt

{"level":"info","ts":"2024-02-25T00:00:30Z","msg":"Backup is already running on","controller":"backup","controllerGroup":"postgresql.cnpg.io","controllerKind":"Backup","Backup":{"name":"demo-postgres-scheduled-backup-20240225000000","namespace":"demo"},"namespace":"demo","name":"demo-postgres-scheduled-backup-20240225000000","reconcileID":"7610326b-daa7-4823-bd94-4b32558bd982","uuid":"e383712c-d370-11ee-8804-ea2969c0a2ef","cluster":"demo-postgresql-db","pod":"demo-postgresql-db-1","started at":"2024-02-25 00:00:00 +0000 UTC"}
{"level":"info","ts":"2024-02-25T00:00:30Z","msg":"found a previously elected pod, reusing it","controller":"backup","controllerGroup":"postgresql.cnpg.io","controllerKind":"Backup","Backup":{"name":"demo-postgres-scheduled-backup-20240225000000","namespace":"demo"},"namespace":"demo","name":"demo-postgres-scheduled-backup-20240225000000","reconcileID":"7610326b-daa7-4823-bd94-4b32558bd982","uuid":"e383712c-d370-11ee-8804-ea2969c0a2ef","targetPodName":"demo-postgresql-db-1"}
{"level":"info","ts":"2024-02-25T00:00:30Z","msg":"Cannot extract Pod status","controller":"cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"demo-postgresql-db","namespace":"demo"},"namespace":"demo","name":"demo-postgresql-db","reconcileID":"19018392-a883-4700-9d8a-fdadbe386b1e","uuid":"d19ed59f-d370-11ee-8804-ea2969c0a2ef","name":"demo-postgresql-db-1","error":"Get \"http://10.244.1.5:8000/pg/status\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)"}
{"level":"info","ts":"2024-02-25T00:00:30Z","msg":"Failed to extract instance status from ready instances. Attempting to requeue...","controller":"cluster","controllerGroup":"postgresql.cnpg.io","controllerKind":"Cluster","Cluster":{"name":"demo-postgresql-db","namespace":"demo"},"namespace":"demo","name":"demo-postgresql-db","reconcileID":"19018392-a883-4700-9d8a-fdadbe386b1e","uuid":"d19ed59f-d370-11ee-8804-ea2969c0a2ef"}
{"level":"info","ts":"2024-02-25T00:00:35Z","msg":"Backup is already running on","controller":"backup","controllerGroup":"postgresql.cnpg.io","controllerKind":"Backup","Backup":{"name":"demo-postgres-scheduled-backup-20240225000000","namespace":"demo"},"namespace":"demo","name":"demo-postgres-scheduled-backup-20240225000000","reconcileID":"8dc13bdb-fd88-4777-aeb9-b8584ff7ab45","uuid":"e67ed42a-d370-11ee-8804-ea2969c0a2ef","cluster":"demo-postgresql-db","pod":"demo-postgresql-db-1","started at":"2024-02-25 00:00:00 +0000 UTC"}
{"level":"info","ts":"2024-02-25T00:00:35Z","msg":"found a previously elected pod, reusing it","controller":"backup","controllerGroup":"postgresql.cnpg.io","controllerKind":"Backup","Backup":{"name":"demo-postgres-scheduled-backup-20240225000000","namespace":"demo"},"namespace":"demo","name":"demo-postgres-scheduled-backup-20240225000000","reconcileID":"8dc13bdb-fd88-4777-aeb9-b8584ff7ab45","uuid":"e67ed42a-d370-11ee-8804-ea2969c0a2ef","targetPodName":"demo-postgresql-db-1"}

Code of Conduct

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

Activity

  1. 99hops commented on Mar 29, 2024

    @99hops

    @localbubble I can confirm this, as I am setting up new cluster I gets inactive on all 3 instances because of failing backups (misconfigured storage). This should not be the case, the cluster should continue to operate as normal as if there is no backup configured. Now I get Readiness probe failed: Get "http://10.233.65.248:8000/readyz": context deadline exceeded (Client.Timeout exceeded while awaiting headers) on all instances which effectively renders the cluster useless and system down..

    Please anyone responsible for this advice on why is this behavious and how to prevent it from happening 🙏

  2. rorynickolls-skyral commented on Oct 15, 2024

    @rorynickolls-skyral

    This issue is the same as #5505

  3. jmealo commented on Jan 14, 2025

    @jmealo
    Contributor

    @99hops: Are you also on Azure AKS by any chance? I'm see a lot of this and trying to narrow down the causes with @sxd.

  4. github-actions commented on Mar 28, 2025

    @github-actions
    Contributor

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

  5. jmealo commented on Mar 28, 2025

    @jmealo
    Contributor

    This issue was duplicated by/addressed in: #6761

  6. github-actions commented on May 30, 2025

    @github-actions
    Contributor

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

  7. jmealo commented on May 30, 2025

    @jmealo
    Contributor

    This issue has been fixed. Can we close the issue?

  8. github-actions commented on Aug 1, 2025

    @github-actions
    Contributor

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

  9. github-actions commented on Aug 22, 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

Staletriage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions