model-writtenrun 4755 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Hubert depesz lubaczewski reported that PostgreSQL 12 removed WAL still required by a logical replication slot during an upgrade to PostgreSQL 14, leaving replication unable to restart even after archived files were restored #1.
- Amit Kapila recommended diagnostic logging, while Kyotaro Horiguchi investigated whether an external process could have removed the files; production restart constraints led to using DEBUG2 logging and upgrading PostgreSQL 12 before repeating the experiment #2 #3 #5 #12 #15.
- The failure recurred with logs showing PostgreSQL recycling the required segments, and one affected replication later recovered spontaneously as its restart_lsn advanced #16 #17 #21.
- Amit supplied checkpoint instrumentation to expose the retention calculation, but deploying it required a production rebuild and restart, and the attachment did not apply to the reporter's PostgreSQL 12 source #18 #19 #42.
- Masahiko Sawada reproduced a possible crash-restart race between an in-memory restart_lsn update and persistence, and Andres Freund suggested protection analogous to effective_catalog_xmin; however, the reporter found no server crashes, so this did not explain the reported incident #31 #39 #41 #44.
- Amit identified that a candidate_restart_lsn older than restart_lsn could move the slot backward, but his initial explanation involving restoration of a serialized snapshot was rejected because restoration does not restore last_serialized_snapshot #34 #35 #36 #37.
- Amit then described how a walsender restart could preserve candidate fields, advance restart_lsn on a subscriber acknowledgment, and subsequently move it backward while decoding older WAL; he initially suggested clearing the candidate fields on slot release #45.
- After Andres questioned whether the acknowledgment and overwrite were possible, Amit used the production logs to demonstrate the acknowledgment sequence and identified an independent if statement that should be else-if, matching LogicalIncreaseXminForSlot() #46 #47.
- Masahiko refined the explanation: restart_lsn retreated without recomputing the global retention minimum because catalog_xmin did not change, allowing the next checkpoint to recycle WAL that the slot still appeared to need #48.
- After a gap, Masahiko supplied a thirteen-step manual reproduction, timing instrumentation, and a patch clearing candidate fields in ReplicationSlotRelease(), reporting that the patch prevented the reproduced failure and clarifying that it required patching the publisher #50 #52.
- Alvaro Herrera questioned whether release should clear the candidate fields, prompting Masahiko to distinguish the workaround from the root cause and endorse the earlier else-if correction that prevents restart_lsn from retreating #53 #54.
- The reporter subsequently described logical walsenders consuming a full CPU and resisting cancellation after missing-WAL failures, but the supplied thread contains no diagnosis or fix for that additional symptom #55.
- The thread ended with Kyotaro and Andres discussing separate KeepLogSeg safeguards, retention-limit logging, rounding, and unnecessary slot invalidation, agreeing that further work belonged in another thread; no landing of the restart_lsn fix was announced in the supplied messages #56 #57.
- In November 2024, Masahiko committed the inline else-if solution with the necessary spinlock releases as e5ed873b1b, backpatched through PostgreSQL 13; the diagnostic attachments and candidate-clearing workaround were not included.