pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: heapam: Use exclusive lock on old page in CLUSTER
Date: Mon, 12 Jan 2026 17:43:11 +0000
Message-ID: <E1vfLwc-0004mC-1X@gemulon.postgresql.org> (raw)

heapam: Use exclusive lock on old page in CLUSTER

To be able to guarantee that we can set the hint bit, acquire an exclusive
lock on the old buffer. This is required as a future commit will only allow
hint bits to be set with a new lock level, which is acquired as-needed in a
non-blocking fashion.

We need the hint bits, set in heapam_relation_copy_for_cluster() ->
HeapTupleSatisfiesVacuum(), to be set, as otherwise reform_and_rewrite_tuple()
-> rewrite_heap_tuple() will get confused. Specifically, rewrite_heap_tuple()
checks for HEAP_XMAX_INVALID in the old tuple to determine whether to check
the old-to-new mapping hash table.

It'd be better if we somehow could avoid setting hint bits on the old page. A
common reason to use VACUUM FULL is very bloated tables - rewriting most of
the old table during VACUUM FULL doesn't exactly help.

Reviewed-by: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://postgr.es/m/4wggb7purufpto6x35fd2kwhasehnzfdy3zdcu47qryubs2hdz@fa5kannykekr

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/852558b9ec9d54194195a7b7418d57e83a2fda70

Modified Files
--------------
src/backend/access/heap/heapam_handler.c    | 16 +++++++++++++++-
src/backend/access/heap/heapam_visibility.c |  7 +++++++
src/backend/access/heap/rewriteheap.c       |  3 +++
3 files changed, 25 insertions(+), 1 deletion(-)



Message-ID: <E1vfLwc-0004mC-1X@gemulon.postgresql.org>
Permalink:  ../E1vfLwc-0004mC-1X@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1vfLwc-0004mC-1X@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: andres@anarazel.de, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: heapam: Use exclusive lock on old page in CLUSTER
  In-Reply-To: <E1vfLwc-0004mC-1X@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