Replace O_EXCL with O_TRUNC for creation of state.tmp in SaveSlotToPath
Kevin K Biju <kevinkbiju@gmail.com>
From: Kevin K Biju <kevinkbiju@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-09-30T11:51:05Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Remove state.tmp when failing to save a replication slot
- c878d9808420 13.23 landed
- f57f2760e665 14.20 landed
- 0adf424b490b 15.15 landed
- bfdd1a12d2d9 16.11 landed
- 42348839d8b7 17.7 landed
- 9a6ea00ac8c0 18.1 landed
- 912af1c7e9c9 19 (unreleased) landed
Attachments
- replslot_state_tmp_otrunc.patch (application/octet-stream) patch
Hi, We have encountered a few instances where logical replication errors out during SaveSlotToPath() after creating the state.tmp file, but before it was renamed (due to ENOSPC, for example). In these cases, since state.tmp is not cleaned up and is created with the O_EXCL flag, further invocations of SaveSlotToPath() for this slot will error out on OpenTransientFile() with EEXIST, completely blocking slot metadata persistence. The only explicit cleanup for state.tmp occurs during server startup as part of RestoreSlotFromDisk(). It doesn't seem that this function relies on data written to state.tmp previously, so O_EXCL is unnecessary. Attaching a patch that swaps O_EXCL for O_TRUNC, ensuring a fresh state.tmp is available for writing. Thanks, Kevin