Flush logical mapping files with fd opened for read/write at checkpoint
authorMichael Paquier <[email protected]>
Wed, 9 Oct 2019 04:31:38 +0000 (13:31 +0900)
committerMichael Paquier <[email protected]>
Wed, 9 Oct 2019 04:31:38 +0000 (13:31 +0900)
The file descriptor was opened with read-only to fsync a regular file,
which would cause EBADFD errors on some platforms.

This is similar to the recent fix done by a586cc4b (which was broken by
me with 82a5649), except that I noticed this issue while monitoring the
backend code for similar mistakes.  Backpatch to 9.4, as this has been
introduced since logical decoding exists as of b89e151.

Author: Michael Paquier
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20191006045548[email protected]
Backpatch-through: 9.4

src/backend/access/heap/rewriteheap.c

index f70b2f320555d70bab8590f6d4ef0603578cd86d..b72dff8e4e7098cdf7177d6bf959a10f10007934 100644 (file)
@@ -1280,7 +1280,8 @@ CheckPointLogicalRewriteHeap(void)
        }
        else
        {
-           int         fd = OpenTransientFile(path, O_RDONLY | PG_BINARY, 0);
+           /* on some operating systems fsyncing a file requires O_RDWR */
+           int         fd = OpenTransientFile(path, O_RDWR | PG_BINARY, 0);
 
            /*
             * The file cannot vanish due to concurrency since this function