You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
After primary SIGKILL, CNPG promotes a replica that is not the most advanced one, causing timeline divergence on other replicas #11557
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.28 (latest patch)
What version of Kubernetes are you using?
1.35
What is your Kubernetes environment?
Cloud: Other
How did you install the operator?
Helm
What happened?
Bug description
After the primary Postgres pod received a SIGKILL (OOM / node eviction), CNPG failed over and promoted a replica for the cluster. However, the promoted replica was not the most up-to-date replica in terms of WAL position. As a result, at least one other replica (which had already received/applied WAL further ahead) could no longer stream from the new primary, because its own history diverged from the new timeline.
The failing replica logs show a classic "history mismatch" error: the new primary forked timeline 22 off timeline 21 at an earlier LSN (85/B7000000) than the position the other replica had already reached/expected (85/B8000000). This looks like the replica that got promoted was behind, rather than CNPG picking the replica with the most advanced WAL/LSN as the new primary.
Expected behavior
On failover, CNPG (via the instance manager / failover logic) should select the replica with the most advanced WAL position as the new primary, to avoid other replicas ending up on a timeline that has less data than they already received.
Actual behavior
A replica with less advanced WAL was promoted, causing the following on another (more advanced) replica:
FATAL: could not start WAL streaming: ERROR: requested starting point 85/B8000000 on timeline 21 is not in this server's history
DETAIL: This server's history forked from timeline 21 at 85/B7000000.
Followed by repeated:
LOG: new timeline 22 forked off current database system timeline 21 before current recovery point 85/B8000000
LOG: waiting for WAL to become available at 85/B8000018
LOG: unexpected pageaddr 85/95000000 in WAL segment 0000001500000085000000B8, LSN 85/B8000000, offset 0
This replica never recovers on its own and stays stuck waiting for WAL that will never arrive on the new timeline, since its own data is ahead of where the new primary forked.
Activity
feat: detect and contain a replica diverged onto a discarded timeline
feat: detect and contain a replica diverged onto a discarded timeline
feat: detect and contain a replica diverged onto a discarded timeline
feat: detect and contain a replica diverged onto a discarded timeline
feat: detect and contain a replica diverged onto a discarded timeline
feat(failover): detect and contain a replica that diverged from the p…
feat(failover): detect and contain a replica that diverged from the p…