Re: race condition when writing pg_control
Noah Misch <noah@leadboat.com>
From: Noah Misch <noah@leadboat.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Andres Freund <andres@anarazel.de>, Tom Lane <tgl@sss.pgh.pa.us>, Nathan Bossart <nathandbossart@gmail.com>, Melanie Plageman <melanieplageman@gmail.com>, Michael Paquier <michael@paquier.xyz>, Fujii Masao <masao.fujii@oss.nttdata.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2024-07-12T11:43:22Z
Lists: pgsql-hackers
On Sat, May 18, 2024 at 05:29:12PM +1200, Thomas Munro wrote:
> On Fri, May 17, 2024 at 4:46 PM Thomas Munro <thomas.munro@gmail.com> wrote:
> > The specific problem here is that LocalProcessControlFile() runs in
> > every launched child for EXEC_BACKEND builds. Windows uses
> > EXEC_BACKEND, and Windows' NTFS file system is one of the two file
> > systems known to this list to have the concurrent read/write data
> > mashing problem (the other being ext4).
> First idea idea I've come up with to avoid all of that: pass a copy of
> the "proto-controlfile", to coin a term for the one read early in
> postmaster startup by LocalProcessControlFile(). As far as I know,
> the only reason we need it is to suck some settings out of it that
> don't change while a cluster is running (mostly can't change after
> initdb, and checksums can only be {en,dis}abled while down). Right?
> Children can just "import" that sucker instead of calling
> LocalProcessControlFile() to figure out the size of WAL segments yada
> yada, I think? Later they will attach to the real one in shared
> memory for all future purposes, once normal interlocking is allowed.
I like that strategy, particularly because it recreates what !EXEC_BACKEND
backends inherit from the postmaster. It might prevent future bugs that would
have been specific to EXEC_BACKEND.
> I dunno. Draft patch attached. Better plans welcome. This passes CI
> on Linux systems afflicted by EXEC_BACKEND, and Windows. Thoughts?
Looks reasonable. I didn't check over every detail, given the draft status.
Commits
-
Fix locking bugs that could corrupt pg_control.
- 09dc17486393 9.5.23 landed
- 644cac32a0bc 9.6.19 landed
- fd11b842eba9 10.14 landed
- 48eb6a3c895d 11.9 landed
- 72766ad6397a 12.4 landed
- acefa2cca6a2 13.0 landed
- 57cb8063089a 14.0 landed