Repository navigation
Closed
Labels
triagePending triage
Description
⚠️ The root cause of this issue was: #6761
This bug is present in all versions up to 1.25 (hopefully fix makes it out in 1.25.1 🤞 )
- Check your pg_stat_activity on your backup target(s) to see if you have stuck backup connections.
- If you do not, open a new issue.
- If you do upgrade CNPG to 1.25.1 or higher
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
Version
1.25 (latest patch)
What version of Kubernetes are you using?
1.29
What is your Kubernetes environment?
Cloud: Azure AKS
How did you install the operator?
YAML manifest
What happened?
Impact:
Replica node entered crash-loop backoff due to WAL volume space exhaustion. WAL files from December persisted on one replica after promotion to primary, while other nodes remained healthy.
Steps to reproduce:
- Configure 3-node PostgreSQL cluster (1 primary, 2 replicas)
- Perform primary/replica role changes
- Monitor WAL retention on all nodes
- Observe inconsistent WAL cleanup behavior, particularly on nodes that change roles
Expected behavior:
- WAL cleanup should occur consistently across all instances
- Role changes should not affect WAL cleanup mechanisms
- No out-of-disk space scenarios due to retained WAL after failovers
Actual behavior:
- Inconsistent WAL cleanup after role changes
- WAL files persisted from December on one node
- WAL volume space exhaustion on replica
- Files eventually self-cleaned during investigation
Additional details:
- Cluster and operator reports with logs available upon request.
- This cluster has at least two separate write transactions every 60 seconds.
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"postgresql.cnpg.io/v1","kind":"Cluster","metadata":{"annotations":{},"name":"staging-pg-common","namespace":"db"},"spec":{"affinity":{"nodeSelector":{"kubernetes.azure.com/agentpool":"pgcommon","kubernetes.io/arch":"arm64"},"tolerations":[{"effect":"NoSchedule","key":"node-role.kubernetes.io/postgres","operator":"Exists"}]},"backup":{"barmanObjectStore":{"azureCredentials":{"connectionString":{"key":"AZURE_STORAGE_CONNECTION_STRING","name":"postgres-backup-azure-creds"}},"data":{"compression":"snappy","jobs":2},"destinationPath":"https://redactedstaging.blob.core.windows.net/postgres-backup","wal":{"maxParallel":2}},"retentionPolicy":"30d","target":"prefer-standby","volumeSnapshot":{"className":"csi-azure-disk","online":true,"onlineConfiguration":{"immediateCheckpoint":false,"waitForArchive":true},"snapshotOwnerReference":"cluster"}},"bootstrap":{"initdb":{"database":"redacted","owner":"redacted","secret":{"name":"postgres-redacted-db-credentials"}}},"enablePDB":true,"enableSuperuserAccess":true,"env":[{"name":"ENABLE_AZURE_PVC_UPDATES","value":"true"}],"failoverDelay":30,"imageCatalogRef":{"apiGroup":"postgresql.cnpg.io","kind":"ImageCatalog","major":17,"name":"custom-postgres-images"},"imagePullSecrets":[{"name":"docker-registry-credentials"}],"instances":3,"monitoring":{"enablePodMonitor":true},"postgresql":{"parameters":{"auto_explain.log_analyze":"true","auto_explain.log_buffers":"true","auto_explain.log_min_duration":"0","auto_explain.log_timing":"true","auto_explain.log_triggers":"true","auto_explain.log_verbose":"true","autovacuum_max_workers":"2","autovacuum_naptime":"20s","autovacuum_vacuum_cost_limit":"1000","autovacuum_vacuum_scale_factor":"0.1","checkpoint_completion_target":"0.9","checkpoint_timeout":"15min","cron.database_name":"redacted","cron.use_background_workers":"on","default_statistics_target":"100","effective_cache_size":"4191MB","effective_io_concurrency":"1000","idle_in_transaction_session_timeout":"30min","jit":"off","lock_timeout":"1800s","maintenance_work_mem":"341MB","max_connections":"100","max_parallel_maintenance_workers":"2","max_parallel_workers":"4","max_parallel_workers_per_gather":"2","max_wal_size":"4GB","max_worker_processes":"4","min_wal_size":"1GB","pg_stat_statements.max":"10000","pg_stat_statements.save":"on","pg_stat_statements.track":"all","pg_stat_statements.track_planning":"off","pg_stat_statements.track_utility":"on","random_page_cost":"1.1","shared_buffers":"1397MB","statement_timeout":"7200s","wal_buffers":"16MB","wal_compression":"lz4","work_mem":"4988kB"},"shared_preload_libraries":["pg_stat_statements","auto_explain","pg_cron"]},"primaryUpdateStrategy":"unsupervised","resources":{"limits":{"cpu":"2628m","memory":"5458Mi"},"requests":{"cpu":"2628m","memory":"5458Mi"}},"storage":{"size":"128Gi","storageClass":"6400-iops-212mb-tp-premium-v2"},"superuserSecret":{"name":"postgres-superuser-secret"},"switchoverDelay":30,"walStorage":{"size":"32Gi","storageClass":"6400-iops-212mb-tp-premium-v2"}}}
creationTimestamp: "2024-12-10T19:09:51Z"
generation: 16
name: staging-pg-common
namespace: db
resourceVersion: "468310505"
uid: 4f3797ad-a333-40f8-9ae1-0f21fb1b742c
spec:
affinity:
nodeSelector:
kubernetes.azure.com/agentpool: pgcommon
kubernetes.io/arch: arm64
podAntiAffinityType: preferred
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/postgres
operator: Exists
backup:
barmanObjectStore:
azureCredentials:
connectionString:
key: AZURE_STORAGE_CONNECTION_STRING
name: postgres-backup-azure-creds
data:
compression: snappy
jobs: 2
destinationPath: https://redactedstaging.blob.core.windows.net/postgres-backup
wal:
maxParallel: 2
retentionPolicy: 30d
target: prefer-standby
volumeSnapshot:
className: csi-azure-disk
online: true
onlineConfiguration:
immediateCheckpoint: false
waitForArchive: true
snapshotOwnerReference: cluster
bootstrap:
initdb:
database: redacted
encoding: UTF8
localeCType: C
localeCollate: C
owner: redacted
secret:
name: postgres-redacted-db-credentials
enablePDB: true
enableSuperuserAccess: true
env:
- name: ENABLE_AZURE_PVC_UPDATES
value: "true"
failoverDelay: 30
imageCatalogRef:
apiGroup: postgresql.cnpg.io
kind: ImageCatalog
major: 17
name: custom-postgres-images
imagePullSecrets:
- name: docker-registry-credentials
instances: 3
logLevel: info
maxSyncReplicas: 0
minSyncReplicas: 0
monitoring:
customQueriesConfigMap:
- key: queries
name: cnpg-default-monitoring
disableDefaultQueries: false
enablePodMonitor: true
postgresGID: 26
postgresUID: 26
postgresql:
parameters:
archive_mode: "on"
archive_timeout: 5min
auto_explain.log_analyze: "true"
auto_explain.log_buffers: "true"
auto_explain.log_min_duration: "0"
auto_explain.log_timing: "true"
auto_explain.log_triggers: "true"
auto_explain.log_verbose: "true"
autovacuum_max_workers: "2"
autovacuum_naptime: 20s
autovacuum_vacuum_cost_limit: "1000"
autovacuum_vacuum_scale_factor: "0.1"
checkpoint_completion_target: "0.9"
checkpoint_timeout: 15min
cron.database_name: redacted
cron.use_background_workers: "on"
default_statistics_target: "100"
dynamic_shared_memory_type: posix
effective_cache_size: 4191MB
effective_io_concurrency: "1000"
full_page_writes: "on"
idle_in_transaction_session_timeout: 30min
jit: "off"
lock_timeout: 1800s
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: 341MB
max_connections: "100"
max_parallel_maintenance_workers: "2"
max_parallel_workers: "4"
max_parallel_workers_per_gather: "2"
max_replication_slots: "32"
max_wal_size: 4GB
max_worker_processes: "4"
min_wal_size: 1GB
pg_stat_statements.max: "10000"
pg_stat_statements.save: "on"
pg_stat_statements.track: all
pg_stat_statements.track_planning: "off"
pg_stat_statements.track_utility: "on"
random_page_cost: "1.1"
shared_buffers: 1397MB
shared_memory_type: mmap
shared_preload_libraries: ""
ssl_max_protocol_version: TLSv1.3
ssl_min_protocol_version: TLSv1.3
statement_timeout: 7200s
wal_buffers: 16MB
wal_compression: lz4
wal_keep_size: 512MB
wal_level: logical
wal_log_hints: "on"
wal_receiver_timeout: 5s
wal_sender_timeout: 5s
work_mem: 4988kB
shared_preload_libraries:
- pg_stat_statements
- auto_explain
- pg_cron
syncReplicaElectionConstraint:
enabled: false
primaryUpdateMethod: restart
primaryUpdateStrategy: unsupervised
replicationSlots:
highAvailability:
enabled: true
slotPrefix: _cnpg_
synchronizeReplicas:
enabled: true
updateInterval: 30
resources:
limits:
cpu: 2628m
memory: 5458Mi
requests:
cpu: 2628m
memory: 5458Mi
smartShutdownTimeout: 180
startDelay: 3600
stopDelay: 1800
storage:
resizeInUseVolumes: true
size: 128Gi
storageClass: 6400-iops-212mb-tp-premium-v2
superuserSecret:
name: postgres-superuser-secret
switchoverDelay: 30
walStorage:
resizeInUseVolumes: true
size: 32Gi
storageClass: 6400-iops-212mb-tp-premium-v2
status:
availableArchitectures:
- goArch: amd64
hash: 58242fc95faa81d6bba0ba19ea959b82d9b49dc5f8e6c755f3c663665ff0ce1d
- goArch: arm64
hash: 8e5ef490a05bbd5700047edda5e2440acd14bafa256dbfcc7d4a5107573df75b
certificates:
clientCASecret: staging-pg-common-ca
expirations:
staging-pg-common-ca: 2025-03-10 19:04:52 +0000 UTC
staging-pg-common-replication: 2025-03-10 19:04:52 +0000 UTC
staging-pg-common-server: 2025-03-10 19:04:52 +0000 UTC
replicationTLSSecret: staging-pg-common-replication
serverAltDNSNames:
- staging-pg-common-rw
- staging-pg-common-rw.db
- staging-pg-common-rw.db.svc
- staging-pg-common-rw.db.svc.cluster.local
- staging-pg-common-r
- staging-pg-common-r.db
- staging-pg-common-r.db.svc
- staging-pg-common-r.db.svc.cluster.local
- staging-pg-common-ro
- staging-pg-common-ro.db
- staging-pg-common-ro.db.svc
- staging-pg-common-ro.db.svc.cluster.local
serverCASecret: staging-pg-common-ca
serverTLSSecret: staging-pg-common-server
cloudNativePGCommitHash: bad5a251
cloudNativePGOperatorHash: 58242fc95faa81d6bba0ba19ea959b82d9b49dc5f8e6c755f3c663665ff0ce1d
conditions:
- lastTransitionTime: "2025-01-08T16:19:02Z"
message: Cluster is Ready
reason: ClusterIsReady
status: "True"
type: Ready
- lastTransitionTime: "2024-12-23T15:21:09Z"
message: Continuous archiving is working
reason: ContinuousArchivingSuccess
status: "True"
type: ContinuousArchiving
- lastTransitionTime: "2025-01-08T17:00:00Z"
message: New Backup starting up
reason: BackupStarted
status: "False"
type: LastBackupSucceeded
configMapResourceVersion:
metrics:
cnpg-default-monitoring: "445853326"
currentPrimary: staging-pg-common-3
currentPrimaryTimestamp: "2024-12-23T15:21:05.448655Z"
firstRecoverabilityPoint: "2024-12-10T20:08:33Z"
firstRecoverabilityPointByMethod:
barmanObjectStore: "2024-12-11T00:00:02Z"
volumeSnapshot: "2024-12-10T20:08:33Z"
healthyPVC:
- staging-pg-common-1
- staging-pg-common-1-wal
- staging-pg-common-3
- staging-pg-common-3-wal
- staging-pg-common-4
- staging-pg-common-4-wal
image: docker.redacted.net/custom-postgres17:17.2@sha256:9d93740c5fcfa7b3113815d6118f8a0afe35dcef38775dae2b93f6d7badedc91
instanceNames:
- staging-pg-common-1
- staging-pg-common-3
- staging-pg-common-4
instances: 3
instancesReportedState:
staging-pg-common-1:
isPrimary: false
timeLineID: 4
staging-pg-common-3:
isPrimary: true
timeLineID: 4
staging-pg-common-4:
isPrimary: false
timeLineID: 4
instancesStatus:
healthy:
- staging-pg-common-1
- staging-pg-common-3
- staging-pg-common-4
lastSuccessfulBackup: "2025-01-08T16:05:41Z"
lastSuccessfulBackupByMethod:
barmanObjectStore: "2025-01-08T00:00:17Z"
volumeSnapshot: "2025-01-08T16:05:41Z"
latestGeneratedNode: 4
managedRolesStatus: {}
phase: Cluster in healthy state
poolerIntegrations:
pgBouncerIntegration:
secrets:
- staging-pg-common-pooler
pvcCount: 6
readService: staging-pg-common-r
readyInstances: 3
secretsResourceVersion:
clientCaSecretVersion: "445853293"
replicationSecretVersion: "445853295"
serverCaSecretVersion: "445853293"
serverSecretVersion: "445853294"
superuserSecretVersion: "445853282"
switchReplicaClusterStatus: {}
targetPrimary: staging-pg-common-3
targetPrimaryTimestamp: "2024-12-23T15:20:52.825593Z"
timelineID: 4
topology:
instances:
staging-pg-common-1: {}
staging-pg-common-3: {}
staging-pg-common-4: {}
nodesUsed: 3
successfullyExtracted: true
writeService: staging-pg-common-rwRelevant log output
{"level":"info","ts":"2025-01-07T23:59:16.506414715Z","msg":"Starting CloudNativePG Instance Manager","logger":"instance-manager","logging_pod":"staging-pg-common-1","version":"1.25.0","build":{"Version":"1.25.0","Commit":"bad5a251","Date":"2024-12-23"}}
{"level":"info","ts":"2025-01-07T23:59:16.506595945Z","msg":"Checking for free disk space for WALs before starting PostgreSQL","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.507873931Z","msg":"Detected low-disk space condition, avoid starting the instance","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.519044943Z","msg":"Starting CloudNativePG Instance Manager","logger":"instance-manager","logging_pod":"staging-pg-common-1","version":"1.25.0","build":{"Version":"1.25.0","Commit":"bad5a251","Date":"2024-12-23"}}
{"level":"info","ts":"2025-01-07T23:59:16.519064272Z","msg":"Checking for free disk space for WALs before starting PostgreSQL","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.519933252Z","msg":"Detected low-disk space condition, avoid starting the instance","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.531096897Z","msg":"Starting CloudNativePG Instance Manager","logger":"instance-manager","logging_pod":"staging-pg-common-1","version":"1.25.0","build":{"Version":"1.25.0","Commit":"bad5a251","Date":"2024-12-23"}}
{"level":"info","ts":"2025-01-07T23:59:16.531116985Z","msg":"Checking for free disk space for WALs before starting PostgreSQL","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.531974061Z","msg":"Detected low-disk space condition, avoid starting the instance","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.542079719Z","msg":"Starting CloudNativePG Instance Manager","logger":"instance-manager","logging_pod":"staging-pg-common-1","version":"1.25.0","build":{"Version":"1.25.0","Commit":"bad5a251","Date":"2024-12-23"}}
{"level":"info","ts":"2025-01-07T23:59:16.54210308Z","msg":"Checking for free disk space for WALs before starting PostgreSQL","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.543052519Z","msg":"Detected low-disk space condition, avoid starting the instance","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.554194298Z","msg":"Starting CloudNativePG Instance Manager","logger":"instance-manager","logging_pod":"staging-pg-common-1","version":"1.25.0","build":{"Version":"1.25.0","Commit":"bad5a251","Date":"2024-12-23"}}
{"level":"info","ts":"2025-01-07T23:59:16.554224299Z","msg":"Checking for free disk space for WALs before starting PostgreSQL","logger":"instance-manager","logging_pod":"staging-pg-common-1"}
{"level":"info","ts":"2025-01-07T23:59:16.555176234Z","msg":"Detected low-disk space condition, avoid starting the instance","logger":"instance-manager","logging_pod":"staging-pg-common-1"}Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by Richard Hagen
Metadata
Metadata
Assignees
Labels
triagePending triage
Activity
gpcmol commentedon Jan 10, 2025
I experience similar behaviour:
Kubernetes 1.28.6
Operator: 1.24.1
Postgress: ghcr.io/cloudnative-pg/postgresql:15.10
I have 3 instances. Keycloak is running and hitting the rw service instance.
I deleted the rw pod instance ~ 11:15. The cluster healed itself, but the WALs of the other instances start increaseing the WALs until the PVC's are full.
It took approx 3 hours when it started increasing.
CN metrics:

