Repository navigation
Labels
bug 🐛Something isn't working
Description
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
No response
Version
1.27 (latest patch)
What version of Kubernetes are you using?
1.33
What is your Kubernetes environment?
Cloud: Amazon EKS
How did you install the operator?
Helm
What happened?
I upgraded from 1.27.0 to 1.27.1 on a cluster and I'm seeing the output below in a postgres cluster.
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
annotations:
cnpg.io/skipEmptyWalArchiveCheck: enabled
pulumi.com/waitFor: condition=Ready
signoz.io/path: /metrics
signoz.io/port: '9187'
signoz.io/scrape: 'true'
creationTimestamp: '2025-09-26T05:14:02Z'
generation: 4
name: postgres-cluster-demo
namespace: pg-demo
resourceVersion: 'REDACTED'
uid: REDACTED-UID
spec:
affinity:
nodeSelector:
demo.io/node-type: postgres-demo
podAntiAffinityType: preferred
tolerations:
- effect: NoSchedule
key: demo.io/node-type
operator: Equal
value: postgres-demo
bootstrap:
recovery:
database: app
owner: app
source: postgres-cluster-demo
enablePDB: true
enableSuperuserAccess: true
externalClusters:
- name: postgres-cluster-demo
plugin:
enabled: true
isWALArchiver: false
name: barman-cloud.cloudnative-pg.io
parameters:
barmanObjectName: postgres-cluster-demo-object-store
serverName: postgres-cluster-demo
failoverDelay: 0
imageName: ghcr.io/cloudnative-pg/postgresql:18.0-standard-trixie@sha256:6f0f41dffed078d700963eb6e0ca918815d603c97ef1875fe1db01db70d18ed5
instances: 2
logLevel: info
maxSyncReplicas: 0
minSyncReplicas: 0
monitoring:
customQueriesConfigMap:
- key: queries
name: cnpg-default-monitoring
disableDefaultQueries: false
enablePodMonitor: false
plugins:
- enabled: true
isWALArchiver: true
name: barman-cloud.cloudnative-pg.io
parameters:
barmanObjectName: postgres-cluster-demo-object-store
serverName: postgres-cluster-demo
postgresGID: 26
postgresUID: 26
postgresql:
parameters:
archive_mode: 'on'
archive_timeout: 5min
checkpoint_completion_target: '0.9'
default_statistics_target: '100'
dynamic_shared_memory_type: posix
effective_cache_size: 3GB
effective_io_concurrency: '200'
full_page_writes: 'on'
huge_pages: 'off'
log_destination: csvlog
log_directory: /controller/log
log_filename: postgres
log_lock_waits: 'on'
log_min_duration_statement: '30000'
log_rotation_age: '0'
log_rotation_size: '0'
log_truncate_on_rotation: 'false'
logging_collector: 'on'
maintenance_work_mem: 256MB
max_connections: '200'
max_parallel_workers: '32'
max_replication_slots: '32'
max_wal_size: 4GB
max_worker_processes: '32'
min_wal_size: 1GB
pg_stat_statements.max: '10000'
pg_stat_statements.track: all
random_page_cost: '1.1'
shared_buffers: 1GB
shared_memory_type: mmap
shared_preload_libraries: ''
ssl_max_protocol_version: TLSv1.3
ssl_min_protocol_version: TLSv1.3
wal_buffers: 16MB
wal_keep_size: 512MB
wal_level: logical
wal_log_hints: 'on'
wal_receiver_timeout: 5s
wal_sender_timeout: 5s
work_mem: 5041kB
syncReplicaElectionConstraint:
enabled: false
synchronous:
dataDurability: required
method: any
number: 1
primaryUpdateMethod: switchover
primaryUpdateStrategy: unsupervised
probes:
liveness:
isolationCheck:
connectionTimeout: 1000
enabled: true
requestTimeout: 1000
replicationSlots:
highAvailability:
enabled: true
slotPrefix: _cnpg_
synchronizeReplicas:
enabled: true
updateInterval: 30
resources: {}
smartShutdownTimeout: 180
startDelay: 3600
stopDelay: 1800
storage:
pvcTemplate:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi
storageClassName: gp3
volumeMode: Filesystem
resizeInUseVolumes: true
switchoverDelay: 3600
status:
availableArchitectures:
- goArch: amd64
hash: a2ec96b19543b25c66838e0250631fba8b7b474fdd94231cfc0f3361dac257a8
- goArch: arm64
hash: 80017fba324cd54525ecd9a3377c359c5ee3ae590d79b57aa2244fc524f49000
certificates:
clientCASecret: postgres-cluster-demo-ca
expirations:
postgres-cluster-demo-ca: 2025-12-25 05:09:02 +0000 UTC
postgres-cluster-demo-replication: 2025-12-25 05:09:02 +0000 UTC
postgres-cluster-demo-server: 2025-12-25 05:09:02 +0000 UTC
replicationTLSSecret: postgres-cluster-demo-replication
serverAltDNSNames:
- postgres-cluster-demo-rw
- postgres-cluster-demo-rw.pg-demo
- postgres-cluster-demo-rw.pg-demo.svc
- postgres-cluster-demo-rw.pg-demo.svc.cluster.local
- postgres-cluster-demo-r
- postgres-cluster-demo-r.pg-demo
- postgres-cluster-demo-r.pg-demo.svc
- postgres-cluster-demo-r.pg-demo.svc.cluster.local
- postgres-cluster-demo-ro
- postgres-cluster-demo-ro.pg-demo
- postgres-cluster-demo-ro.pg-demo.svc
- postgres-cluster-demo-ro.pg-demo.svc.cluster.local
serverCASecret: postgres-cluster-demo-ca
serverTLSSecret: postgres-cluster-demo-server
cloudNativePGCommitHash: 9daa68132
cloudNativePGOperatorHash: a2ec96b19543b25c66838e0250631fba8b7b474fdd94231cfc0f3361dac257a8
conditions:
- lastTransitionTime: '2025-09-27T11:50:30Z'
message: A single, unique system ID was found across reporting instances.
reason: Unique
status: 'True'
type: ConsistentSystemID
- lastTransitionTime: '2025-11-10T18:38:58Z'
message: Cluster is Ready
reason: ClusterIsReady
status: 'True'
type: Ready
- lastTransitionTime: '2025-11-08T16:48:28Z'
message: Continuous archiving is working
reason: ContinuousArchivingSuccess
status: 'True'
type: ContinuousArchiving
- lastTransitionTime: '2025-11-10T01:00:21Z'
message: Backup was successful
reason: LastBackupSucceeded
status: 'True'
type: LastBackupSucceeded
configMapResourceVersion:
metrics:
cnpg-default-monitoring: '94669024'
currentPrimary: postgres-cluster-demo-3
currentPrimaryTimestamp: '2025-11-08T16:48:24.940335Z'
healthyPVC:
- postgres-cluster-demo-1
- postgres-cluster-demo-3
image: ghcr.io/cloudnative-pg/postgresql:18.0-standard-trixie@sha256:6f0f41dffed078d700963eb6e0ca918815d603c97ef1875fe1db01db70d18ed5
instanceNames:
- postgres-cluster-demo-1
- postgres-cluster-demo-3
instances: 2
instancesReportedState:
postgres-cluster-demo-1:
ip: 10.0.98.37
isPrimary: false
timeLineID: 6
postgres-cluster-demo-3:
ip: 10.0.101.207
isPrimary: true
timeLineID: 6
instancesStatus:
healthy:
- postgres-cluster-demo-1
- postgres-cluster-demo-3
latestGeneratedNode: 3
managedRolesStatus: {}
pgDataImageInfo:
image: ghcr.io/cloudnative-pg/postgresql:18.0-standard-trixie@sha256:6f0f41dffed078d700963eb6e0ca918815d603c97ef1875fe1db01db70d18ed5
majorVersion: 18
phase: Cluster in healthy state
pluginStatus:
- capabilities:
- TYPE_RECONCILER_HOOKS
- TYPE_LIFECYCLE_SERVICE
name: barman-cloud.cloudnative-pg.io
version: 0.9.0
poolerIntegrations:
pgBouncerIntegration: {}
pvcCount: 2
readService: postgres-cluster-demo-r
readyInstances: 2
secretsResourceVersion:
applicationSecretVersion: 'REDACTED'
clientCaSecretVersion: 'REDACTED'
replicationSecretVersion: 'REDACTED'
serverCaSecretVersion: 'REDACTED'
serverSecretVersion: 'REDACTED'
superuserSecretVersion: 'REDACTED'
switchReplicaClusterStatus: {}
systemID: 'REDACTED-SYSTEMID'
targetPrimary: postgres-cluster-demo-3
targetPrimaryTimestamp: '2025-11-08T11:47:49.610065-05:00'
timelineID: 6
topology:
instances:
postgres-cluster-demo-1: {}
postgres-cluster-demo-3: {}
nodesUsed: 2
successfullyExtracted: true
writeService: postgres-cluster-demo-rw
Relevant log output
{"level":"error","ts":"2025-11-08T16:41:01.349452822Z","msg":"while collecting pg_stat_wal","logging_pod":"postgres-cluster-application-3","error":"sql: Scan error on column index 4, name \"stats_reset\": converting NULL to string is unsupported","stacktrace":"github.com/cloudnative-pg/machinery/pkg/log.(*logger).Error\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/log/log.go:125\ngithub.com/cloudnative-pg/machinery/pkg/log.Error\n\tpkg/mod/github.com/cloudnative-pg/[email protected]/pkg/log/log.go:163\ngithub.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres/webserver/metricserver.(*Exporter).collectPgMetrics\n\tpkg/management/postgres/webserver/metricserver/pg_collector.go:454\ngithub.com/cloudnative-pg/cloudnative-pg/pkg/management/postgres/webserver/metricserver.(*Exporter).Collect\n\tpkg/management/postgres/webserver/metricserver/pg_collector.go:321\ngithub.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1\n\tpkg/mod/github.com/prometheus/[email protected]/prometheus/registry.go:456"}Code of Conduct
- I agree to follow this project's Code of Conduct
Reacted by dosubot, André Mohr, Mike, nat, duvduv, Ladislav Čapka, PauliusLe, Kellen Miller, Bohdan, Caetano D'Araujo and 1 more
Metadata
Metadata
Assignees
Labels
bug 🐛Something isn't working
Activity
gbartolini commentedon Nov 10, 2025
Can you please provide the info to reproduce this issue?
aniravi24 commentedon Nov 10, 2025
@gbartolini what would be helpful here? I added the cluster resource definition to the main issue description now. The only thing I did was install the latest helm chart to upgrade from 1.27.0 to 1.27.1 and am now seeing this error on both pod instances.
bmironov commentedon Nov 18, 2025
Hi @gbartolini ,
My guess here is that manifest attempts to "restore" this cluster in
.spec.bootstrap.recoveryfrom external DB cluster and specifies own name as name of that cluster. Perhaps, intention was to restore from own backup.Condition when
pg_stat_wal.stats_resetis NULL might arise wheninitdbwasn't executed for new PostgreSQL cluster as initialization step.aniravi24 commentedon Jan 6, 2026
This is a new cluster that hasn't been restored from a backup (as far as I'm aware). I'm still seeing it on my latest 1.28. It seems to happen when I upgrade a cluster?
redbaron commentedon Jan 22, 2026
We see it in one cluster as well. Interestingly it tries to run that query on a replica, but
pg_stat_waldoesn't seem to be very meaningful on a replica.dosubot commentedon Apr 24, 2026
Hi, @aniravi24. I'm Dosu, and I'm helping the cloudnative-pg team manage their backlog and am marking this issue as stale.
Issue Summary:
pg_stat_wal.stats_resetafter upgrading CloudNativePG from 1.27.0 to 1.27.1 on Amazon EKS.initdbnot being run or the query running on replicas wherepg_stat_walis less meaningful.Next Steps:
Thank you for your understanding and contribution!
aniravi24 commentedon Apr 24, 2026
@dosubot I still see this all the time, it's always in my logs. Have done several upgrades of CNPG now
dosubot commentedon Apr 24, 2026
This is a confirmed bug that is still present in the codebase. The root cause is that the
StatsResetfield in thePgStatWalstruct is defined as a plain (non-nullable) Gostring[1], but PostgreSQL'spg_stat_wal.stats_resetcolumn can legitimately be NULL — particularly on replica instances that have never generated WAL statistics. When the pgx driver tries to scan a NULL into a non-nullablestring, it fails with the error you're seeing.The SQL queries used to collect these metrics don't include any
COALESCEor NULL protection either [2].No fix has been merged yet. There are two viable approaches:
Type-safe fix — Change
StatsResetfromstringtosql.NullString(or*string) and handle the NULL case when emitting Prometheus labels. The codebase already usessql.NullStringelsewhere for similar situations [3].Architectural fix — Add a predicate query to only collect
pg_stat_walmetrics on primary instances, similar to what was done forpg_stat_archiverin PR #9411. This avoids the problem entirely since the data isn't meaningful on replicas anyway (as @redbaron noted above).The error doesn't break your cluster — it just means
pg_stat_walmetrics are not being collected, and the error line is logged repeatedly. But it's definitely noise that should be fixed. This issue could benefit from a PR if anyone wants to pick it up.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
honi-at-simspace commentedon May 5, 2026
@dosu
I put a PR to solve this issue using your approach 1.
honi-at-simspace commentedon May 8, 2026
@gbartolini What is the process for getting a review on my small PR to fix this bug? https://github.com/cloudnative-pg/cloudnative-pg/pull/10624
HoniSanders commentedon Jul 15, 2026
I opened a fix for this: #11207. Since PG18, pg_stat_wal.stats_reset can be NULL, but the exporter scanned it into a non-nullable string. The PR scans into sql.NullString at the scan site (per @mnencia's note in #9788), with tests for the NULL case.
fix(metrics): handle NULL stats_reset in pg_stat_wal
fix(metrics): handle NULL stats_reset in pg_stat_wal (#11207)
fix(metrics): handle NULL stats_reset in pg_stat_wal (#11207)
fix(metrics): handle NULL stats_reset in pg_stat_wal (#11207)
fix(metrics): handle NULL stats_reset in pg_stat_wal (#11207)