Checkpoint taken during vac_truncate_clog() records a stale oldestXid; after a crash pg_xact_status() errors on truncated XIDs ============================================================================================================================== AI-generated bug report from the AI Annex Report ID: 01a1f1fd-e9f4-7b04-ada4-9a6f69bfcfac Filed: 2026-11-19 04:08:31 UTC Severity: 25/100 Blamed commit: ea42cc18c35381f639d45628d792e790ff39e271 ## Summary vac_truncate_clog() truncates pg_xact first, which advances oldestClogXid and WAL-logs CLOG_TRUNCATE. It only later calls SetTransactionIdLimit(), which advances TransamVariables->oldestXid. A checkpoint that reads oldestXid in between writes the old value, with a REDO pointer after the CLOG_TRUNCATE record. If the server crashes before the next checkpoint, startup initializes oldestClogXid from that stale oldestXid, and redo never replays the truncation. pg_xact_status() for an XID between the stale oldestXid and the start of the oldest remaining pg_xact segment then raises "could not access status of transaction" instead of returning NULL. ## Reproduction This needs a pause between TruncateCLOG() and SetTransactionIdLimit() in vac_truncate_clog(), e.g. a debugger breakpoint on SetTransactionIdLimit in the vacuuming backend. Commit timestamp and multixact truncation run in that window, so it lasts as long as their unlinks take. -- autovacuum = off; template0 ALLOW_CONNECTIONS true -- consume XIDs so that VACUUM FREEZE of every database moves -- datfrozenxid past a pg_xact segment boundary (about 1M XIDs), -- then VACUUM FREEZE template0 and template1. -- session A, in the last database (breakpoint hits): VACUUM FREEZE; -- session B, while A is stopped at the breakpoint: CHECKPOINT; -- crash: pg_ctl stop -m immediate; then start SELECT pg_xact_status(:'xid_in_removed_segment'::xid8); Observed (oldestXID in pg_controldata is 52079065; the oldest pg_xact segment left is 0032, which starts at 52428800): ERROR: could not open file "pg_xact/0031": No such file or directory DETAIL: Could not access commit status of transaction 52100000. Without the CHECKPOINT the same crash is harmless, because redo replays CLOG_TRUNCATE and advances oldestClogXid. ## Analysis CreateCheckPoint() deliberately does not save oldestClogXid. Its comment says that if we crash during clog truncation, "we'll redo the clog truncation and fix up oldestClogXid". That holds only if the checkpoint's REDO point precedes the CLOG_TRUNCATE record. A checkpoint whose REDO point follows it, but which read oldestXid before SetTransactionIdLimit(), breaks the assumption. DELAY_CHKPT_START in TruncateMultiXact() does not help, because oldestXid has already been read when the checkpointer waits on it. The stale value persists across later checkpoints until datfrozenxid next changes, because ForceTransactionIdLimitUpdate() normally returns false. ## Notes Tested on master ba11c48390004ed49b889cbd718c9e5f691fe493 (cassert), using a test-only sleep before SetTransactionIdLimit() in vac_truncate_clog(), CHECKPOINT during the sleep, then an immediate shutdown. Tuple visibility is not affected, because all live XIDs follow datfrozenxid. Only status lookups by explicit XID (pg_xact_status, txid_status) are exposed. The same ordering in vac_truncate_clog() and the same CreateCheckPoint() comment are present on REL_14_STABLE and later. Back branches were not tested.