pgsql: heapam: Use exclusive lock on old page in CLUSTER

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: heapam: Use exclusive lock on old page in CLUSTER
Date: 2026-01-12 17:43:11
Message-ID: E1vfLwc-0004mC-1X@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)linnakangas(at)iki(dot)fi>
Reviewed-by: Kirill Reshke <reshkekirill(at)gmail(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2026-01-12 18:34:32 pgsql: heapam: Add batch mode mvcc check and use it in page mode
Previous Message Álvaro Herrera 2026-01-12 17:14:20 pgsql: Stop including {brin,gin}_tuple.h in tuplesort.h