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.
Version
1.30.0
What version of Kubernetes are you using?
1.34
What is your Kubernetes environment?
Self-managed: k3s
How did you install the operator?
YAML manifest
What happened?
The version and environment fields above describe the third-party reproduction this report is based on, not a deployment of mine. This comes from reading the code after that reproduction was published, and I am filing it because the mechanism checks out against main and against every supported release.
The primary isolation check is documented as fencing an isolated primary and stopping it from accepting writes. It does not do that. It only returns HTTP 500 from the liveness probe (pkg/management/postgres/webserver/probes/liveness.go). The kubelet then signals the container, and the instance manager handles that signal by calling TryShuttingDownSmartFast (internal/cmd/manager/instance/run/lifecycle/lifecycle.go), which issues pg_ctl stop -m smart -w -t 180 first (pkg/management/postgres/instance.go). A PostgreSQL smart shutdown refuses new connections but lets every session that is already open run to completion, so sessions established before the partition keep committing on the isolated primary for up to smartShutdownTimeout, which defaults to 180 seconds.
This is not an argument for changing the shutdown mode generally. Smart shutdown is the right behaviour for the other paths that reach this code, a rolling update, a pod deletion, a node drain, where not killing user sessions is the entire point. The problem is that the isolation path, whose purpose is to stop writes as quickly as possible, inherits a shutdown routine designed for planned termination.
The documentation does not describe this. docs/src/failover.md says "The isolation check stops an isolated primary from continuing to accept writes", and docs/src/instance_manager.md says the isolation check "fences" a primary and that the effect is to "shut it down" when the liveness probe fails. On an asynchronous cluster none of that holds for the sessions that are already connected: they go on committing, and go on being acknowledged, for the length of the smart shutdown.
Evidence
Coroot published a measured reproduction at https://coroot.com/blog/reproducing-split-brain-on-cloudnativepg/, on 1.30.0 with asynchronous replication, and their numbers match the mechanism. They applied a network partition at 18:11:20, the isolation check fired 34 seconds in ("18:11:54 Killing Container postgres failed liveness probe"), and the isolated primary acknowledged its last write at 18:14:55, t+215s. 215 minus 34 is 181, against the 180 second smartShutdownTimeout. Their replacement primary took its first write at 18:13:17, so 99 seconds passed with both primaries acknowledging commits. Of the writes acknowledged after the partition they report 291 rows that pg_rewind later deleted and 562 for which, in their words, "that id now belongs to another client".
On synchronous replication
Synchronous replication closes this, and it is the project's standing advice for not losing commits: it is what the sample cluster and the quickstart configure on main, and #11148 warns when a multi-instance cluster has none. With it configured the isolated primary blocks on COMMIT and never acknowledges, and the blocked transactions are not visible to any other session either, since the transaction stays in the procarray for the whole wait.
This report is therefore about asynchronous clusters, which is what was measured above and what every released version still defaults to.
Suggested direction
Have the isolation check request a fast shutdown rather than only failing the probe, so that stopping the primary does not depend on the kubelet's timing or on a shutdown routine shared with planned termination.
Most of the machinery for that already exists: Instance.RequestFastImmediateShutdown() in pkg/management/postgres/instance.go puts the request on the instance command channel. Note that it is not unused, reconcileOldPrimary already demotes a former primary through it, so the isolation path needs a budget of its own rather than the one that path relies on. Its interaction with the lifecycle loop needs attention too, since an instance stopped for isolation must not be restarted in place.
This only collapses the second of two windows. From the partition until the liveness probe gives up, roughly 30 seconds with the default probe settings, the primary is fully open. After that, and this is the part the fix addresses, only the sessions already established on the isolated side keep writing, for up to smartShutdownTimeout.
Scope
The isolation check landed in 1.27.0, so this affects every supported release as well as main. The primary lease added in 1.30.0 neither helps nor is meant to: an isolated instance manager cannot reach the API server, so it classifies its lease read as unverifiable and keeps running, which docs/src/failover.md already documents.
Until this is fixed, spec.smartShutdownTimeout: 0 skips straight to a fast shutdown and collapses the second window to the probe detection latency.
Cluster resource
$ kubectl get cluster postgres-splitbrain -o json | jq '.spec | {failoverDelay, smartShutdownTimeout, probes}'
{
"failoverDelay": 0,
"smartShutdownTimeout": 180,
"probes": {
"liveness": {
"isolationCheck": {"connectionTimeout": 1000, "enabled": true, "requestTimeout": 1000}
}
}
}(Coroot's cluster as they published it; the rest was default.)
Relevant log output
# partition applied at 18:11:20
18:11:54 Killing Container postgres failed liveness probe
18:11:57 FailingOver Current primary isn't healthy, initiating a failover
18:11:58 FailoverTarget Failing over from postgres-splitbrain-1 to postgres-splitbrain-2
# new primary takes its first write at 18:13:17
# isolated primary acknowledges its last write at 18:14:55, t+215sCode of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
def commentedon Jul 30, 2026
Hi team, I'm the author of the post mentioned above. If there's anything I can help with, just let me know.
ardentperf commentedon Jul 31, 2026
wrt. sync replication, i think it's worth just posting a link to #10783 too ~ discussion around moving toward sync-replication-by-default
ardentperf commentedon Aug 15, 2026
@mnencia should it be an immediate shutdown?
mnencia commentedon Aug 15, 2026
@ardentperf I don't see any advantage of an immediate shutdown over a fast one. In both cases all transactions are immediately canceled. An immediate would only add an unnecessary and unneeded crash recovery.
ardentperf commentedon Aug 15, 2026
If rewind is happening then do we need the checkpoint that fast shutdown waits for? Won’t hot-standby startup need to replay WAL at the rewind point either way?
I think the main concern is cases where isolation check kicks in, but cnpg does not choose a new primary, and the restarted primary eventually takes writes again as a primary.
This seems like the less common case and I was wondering if it makes more sense to optimize for the more common case (about to rewind). Immediate would be significantly faster on systems with large buffer caches - I have seen checkpoints spike to double-digit minutes under demanding workloads. Immediate might enable the system to come back as a replica more quickly.
Admittedly this stuff is tricky to reason through though, a test with a large dirty buffer cache would be worthwhile just to confirm my thinking about Postgres behavior; I might have it wrong
gbartolini commentedon Aug 16, 2026
Given the extraordinary nature of this decision to make (emergency), I am inclined to automatically trigger an immediate shutdown. In my opinion, the most common scenario aligns with what @ardentperf described. However, we could implement a setting that lets users choose the shutdown type (smart, fast, or immediate), with immediate as the default. What are your thoughts on this?
mnencia commentedon Aug 16, 2026
@ardentperf if my memory doesn't trick me, pg_rewind requires a clean shutdown to work correctly, so if we do an immediate shutdown, when the node restarts, pg_rewind will need to start the instance and shutdown it cleanly before rewinding the node. This is handled automatically by pg_rewind, but is additional work to do (crash recovery, fast shutdown, rewindil).
15 remaining items
PeterZaitsev commentedon Oct 14, 2026
Independent reproduction on 1.30.1 (the release that carries #11518, #11347 and #11356), following the method from the Coroot post.
Setup: k3s v1.35.9, 1 tainted control-plane node + 3 workers (2 vCPU / 4 GB), local-path storage.
cluster-example(3 instances, PG 18.6), async replication, defaults:smartShutdownTimeout: 180,failoverDelay: 0, isolation check enabled. Three writers on the control-plane node hold persistent connections through-rwand insert a row every ~100 ms, logging each acknowledged id and commit timestamp.Fault: iptables rules inside the primary pod's network namespace drop everything except the client pods' subnet and the node's own pod CIDR, which keeps the kubelet's probes working. That cuts the pod off from the replicas, the operator, the barman-cloud plugin and the API server (10.43.0.0/16). The partition lasted 300 s.
Result with defaults (1.30.1):
database system is ready to accept connections)So the window described here is still present in 1.30.1.
Same fault with the mitigations (one run each):
smartShutdownTimeout: 0smartShutdownTimeout: 0,failoverDelay: 30synchronous: {method: any, number: 1, dataDurability: required, failoverQuorum: true}With quorum sync, the writers' sessions stayed blocked on the old primary until the smart shutdown expired (+207 s), so they could not reach the new primary for about 130 s after it was ready.
Two related observations on 1.30.1:
-rwfailed for 264 s, because the node went NotReady (see also [Bug]: Healthy primary removed from -rw when its node loses API-server connectivity, no failover (136 s write outage) #11656).I can share the scripts if that is useful.
ardentperf commentedon Oct 20, 2026
@PeterZaitsev thanks for testing against 1.30+ which includes the new primary lease feature. we probably need to see how that is interacting with this, since it may change the failure modes and how things play out
gbartolini commentedon Oct 23, 2026
I agree with you, thanks @PeterZaitsev. We are implementing several changes to enhance asynchronous replication scenarios and are shifting our focus towards data durability rather than self-healing for these situations. By the time we reach epic #11721, we expect to be in a much better position, and we would appreciate it if the tests could be re-run at that point (using the development snapshots).
mnencia commentedon Oct 29, 2026
Fixed on
main. #11357 moved the isolation check to the primary lease and #11358 turned the liveness probe into a watchdog. An isolated primary now gets an immediate shutdown 10-13s after its last lease renewal. If PostgreSQL is still running at 13s, the instance manager sends SIGQUIT and exits. Both happen before a replica can claim the lease at 15s. The smart shutdown window is gone, and the docs match the code.1.30 keeps the old probe-based check, so the window is still there. We did not backport the fix. The first attempt (#11504) fired on ordinary connectivity blips, and the lease rework is too big to backport. #11518 documents the window on 1.30. Until 1.31,
smartShutdownTimeout: 0closes it.Some loss remains on async clusters. Writes acknowledged before the stop (up to about 13s) are lost, and only synchronous replication prevents that. Further hardening is tracked in #11721.
@PeterZaitsev, @def: it would be great to re-run your tests on a 1.31 development snapshot.