Fix data loss at inplace update after heap_update().
Noah Misch <noah@leadboat.com>
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
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/heap/heapam.c | modified | +237 −15 |
| src/backend/access/heap/README.tuplock | modified | +11 −0 |
| src/backend/access/index/genam.c | modified | +137 −0 |
| src/backend/catalog/index.c | modified | +10 −28 |
| src/backend/catalog/toasting.c | modified | +24 −7 |
| src/backend/commands/dbcommands.c | modified | +12 −22 |
| src/backend/commands/vacuum.c | modified | +21 −11 |
| src/include/access/genam.h | modified | +9 −0 |
| src/include/access/heapam.h | modified | +7 −0 |
| src/test/isolation/expected/intra-grant-inplace-db.out | modified | +5 −5 |
| src/test/isolation/expected/intra-grant-inplace.out | modified | +10 −6 |
| src/test/isolation/specs/intra-grant-inplace-db.spec | modified | +0 −1 |
| src/test/isolation/specs/intra-grant-inplace.spec | modified | +3 −1 |
Discussion
- race condition in pg_class 86 messages · 2023-10-25 → 2026-02-16