From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix hash index redo reading a torn primary bucket page.
Date: Wed, 18 Nov 2026 03:53:45 +0000
Message-ID: <E1xTWjw-00000000BMR-46de@gemulon.postgresql.org> (raw)
Fix hash index redo reading a torn primary bucket page.
Replay of XLOG_HASH_DELETE, XLOG_HASH_MOVE_PAGE_CONTENTS and
XLOG_HASH_SQUEEZE_PAGE reads the primary bucket page only to take a
cleanup lock on it, so that no hot standby scan runs in the bucket while
tuples are removed or moved. VACUUM holds only a pin on that page, so
these records do not modify it and carry no full-page image of it.
If the on-disk page is torn and the full-page image that repairs it comes
later in the WAL, this read fails with "invalid page". That can happen in
crash recovery, and on a standby started from a base backup whose copy of
the page is torn.
The lock is needed only to serialize against hot standby scans, which can
run only once recovery has reached consistency. Skip the read and lock
while HotStandbyActiveInReplay() is false. This also avoids reading the
page before its repairing image has been replayed, since that image always
precedes the consistency point.
Reported-by: shihao zhong <zhong950419@gmail.com>
Author: Greg Burd <greg@burd.me>
Co-authored-by: Vignesh C <vignesh21@gmail.com>
Suggested-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: Joao Rito <joaovictor.rito@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Discussion: https://postgr.es/m/CAGRkXqT_AiwcsWZg5hnR1L2oWO8UpQpkL0iAjoZR+bey=GOWaQ@mail.gmail.com
Discussion: https://postgr.es/m/CAA4eK1LwZk0MaK0LncZz6hsqcHnamfJB47nA8xuwRp4CyLFKzw@mail.gmail.com
Backpatch-through: 15
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/8becd1123c98cd9338678c6c2d4ae6b4d56a6fb9
Modified Files
--------------
src/backend/access/hash/hash_xlog.c | 52 +++++++++++++++++++++++++------
src/backend/access/transam/xlogrecovery.c | 3 +-
src/include/access/xlogrecovery.h | 1 +
3 files changed, 45 insertions(+), 11 deletions(-)
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: akapila@postgresql.org
Subject: Re: pgsql: Fix hash index redo reading a torn primary bucket page.
In-Reply-To: <E1xTWjw-00000000BMR-46de@gemulon.postgresql.org>
References: <E1xTWjw-00000000BMR-46de@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