pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
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:46 +0000
Message-ID: <E1xTWjx-00000000BMb-0Mxy@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
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0e278a7ddee4093674d7ee8205423d2dea7ce672

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(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1xTWjx-00000000BMb-0Mxy@gemulon.postgresql.org>
Permalink:  ../E1xTWjx-00000000BMb-0Mxy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xTWjx-00000000BMb-0Mxy@gemulon.postgresql.org

 · 

reply

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: <E1xTWjx-00000000BMb-0Mxy@gemulon.postgresql.org>
  References: <E1xTWjx-00000000BMb-0Mxy@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