aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2019-10-04 13:08:51 -0700
committerAndres Freund <andres@anarazel.de>2019-10-04 13:34:28 -0700
commita586cc4b6c568e88a459f1a69ac82aa42af7e5ba (patch)
treeed78cfbb27bd71031d6c40b40636513147aff83c /src
parentad7595b890dbc26284bb0d784c2aaf1b9d6f903a (diff)
downloadpostgresql-a586cc4b6c568e88a459f1a69ac82aa42af7e5ba.tar.gz
postgresql-a586cc4b6c568e88a459f1a69ac82aa42af7e5ba.zip
Use a fd opened for read/write when syncing slots during startup, take 2.
Cribbing from dfbaed45975: 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 this fix was undone in 82a5649fb9db. Re-apply, and add a comment. Bug: 16039 Reported-By: Hans Buschmann Author: Andres Freund Discussion: https://postgr.es/m/16039-196fc97cc05e141c@postgresql.org Backpatch: 12-, as 82a5649fb9db
Diffstat (limited to 'src')
-rw-r--r--src/backend/replication/slot.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c
index b1bcd93345d..21ae8531b3c 100644
--- a/src/backend/replication/slot.c
+++ b/src/backend/replication/slot.c
@@ -1386,7 +1386,8 @@ RestoreSlotFromDisk(const char *name)
elog(DEBUG1, "restoring replication slot from \"%s\"", path);
- fd = OpenTransientFile(path, O_RDONLY | PG_BINARY);
+ /* on some operating systems fsyncing a file requires O_RDWR */
+ fd = OpenTransientFile(path, O_RDWR | PG_BINARY);
/*
* We do not need to handle this as we are rename()ing the directory into