Use a fd opened for read/write when syncing slots during startup.
authorAndres Freund <[email protected]>
Mon, 27 Apr 2015 22:12:38 +0000 (00:12 +0200)
committerAndres Freund <[email protected]>
Mon, 27 Apr 2015 22:17:43 +0000 (00:17 +0200)
commitdfbaed459754e71e01bb0cc90a12802bba3f9786
treee321306e7c21bcc290fb03c989a0fed634d4ef85
parentdcbf5948e12aa60b4d6ab65b6445897dfc971e01
Use a fd opened for read/write when syncing slots during startup.

Some operating systems, including the reporter's windows, return EBADFD
or similar when fsync() is invoked on a O_RDONLY file descriptor.
Unfortunately RestoreSlotFromDisk() does exactly that; which causes
failures after restarts in at least some scenarios.

If you hit the bug the error message will be something like
ERROR: could not fsync file "pg_replslot/$name/state": Bad file descriptor

Simply use O_RDWR instead of O_RDONLY when opening the relevant file
descriptor to fix the bug.  Unfortunately I have no way of verifying the
fix, but we've seen similar problems in the past.

This bug goes back to 9.4 where slots were introduced. Backpatch
accordingly.

Reported-By: Patrice Drolet
Bug: #13143:
Discussion: 20150424101006[email protected]
src/backend/replication/slot.c