PVC:

ardentperf commentedon Jan 12, 2025
I don't think this is quite right; role changed impact the algorithms for deciding when WAL can be cleaned up, and there are many workload related reasons it can be inconsistent.
Can we collect specific data on replication lag, backup/RPO lag, and logical replication? I think we'd need to at least establish status of backups and all slots, since those directly impact WAL cleanup
jmealo commentedon Jan 13, 2025
@gpcmol: Can you provide the replication slot status for your primary? Are you on Azure AKS by any chance?
@ardentperf: The two issues that I'm seeing:
Sometimes the entire cluster runs out of wal space, other times it's two instances (the primary and one standby) whereas the other standby is fine.
gpcmol commentedon Jan 14, 2025
@jmealo unforunaltely, I can't hunt down the status again, since we had to restart everything again. But now I know what to do. I'm trying to reproduce the issue again, by deleting the rw instance, put some load and wait. No success still.
We're on our own data center's kubernetes (on VM-ware).
jmealo commentedon Jan 16, 2025
I think this may be explained by #6599.
jmealo commentedon Jan 16, 2025
@ardentperf @gpcmol I'd be interested in your thoughts/feedback on: #6617
thearperson commentedon Jan 16, 2025
We ran into the same issue,
Kubernetes 1.31 (on AKS)
cloudnative-pg: 1.24.1 (helm chart: 0.22.1)
postgres:15.1 (a supabase fork)
jmealo commentedon Feb 17, 2025
@thearperson: Next time this happens, can you check
pg_stat_activityto see if you have stuck backups?If anyone encounters this behavior who does not have stuck backups, please open a new issue.