From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Forget the prefetcher's current record in XLogPrefetcherBeginRea
Date: Thu, 19 Nov 2026 18:23:57 +0000
Message-ID: <E1xU6nc-00000000PnD-3HgH@gemulon.postgresql.org> (raw)
Forget the prefetcher's current record in XLogPrefetcherBeginRead()
XLogPrefetcherBeginRead() reset the decoder's record queue, but not
prefetcher->record, whose block references XLogPrefetcherNextBlock()
examines. The next read then continued with the remaining block
references of that stale record, before decoding the record at the new
read position.
FinishWalRecovery() re-reads the last replayed record to find the end
of WAL. When recovery stops at a recovery target, the prefetcher may
be part-way through a later record, and if its remaining block
references fill up the I/O queue, no record is decoded. This fails an
assertion in XLogPrefetcherReadRecord(). Without assertions, the start
of the last replayed record silently becomes the end of WAL, the new
timeline branches off at the wrong point, and the end-of-recovery
checkpoint fails with "xlog flush request ... is not satisfied". The
recovery signal file is gone by then, so a restart performs crash
recovery past the recovery target.
This mostly happens with maintenance_io_concurrency set to 7 or less,
and a recovery target shortly before an XLOG_FPI record written by an
index build, CLUSTER or similar operation, as such records carry up to
XLR_MAX_BLOCK_ID block references that need no I/O.
Fix by forgetting the current record in XLogPrefetcherBeginRead(). The
other callers run before the redo loop, when there is no current record.
Add a TAP test that stops recovery shortly before a multi-block XLOG_FPI
record of an SP-GiST index build, with maintenance_io_concurrency = 1.
The test uses SP-GiST rather than B-tree, so that it works unchanged in
the back branches. B-tree builds before 17 WAL-log each page in a
separate XLOG_FPI record with a single block reference, so the
prefetcher is never part-way through such a record.
Author: Tomas Vondra <tomas@vondra.me>
Reviewed-by: surya poondla <suryapoondla4@gmail.com>
Reviewed-by: shihao zhong <zhong950419@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/a797f236-286a-43e6-9b82-5f3d70bd5e99@vondra.me
Backpatch-through: 15
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/61b11a31bf4466983156a44d2a299cffed3529e3
Modified Files
--------------
src/backend/access/transam/xlogprefetcher.c | 3 +
src/test/recovery/meson.build | 1 +
.../recovery/t/061_recovery_target_prefetch.pl | 94 ++++++++++++++++++++++
3 files changed, 98 insertions(+)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tomas.vondra@postgresql.org
Subject: Re: pgsql: Forget the prefetcher's current record in XLogPrefetcherBeginRea
In-Reply-To: <E1xU6nc-00000000PnD-3HgH@gemulon.postgresql.org>
References: <E1xU6nc-00000000PnD-3HgH@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox