]> git.ipfire.org Git - thirdparty/postgresql.git/commit
heapam: Use exclusive lock on old page in CLUSTER
authorAndres Freund <andres@anarazel.de>
Mon, 12 Jan 2026 16:50:05 +0000 (11:50 -0500)
committerAndres Freund <andres@anarazel.de>
Mon, 12 Jan 2026 17:40:13 +0000 (12:40 -0500)
commit852558b9ec9d54194195a7b7418d57e83a2fda70
tree2abf5bf1c83c40b2bf700ed53e867363138713cc
parent45f658dacb9c2d333893fcf0d6b5a5e4f8ee5752
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
src/backend/access/heap/heapam_handler.c
src/backend/access/heap/heapam_visibility.c
src/backend/access/heap/rewriteheap.c