Skip to content

wip(instance): keep the startup probe from failing during WAL replay - #11141

Closed
armru wants to merge 6 commits into
mainfrom
wal-replay-startup-probe
Closed

armru wants to merge 6 commits into
mainfrom
wal-replay-startup-probe

Conversation

@armru

@armru armru commented Jul 7, 2026 •

Copy link
Copy Markdown
Member

Closes #11024

armru and others added 5 commits July 7, 2026 12:58
A replica catching up on WAL after a restart, or a primary performing
crash recovery, can spend more than startDelay without accepting
connections. The startup probe then fails and the kubelet kills the
Pod, losing all the replay work done so far and repeating it at every
restart (#11024).

The instance manager now tracks evidence that WAL replay is making
progress by sampling the title of the PostgreSQL startup process. The
startup process sets its title to "recovering <segment>" every time
it opens a WAL segment, whether it comes from pg_wal, streaming
replication or the WAL archive, so the segment name is a replay
position advancing in every form of recovery, on any supported
PostgreSQL version and regardless of the log messages locale. While
replay is progressing, the startup probe reports success instead of
failing, handing control over to the readiness probe, which keeps the
instance out of the ready set until PostgreSQL accepts connections.

Since the kubelet stops running the startup probe after its first
success, the liveness probe takes over stall detection: if replay
stops making progress for more than startDelay before PostgreSQL
accepts connections, the liveness probe fails and the Pod is
restarted. startDelay therefore bounds the time allowed without
replay progress instead of the total startup time.

Based on the diagnosis of #11024 and on the probe design proposed in
#11138.

Fixes #11024

Co-authored-by: Jeremy Schneider <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
The startup probe now reports success during a progressing WAL replay
only when the new .spec.probes.startup.skipOnWALReplay option is
enabled, and only with the default pg_isready startup strategy, so
that custom startup strategies keep their configured semantics.

Since the replay position is observed at WAL segment granularity, the
stall timeout enforced by the liveness probe is now scaled with the
WAL segment size read from the control file, avoiding the restart of
an instance that is still making progress within a segment larger
than the default 16MiB.

Signed-off-by: Armando Ruocco <[email protected]>
Persist the startup skip and completion latches to a file on the pod
scratch volume: the kubelet keeps its startup probe state across an
in-place instance manager upgrade, so a new instance manager process
has to keep the stalled replay detection armed too. When a persisted
skip latch is restored, the stall clock restarts from load time,
giving a progressing instance a full fresh timeout while a stuck one
is still detected.

Log the state transitions (startup probe first reported as passed
during replay, and replay completed) at info level, so the behavior
can be diagnosed from the instance logs.

Warn at admission time about skipOnWALReplay values that the schema
accepts but the runtime ignores: the option set on the readiness
probe, or enabled together with a custom startup strategy.

Signed-off-by: Armando Ruocco <[email protected]>
succeedDuringWALReplay describes what actually happens: the startup
probe succeeds while WAL replay is progressing. Nothing is skipped,
that wording leaked from the probe response body.

Signed-off-by: Armando Ruocco <[email protected]>
The freshness window used by the startup probe to decide whether the
observed WAL replay progress is current defaults to 5 minutes and can
now be tuned with .spec.probes.startup.walReplayProgressTimeoutSeconds,
for instances whose replay of a single WAL segment may reasonably take
longer.

Signed-off-by: Armando Ruocco <[email protected]>
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

The admission webhook now also warns when walReplayProgressTimeoutSeconds
is set on the readiness probe or without succeedDuringWALReplay enabled,
since the runtime ignores it in both cases.

Signed-off-by: Armando Ruocco <[email protected]>
@armru

armru commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

@armru

armru commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

closing in favor of #11152

@armru armru closed this Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases ok to merge 👌 This PR can be merged release-1.28 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Replica enters crash/restart loop after restart with overloaded primary checkpointer

2 participants