Repository navigation
Description
[Bug]: Replica cluster with primaryUpdateMethod: switchover gets stuck when WAL receiver is temporarily inactive
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.
Related issues:
- [Bug]: Operator stuck in reconciliation loop #9885 - Operator stuck in reconciliation loop (similar symptoms, different cause)
- [Bug]: Stuck in phase "Waiting for the instances to become active" #8602 - Stuck in phase "Waiting for the instances to become active" (closed without fix)
- [Bug]: demoted replica cluster stuck with all Pods being not ready #5754 - demoted replica cluster stuck (different scenario)
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
- Yes
Version
1.28.0
What version of Kubernetes are you using?
1.30
What is your Kubernetes environment?
Self-managed (production)
How did you install the operator?
Helm
What happened?
Summary
A replica cluster (replica.enabled: true) with primaryUpdateMethod: switchover gets stuck in phase "Waiting for the instances to become active" when attempting to roll out pod changes (e.g., after spec changes like fsGroupChangePolicy).
The operator repeatedly logs "Pod rollout required" but never performs the rollout. The cluster remains stuck indefinitely.
Root Cause Analysis
After tracing the code, I identified the exact blocking condition in cluster_upgrade.go:
- The operator detects the designated primary needs rollout
- With
switchovermethod, it selects the cascading replica as the switchover target - At line 213, it checks
if !targetInstance.IsWalReceiverActive - If the WAL receiver is not active (even temporarily), it returns
errLogShippingReplicaElected - The phase is never updated to reflect this blocked state
- Result: Cluster shows stale "Waiting for instances to become active" phase
The Problematic Code Path
// cluster_upgrade.go:194-222
if cluster.Status.Instances > 1 && len(podList.Items) > 1 {
targetInstance := podList.Items[1] // Cascading replica for replica clusters
if targetInstance.Pod.Name == primaryPod.Name {
targetInstance = podList.Items[0]
}
// THIS CHECK BLOCKS ROLLOUT
if !targetInstance.IsWalReceiverActive {
contextLogger.Info(
"chosen new primary is still not connected via streaming replication",
...)
return false, errLogShippingReplicaElected // Returns error, no phase update
}
// Only reached if WAL receiver is active
return true, r.setPrimaryInstance(ctx, cluster, targetInstance.Pod.Name)
}Why This is Problematic for Replica Clusters
For replica clusters with cascading replication:
External Source
│
▼ (streaming replication)
Pod-2 (designated primary)
│
▼ (cascading replication)
Pod-1 (cascading replica)
- The "switchover" semantics don't apply the same way as regular clusters
- There's no real "promotion" - just a change in which pod replicates from external
- The WAL receiver check is too strict - temporary disconnections block rollouts indefinitely
- The phase message is misleading - all pods ARE active, but the rollout is blocked
Phase Staleness Issue
The phase "Waiting for the instances to become active" is set earlier when allInstancesAreActive() returned false. When the pods become ready, allInstancesAreActive() returns true, and reconciliation proceeds to handleRollingUpdate. However, when blocked by errLogShippingReplicaElected:
// cluster_controller.go:1098-1103
case errors.Is(err, errLogShippingReplicaElected):
contextLogger.Warning(
"The primary needs to be restarted, but the chosen new primary is still " +
"not connected via streaming replication, waiting for 5 seconds",
)
return ctrl.Result{RequeueAfter: 5 * time.Second}, nil // NO PHASE UPDATE!The phase is never updated, leaving users confused with a stale message.
Steps to Reproduce
- Create a replica cluster:
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: replica-test
spec:
instances: 2
primaryUpdateMethod: switchover
primaryUpdateStrategy: unsupervised
replica:
enabled: true
source: external-cluster
# ... storage config
externalClusters:
- name: external-cluster
connectionParameters:
host: primary-cluster-rw
# ...- Wait for cluster to become healthy
- Apply a spec change that triggers pod rollout (e.g., change
fsGroupChangePolicy) - Observe the cluster gets stuck in "Waiting for the instances to become active"
Expected Behavior
- The phase should be updated to reflect the actual blocking condition
- For replica clusters, the rollout should work even with temporary WAL receiver disconnections
- The designated primary should be rollable directly (like a replica) since there's no real failover
Actual Behavior
- Phase shows stale "Waiting for the instances to become active"
- Operator logs "Pod rollout required" repeatedly
- No actual rollout occurs
- Cluster remains stuck indefinitely
Workarounds
- Use
restartinstead ofswitchoverfor replica clusters:
spec:
primaryUpdateMethod: restart- Manually delete the designated primary pod:
kubectl delete pod <cluster>-2 -n <namespace>Diagnostic Commands
# Check if replica cluster with switchover
kubectl get cluster <name> -o jsonpath='{.spec.replica.enabled}' # true
kubectl get cluster <name> -o jsonpath='{.spec.primaryUpdateMethod}' # switchover
# Check WAL receiver status
kubectl exec -it <cluster>-1 -c postgres -- psql -U postgres -c \
"SELECT pid, status, sender_host FROM pg_stat_wal_receiver;"
# Check operator logs for blocking message
kubectl logs -l app.kubernetes.io/name=cloudnative-pg -n cnpg-system | \
grep -i "not connected via streaming"Proposed Fix
See attached PR that:
- Updates the phase when blocked by
errLogShippingReplicaElected - Adds a metric for blocked rollouts
- (Optional) Considers using
restartsemantics for replica cluster designated primary
Cluster Resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: pg-b21fd85c-95b2-438d-b6e5-2308a6155695
namespace: databases
spec:
instances: 2
primaryUpdateMethod: switchover
primaryUpdateStrategy: unsupervised
replica:
enabled: true
source: external-cluster
postgresql:
parameters:
max_connections: "200"
storage:
size: 100Gi
storageClass: premium-rwo
# ...Relevant Log Output
{"level":"info","ts":"...","msg":"Pod rollout required","controller":"cluster","podName":"pg-xxx-2","reason":"startup-probe differs"}
{"level":"info","ts":"...","msg":"Pod rollout required","controller":"cluster","podName":"pg-xxx-2","reason":"startup-probe differs"}
... (repeats every ~1 second)
The expected switchover log ("The primary needs to be restarted, we'll trigger a switchover") never appears.
Code of Conduct
- I agree to follow this project's Code of Conduct
Analysis Artifacts
Full code path analysis with Mermaid diagrams: CNPG-Reconciliation.md
Key Files Traced
| File | Line | Function | Description |
|---|---|---|---|
cluster_controller.go |
770 | allInstancesAreActive() |
Gate before pod reconciliation |
cluster_controller.go |
1085 | handleRollingUpdate |
Calls rollout logic |
cluster_controller.go |
1096 | rolloutRequiredInstances |
Main rollout orchestration |
cluster_controller.go |
1098-1103 | error handling | Missing phase update |
cluster_upgrade.go |
54 | rolloutRequiredInstances |
Pod iteration logic |
cluster_upgrade.go |
147 | updatePrimaryPod |
Primary rollout logic |
cluster_upgrade.go |
213 | WAL receiver check | BLOCKING CONDITION |
status.go |
313-321 | Less |
Replica cluster sorting |
probes.go |
559 | IsWALReceiverActive |
Check pg_stat_wal_receiver |
Activity
dosubot commentedon Feb 6, 2026
Hi @usiegj00! I'm Dosu and I’m helping the cloudnative-pg team.
Your analysis is correct: this is a new bug and not tracked in any existing issue or PR. The code path in
cluster_upgrade.goandcluster_controller.goconfirms that when a replica cluster withprimaryUpdateMethod: switchovertries to roll out the designated primary, the operator blocks rollout if the WAL receiver on the switchover target is inactive—even temporarily. When this happens, the operator returns an error but does not update the cluster phase, so the UI remains stuck on "Waiting for the instances to become active" even though all pods are healthy and ready. This leads to indefinite blocking and a misleading phase message, matching your description and code trace.No documentation or release notes mention this scenario, and related issues like #9885, #8602, and #5754 discuss similar symptoms but have different root causes or were closed without a fix. The workaround you described—switching to
primaryUpdateMethod: restartor manually deleting the designated primary pod—is currently the only way to unblock the rollout. Your proposed fix (updating the phase and/or relaxing the WAL receiver check for replica clusters) would address the root cause and improve user experience. This behavior has not been addressed in any recent release or open PRs as of v1.28.0 and 1.28.1 [source].Let me know if you want a deeper dive into the code or more details on possible mitigations.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
usiegj00 commentedon Feb 6, 2026
Update: Pod deletion workaround did not work
Attempted the manual pod deletion workaround on a stuck replica cluster:
startDelay: 32) → No effectObservations:
FailingOverbetween podsinstancesStatus.healthyshows both podsHealthyNext attempt: Will try changing
primaryUpdateMethodfromswitchovertorestartto see if that resolves the stuck state.usiegj00 commentedon Feb 6, 2026
Update: Successful Fix Procedure
After extensive testing, I found that simple pod deletion does not resolve this issue. Here's what we tried and what actually worked:
What Didn't Work
primaryUpdateMethodtorestart- Still stuckWhat Actually Worked
The only fix that worked was a complete cluster rebuild:
Why Step 2 is Critical
After deleting all PVCs/pods, the operator logged:
The
latestGeneratedNodestatus field acts as a safety mechanism but must be manually reset after a disaster recovery scenario.Post-Fix Status
After the rebuild completed (~15 minutes for pgbasebackup):
Recommendation
The workaround section in the issue should be updated to note that simple pod deletion may not work and a full rebuild may be required for severely stuck clusters.
jsilvela commentedon Mar 17, 2026
Hi,
I haven't tried to repro your issue yet, and I'm talking only from looking at the code, so please take my comments with a grain of salt and excuse if I miss something.
Something that I don't get in your report is the "even temporarily" part.
When the primary update fails, in the code you show, the error bubbles up to here
in
cluster_controller.go, line 1112What I expect there is a retry.
Are you seeing a retry and then the same behavior repeating, or is the "Pod rollout required" happening only once?
You say that for the replica cluster a switchover is not really a switchover, but it's not only marking an instance as the new designated primary, but setting the other instances to stream from the new designated primary.
What's going on in the replica instances? Why are they not streaming from the designated primary? Any error logs in them?
usiegj00 commentedon Mar 26, 2026
You know I tried to dig in while we had a number of instances to test in this configuration, and I really did think we had isolated this. BUT I completely agree that this code path could not be the issue. I could have walked myself into the wrong cul de sac as you can see I was updating the ticket as I tried to pin things down. I will do a better job if/when I come across this again.
jsilvela commentedon Apr 4, 2026
Ha, the bugs get more subtle as the codebase improves.
dosubot commentedon Aug 17, 2026
Hi, @usiegj00. I'm Dosu, and I'm helping the cloudnative-pg team manage their backlog and am marking this issue as stale.
Issue Summary
primaryUpdateMethod: switchovercan get stuck during pod rollouts in a perpetual “Waiting for the instances to become active” state.restartdid not resolve the issue.status.latestGeneratedNodeto0.Next Steps
Thanks for your understanding and contribution.
zerkms commentedon Sep 2, 2026
I think I observe this very bug too.
I also have a test cluster with
primaryUpdateMethod: switchover(one primary and two replicas) and here is what I see in logs in the replica (db-3) that has been restarted:It's now been lasting for 12+ hours.
I have fixed it with removing PVC/pod and letting cnpg recreate it from the scratch.
Coincidentally, the other replica (db-2) has been broken in the other way:
BUT!!! - recreating
db-3replica also fixeddb-2as well.CNPG version: 1.30.0
github-actions commentedon Nov 11, 2026
This issue is stale because it has been open for 60 days with no activity.
github-actions commentedon Nov 25, 2026
This issue was closed because it has been inactive for 14 days since being marked as stale.