postgresql/src/backend
Melanie Plageman fd4f12df5e 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 may attempt to freeze the tuple's xmax and then ERROR out in
pre-freeze checks with "cannot freeze committed xmax".

Fix this by having vacuum always remove tuples older than OldestXmin.

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.

In back branches starting with 14, the first version using
GlobalVisState, failing to remove tuples older than OldestXmin during
pruning caused vacuum to infinitely loop in lazy_scan_prune(), as
investigated on this [1] thread. After 1ccc1e05ae removed the retry loop
in lazy_scan_prune() and stopped comparing tuples to OldestXmin, the
hang could no longer happen, but we could still attempt to freeze dead
tuples with xmax older than OldestXmin -- resulting in an ERROR.

Fix this by always removing dead tuples with xmax older than
VacuumCutoffs->OldestXmin. 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.

[1] https://postgr.es/m/20240415173913.4zyyrwaftujxthf2%40awork3.anarazel.de#1b216b7768b5bd577a3d3d51bd5aadee

Back-patch through 14

Author: Melanie Plageman
Reviewed-by: Peter Geoghegan, Robert Haas, Andres Freund, Heikki Linnakangas, and Noah Misch
Discussion: https://postgr.es/m/CAAKRu_bDD7oq9ZwB2OJqub5BovMG6UjEYsoK2LVttadjEqyRGg%40mail.gmail.com
2024-07-19 12:12:03 -04:00
..
access Ensure vacuum removes all visibly dead tuples older than OldestXmin 2024-07-19 12:12:03 -04:00
archive Fix memory leaks in error reporting with LOG level 2024-05-14 10:41:32 +02:00
backup Fix limit block handling in pg_wal_summary_contents(). 2024-07-09 09:29:11 +09:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Fix missing invalidations for search_path cache. 2024-07-09 11:27:10 -07:00
commands Use PqMsg_* macros in more places. 2024-07-17 10:51:00 -05:00
executor Propagate query IDs of utility statements in functions 2024-07-19 10:21:21 +09:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Move resowner from common JitContext to LLVM specific 2024-07-19 10:27:54 +03:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq A few follow-up fixes for GUC name quoting 2024-05-17 13:48:31 +02:00
main Tighten check for --forkchild argument when spawning child process 2024-07-03 16:20:56 +03:00
nodes Adapt REL_17_STABLE to its new status as a stable branch 2024-07-01 08:05:35 +09:00
optimizer Fix possible Assert failure in cost_memoize_rescan 2024-06-19 10:20:24 +12:00
parser SQL/JSON: Rethink c2d93c3802 2024-07-17 17:13:48 +09:00
partitioning Fix creation of partition descriptor during concurrent detach 2024-06-11 11:38:45 +02:00
po Translation updates 2024-06-24 13:11:27 +02:00
port Revise GUC names quoting in messages again 2024-05-17 11:44:26 +02:00
postmaster Do not summarize WAL if generated with wal_level=minimal. 2024-07-18 12:19:29 -04:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Use PqMsg_* macros in more places. 2024-07-17 10:51:00 -05:00
rewrite Fix assorted bugs related to identity column in partitioned tables 2024-05-07 22:50:00 +02:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
storage Fix lost Windows socket EOF events. 2024-07-13 15:02:33 +12:00
tcop Use PqMsg_* macros in more places. 2024-07-17 10:51:00 -05:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Use PqMsg_* macros in more places. 2024-07-17 10:51:00 -05:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make build on MinGW 2024-06-21 08:17:23 +02:00
meson.build meson: Fix import library name in Windows 2024-06-20 09:08:36 +02:00
nls.mk Add missing gettext triggers 2024-05-14 12:57:22 +02:00