Repository navigation
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
tag me in github
Version
1.30 (latest patch)
What version of Kubernetes are you using?
1.35
What is your Kubernetes environment?
Other
How did you install the operator?
Helm
What happened?
A node running one of our replicas was down for about two days. The primary wrote more WAL than max_slot_wal_keep_size (6GB) during that time, so PostgreSQL invalidated the replica's HA slot:
slot_name | active | wal_status | invalidation_reason
--------------------+--------+------------+---------------------
_cnpg_cluster_example_2 | f | lost | wal_removed
When the node came back, the replica could not start streaming and kept falling back to restoring WAL from the archive:
FATAL: could not start WAL streaming: ERROR: can no longer access replication slot "_cnpg_cluster_example_2"
DETAIL: This replication slot has been invalidated due to "wal_removed".
It caught up from the archive, but it never went back to streaming. The cluster reported Cluster in healthy state with all instances ready, and stayed like that until we fixed it by hand.
The other 15 replicas on the same node reconnected fine because their slots had not been invalidated.
Looking at the code, reconcilePrimaryHAReplicationSlots only creates a slot when no slot with that name exists. infrastructure.List does not read wal_status, so a lost slot counts as present and is left alone. An invalidated slot cannot be reused, it has to be dropped and created again.
There is a second, smaller problem. After we dropped the slot manually, the operator did not recreate it. On the primary, HA slots seem to be reconciled only when the Cluster object changes (instance_controller.go), so in a quiet, healthy cluster that can take a long time. The replica kept logging replication slot "_cnpg_cluster_example_2" does not exist. We had to create the slot ourselves:
SELECT pg_drop_replication_slot('_cnpg_cluster_example_2');
SELECT pg_create_physical_replication_slot('_cnpg_cluster_example_2');After that the replica switched to streaming within a few seconds.
Expected: if a HA slot is inactive and wal_status = 'lost', the operator drops and recreates it. If the replica can no longer catch up, it should at least report the instance as not healthy instead of showing the cluster as healthy.
To reproduce:
- Create a 3-instance cluster with
max_slot_wal_keep_sizeset (e.g. 1GB). - Stop one replica (e.g. scale down its node or cordon it and delete the pod).
- Write more than
max_slot_wal_keep_sizeof WAL on the primary. - Bring the replica back. Its slot is
lost, the replica only restores from the archive, and the cluster is reported as healthy.
Possibly related, but not the same: #8726, #10419.
Cluster resource
spec:
instances: 3
imageCatalogRef: # PostgreSQL 18.4
apiGroup: postgresql.cnpg.io
kind: ClusterImageCatalog
name: <custom catalog>
major: 18
postgresql:
parameters:
max_slot_wal_keep_size: "6GB"
wal_keep_size: "512MB"
archive_timeout: "5min"
replicationSlots:
highAvailability:
enabled: true
slotPrefix: _cnpg_
synchronizeReplicas:
enabled: true
updateInterval: 30
plugins:
- name: pgbackrest.cnpg.opera.com
isWALArchiver: trueRelevant log output
{"logger":"postgres","msg":"record","logging_pod":"cluster-example-2","record":{"error_severity":"FATAL","message":"could not start WAL streaming: ERROR: can no longer access replication slot \"_cnpg_cluster_example_2\"\nDETAIL: This replication slot has been invalidated due to \"wal_removed\"."}}
{"logger":"wal-restore","msg":"Refusing to restore future timeline history file"}
{"logger":"postgres","msg":"record","logging_pod":"cluster-example-2","record":{"error_severity":"LOG","message":"waiting for WAL to become available at 3/9000018"}}Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
[-][Bug]:[/-][+][Bug]: Invalidated (`wal_status = lost`) HA replication slot is never recreated, replica stays on archive recovery forever[/+]gbartolini commentedon Oct 22, 2026
I think this is related to https://www.postgresql.org/message-id/CA%2BVUV5r0XoJdXpM_NFcxw5_YXmcHoAWb909Fu9ApUsH16Sf6_w%40mail.gmail.com
LeVadim commentedon Nov 3, 2026
We hit the same thing on CloudNativePG 1.30.1 with PostgreSQL 18.6, using plugin-barman-cloud v0.15.1 as the WAL archiver, so it is not specific to the pgBackRest plugin. This was on kind, with a 3-instance cluster and HA replication slots at their defaults. The only relevant settings were
max_slot_wal_keep_size: 256MBandarchive_timeout: 60s.Steps
kubectl cnpg fencing on <cluster> <cluster>-2.pgbench -i -s 70), then runCHECKPOINT,SELECT pg_switch_wal()andCHECKPOINTagain.wal_status = lost,active = f.kubectl cnpg fencing off <cluster> <cluster>-2.What we saw 240 s after unfencing
pg_stat_replicationlists only<cluster>-3(streaming,quorum).pg_replication_slotsstill shows_cnpg_<cluster>_2 | lost | f.Cluster in healthy state.restored log file, 28could not start WAL streaming: ERROR: can no longer access replication slot, and 27waiting for WAL to become availablelines.So the replica keeps up from the archive, but it does not stream again on its own and stays out of the synchronous quorum. Nothing in the Cluster status shows it.
The second problem you describe reproduces too
SELECT pg_drop_replication_slot('_cnpg_<cluster>_2')on the primary, the slot had not been recreated 120 s later. The replica was still not streaming.kubectl delete pod <cluster>-2) got things moving. Within 150 s the slot was back asreservedand the replica wasstreaming/quorum, with no manualpg_create_physical_replication_slot.The same symptom showed on a second cluster in the same environment. It looks related to #11762 and #11808.