]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Ensure vacuum removes all visibly dead tuples older than OldestXmin
authorMelanie Plageman <melanieplageman@gmail.com>
Fri, 19 Jul 2024 15:16:51 +0000 (11:16 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Fri, 19 Jul 2024 16:07:53 +0000 (12:07 -0400)
commit45ce054c02b8ac42909b8617819ff645e5c0487f
tree1ca0929e29fedaf5fe8a4066dfbbe1ed249ad054
parent5e578acca54b47c0fe195458f3fe57a5a42f4f01
Ensure vacuum removes all visibly dead tuples older than OldestXmin

If vacuum fails to remove a tuple with xmax older than
VacuumCutoffs->OldestXmin and younger than GlobalVisState->maybe_needed,
it will loop infinitely in lazy_scan_prune(), which compares tuples'
visibility information to OldestXmin.

Starting in version 14, which uses GlobalVisState for visibility testing
during pruning, it is possible for GlobalVisState->maybe_needed to
precede OldestXmin if maybe_needed is forced to go backward while vacuum
is running. This can happen if a disconnected standby with a running
transaction older than VacuumCutoffs->OldestXmin reconnects to the
primary after vacuum initially calculates GlobalVisState and OldestXmin.

Fix this by having vacuum always remove tuples older than OldestXmin
during pruning. This is okay because the standby won't replay the tuple
removal until the tuple is removable. Thus, the worst that can happen is
a recovery conflict.

Fixes BUG# 17257

Back-patched in versions 14-17

Author: Melanie Plageman
Reviewed-by: Noah Misch, Peter Geoghegan, Robert Haas, Andres Freund, and Heikki Linnakangas
Discussion: https://postgr.es/m/CAAKRu_Y_NJzF4-8gzTTeaOuUL3CcGoXPjXcAHbTTygT8AyVqag%40mail.gmail.com
src/backend/access/heap/pruneheap.c
src/backend/access/heap/vacuumlazy.c
src/include/access/heapam.h