pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix bug in following update chain when locking a heap tuple
Date: Tue, 23 Dec 2025 12:07:33 +0000
Message-ID: <E1vY1Aq-002FRH-2I@gemulon.postgresql.org> (raw)

Fix bug in following update chain when locking a heap tuple

After waiting for a concurrent updater to finish, heap_lock_tuple()
followed the update chain to lock all tuple versions. However, when
stepping from the initial tuple to the next one, it failed to check
that the next tuple's XMIN matches the initial tuple's XMAX. That's an
important check whenever following an update chain, and the recursive
part that follows the chain did it, but the initial step missed it.
Without the check, if the updating transaction aborts, the updated
tuple is vacuumed away and replaced by an unrelated tuple, the
unrelated tuple might get incorrectly locked.

Author: Jasper Smit <jasper.smit@servicenow.com>
Discussion: https://www.postgresql.org/message-id/CAOG+RQ74x0q=kgBBQ=mezuvOeZBfSxM1qu_o0V28bwDz3dHxLw@mail.gmail...
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/955f5506863dce0a3416e3fae7c3297dbbaa946d

Modified Files
--------------
src/backend/access/heap/heapam.c                   |  48 ++++++---
src/test/modules/injection_points/Makefile         |   3 +-
.../injection_points/expected/heap_lock_update.out |  83 +++++++++++++++
src/test/modules/injection_points/meson.build      |   1 +
.../injection_points/specs/heap_lock_update.spec   | 117 +++++++++++++++++++++
5 files changed, 236 insertions(+), 16 deletions(-)



view thread (6+ messages)

Message-ID: <E1vY1Aq-002FRH-2I@gemulon.postgresql.org>
Permalink:  ../E1vY1Aq-002FRH-2I@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vY1Aq-002FRH-2I@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix bug in following update chain when locking a heap tuple
  In-Reply-To: <E1vY1Aq-002FRH-2I@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