pgsql: Use a fd opened for read/write when syncing slots during startup

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Use a fd opened for read/write when syncing slots during startup
Date: 2015-04-27 22:22:33
Message-ID: E1YmrQ9-0007YZ-W7@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(dot)2556(dot)60897(at)wrigleys(dot)postgresql(dot)org

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/dfbaed459754e71e01bb0cc90a12802bba3f9786

Modified Files
--------------
src/backend/replication/slot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2015-04-27 22:22:36 pgsql: Use a fd opened for read/write when syncing slots during startup
Previous Message Alvaro Herrera 2015-04-27 17:27:12 Re: pgsql: Add transforms feature