model-writtenrun 3959 - may be wrong, links go to the source messages. Commit-by-commit LLM analysis is in the Commits dialog.
- Andres Freund opened the thread after a buildfarm standby promoted successfully but pg_ctl reported a corrupt control file; Thomas Munro identified concurrent, uninterlocked reads and writes on ext4 as the likely cause #1 #4.
- Thomas considered advisory locks, retries and rename-based replacement, initially favoring retries for this rare failure; Tom Lane suggested stopping when two successive calculated checksums agree #5 #6.
- Thomas supplied a stress reproducer and a retry implementation with 10 ms sleeps and backend interrupt checks, demonstrating the failure through pg_control_system() #7.
- Anton A. Melnikov reproduced the problem with and without fsync, tested the retry fix, and questioned its potentially unbounded loop; Thomas then offered POSIX advisory locking as a more principled alternative #9 #10 #11.
- A performance concern about adding locking led to separate work applying wal_sync_method to control-file writes, with Anton reviewing the synchronization choices and identifying an incorrect error message #13 #14.
- Anton's Windows experiments eventually reproduced corruption even with fsync enabled, prompting Thomas to add Windows file locks and propose fdatasync as the default everywhere to avoid weakening control-file durability #15 #16.
- Windows mandatory locks interfered with ordinary readers, so Thomas moved the locked range beyond EOF, restricted filesystem locking to frontend/backend coordination, and added ControlFileLock protection for base backups; Anton tested the revised series successfully on Windows and Linux #17 #19 #20.
- The filesystem-locking design still imposed awkward requirements on external backup tools, and Thomas withdrew the mistaken suggestion that WAL already contained a safe control-file copy #19 #21.
- After several months, Thomas narrowed the proposal to backend locks for base backups and SQL functions, copying backup contents into memory before sending them, and moved WAL synchronization work to a separate thread #24.
- Stephen Frost objected to leaving external backup tools without protection and supported checksum validation with retries; Thomas retained the backend fixes, added backup documentation, and restored frontend retries with a ten-attempt limit #25 #27.
- Following discussion with Robert Haas and Andres Freund, Thomas replaced the documentation workaround with temporary-file replacement only while backups run, retaining backend locking because Windows rename behavior introduced additional hazards #29.
- David Steele found the series generally reasonable but raised standby performance and control-file padding concerns, while Anton urged landing the frontend fix first and proposed moving its retry logic to a higher level #30 #31 #32.
- Thomas proposed landing the frontend retries and SQL locks while deferring backup changes for a broader backup-label design; Michael Paquier supported the SQL fix, and David explicitly supported both selected components #33 #34 #35.
- David explored putting control-file information into backup_label, then concluded that the broader approach was unsuitable for backpatching, leaving the atomic-update proposal relevant to older releases despite performance concerns #36 #38 #39.
- The SQL-locking component of #29 landed unchanged as c558e6fd92, and its frontend-retry component landed with a rewritten explanatory comment as 63a582222c; the former was backpatched to all supported releases and the latter only as far as PostgreSQL 12.
- Thomas confirmed both landings and reposted the two unchanged backup patches as a rebased remainder while debate continued over the backup-label alternative #40.
- Robert Haas favored atomic replacement for protecting low-level backups but requested clearer comments, a better sendFileWithContent() interface, and refactoring of frontend/backend differences in update_controlfile(); David G. Johnston suggested a backup-metadata directory as another direction #41 #42.
- The backup remainder received no revision addressing that feedback, was marked Waiting on Author, and finally returned with feedback in February 2024, leaving the frontend and SQL fixes committed but backup protection unresolved #43 #44.