aboutsummaryrefslogtreecommitdiff
path: root/src/include/access/heapam.h
diff options
context:
space:
mode:
authorNoah Misch <noah@leadboat.com>2024-09-24 15:25:18 -0700
committerNoah Misch <noah@leadboat.com>2024-09-24 15:25:23 -0700
commit8590c942c1a6b861d0cf4fa5aa694ab3a65fa306 (patch)
tree73af53b6df3bf0a6abad9699e5bf802d2b7288d1 /src/include/access/heapam.h
parent41e0ba33d5ab2b2301aa5d932836927bf69a76a8 (diff)
downloadpostgresql-8590c942c1a6b861d0cf4fa5aa694ab3a65fa306.tar.gz
postgresql-8590c942c1a6b861d0cf4fa5aa694ab3a65fa306.zip
Fix data loss at inplace update after heap_update().
As previously-added tests demonstrated, heap_inplace_update() could instead update an unrelated tuple of the same catalog. It could lose the update. Losing relhasindex=t was a source of index corruption. Inplace-updating commands like VACUUM will now wait for heap_update() commands like GRANT TABLE and GRANT DATABASE. That isn't ideal, but a long-running GRANT already hurts VACUUM progress more just by keeping an XID running. The VACUUM will behave like a DELETE or UPDATE waiting for the uncommitted change. For implementation details, start at the systable_inplace_update_begin() header comment and README.tuplock. Back-patch to v12 (all supported versions). In back branches, retain a deprecated heap_inplace_update(), for extensions. Reported by Smolkin Grigory. Reviewed by Nitin Motiani, (in earlier versions) Heikki Linnakangas, and (in earlier versions) Alexander Lakhin. Discussion: https://postgr.es/m/CAMp+ueZQz3yDk7qg42hk6-9gxniYbp-=bG2mgqecErqR5gGGOA@mail.gmail.com
Diffstat (limited to 'src/include/access/heapam.h')
-rw-r--r--src/include/access/heapam.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h
index 50b9e729e63..266934b71b0 100644
--- a/src/include/access/heapam.h
+++ b/src/include/access/heapam.h
@@ -163,6 +163,13 @@ extern TM_Result heap_lock_tuple(Relation relation, HeapTuple tuple,
bool follow_update,
Buffer *buffer, struct TM_FailureData *tmfd);
+extern bool heap_inplace_lock(Relation relation,
+ HeapTuple oldtup_ptr, Buffer buffer);
+extern void heap_inplace_update_and_unlock(Relation relation,
+ HeapTuple oldtup, HeapTuple tuple,
+ Buffer buffer);
+extern void heap_inplace_unlock(Relation relation,
+ HeapTuple oldtup, Buffer buffer);
extern void heap_inplace_update(Relation relation, HeapTuple tuple);
extern bool heap_freeze_tuple(HeapTupleHeader tuple,
TransactionId relfrozenxid, TransactionId relminmxid,