Remove wal_sync_method=fsync_writethrough on Windows.
authorThomas Munro <[email protected]>
Thu, 13 Jul 2023 23:59:07 +0000 (11:59 +1200)
committerThomas Munro <[email protected]>
Fri, 14 Jul 2023 00:30:13 +0000 (12:30 +1200)
The "fsync" level already flushes drive write caches on Windows (as does
"fdatasync"), so it only confuses matters to have an apparently higher
level that isn't actually different at all.

That leaves "fsync_writethrough" only for macOS, where it actually does
something different.

Reviewed-by: Magnus Hagander <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJ2CG2SouPv2mca2WCTOJxYumvBARRcKPraFMB6GSEMcA%40mail.gmail.com

doc/src/sgml/wal.sgml
src/backend/storage/file/fd.c
src/bin/pg_test_fsync/pg_test_fsync.c
src/include/port/win32_port.h

index ed7929cbcd72c4d2375c8e59d0f85aebafc09c66..4aad0e1a075e2b65ad1af7360dccfc6106f92dc0 100644 (file)
         <literal>open_datasync</literal> (the default), write caching can be disabled
         by unchecking <literal>My Computer\Open\<replaceable>disk drive</replaceable>\Properties\Hardware\Properties\Policies\Enable write caching on the disk</literal>.
         Alternatively, set <varname>wal_sync_method</varname> to
-        <literal>fdatasync</literal> (NTFS only), <literal>fsync</literal> or
-        <literal>fsync_writethrough</literal>, which prevent
-        write caching.
+        <literal>fdatasync</literal> (NTFS only) or <literal>fsync</literal>,
+        which prevent write caching.
       </para>
     </listitem>
 
index 3c2a2fbef73183f609b23421846545e2c07fa796..a027a8aabc22da4a8a85abbfecbc8cfb2474af21 100644 (file)
@@ -399,7 +399,7 @@ pg_fsync(int fd)
 #endif
 
    /* #if is to skip the sync_method test if there's no need for it */
-#if defined(HAVE_FSYNC_WRITETHROUGH) && !defined(FSYNC_WRITETHROUGH_IS_FSYNC)
+#if defined(HAVE_FSYNC_WRITETHROUGH)
    if (sync_method == SYNC_METHOD_FSYNC_WRITETHROUGH)
        return pg_fsync_writethrough(fd);
    else
@@ -437,9 +437,7 @@ pg_fsync_writethrough(int fd)
 {
    if (enableFsync)
    {
-#ifdef WIN32
-       return _commit(fd);
-#elif defined(F_FULLFSYNC)
+#if defined(F_FULLFSYNC)
        return (fcntl(fd, F_FULLFSYNC, 0) == -1) ? -1 : 0;
 #else
        errno = ENOSYS;
index 435df8d808de752e65540f5afb360986dda6781e..14fa4acae26107e5998333be3297016b68ca0097 100644 (file)
@@ -605,9 +605,7 @@ signal_cleanup(SIGNAL_ARGS)
 static int
 pg_fsync_writethrough(int fd)
 {
-#ifdef WIN32
-   return _commit(fd);
-#elif defined(F_FULLFSYNC)
+#if defined(F_FULLFSYNC)
    return (fcntl(fd, F_FULLFSYNC, 0) == -1) ? -1 : 0;
 #else
    errno = ENOSYS;
index 0e6d60833083ccceeab989bafc5b98c46c77bae8..27a11c7868ed714304f3231b74ce8d681457711a 100644 (file)
 /* Windows doesn't have fsync() as such, use _commit() */
 #define fsync(fd) _commit(fd)
 
-/*
- * For historical reasons, we allow setting wal_sync_method to
- * fsync_writethrough on Windows, even though it's really identical to fsync
- * (both code paths wind up at _commit()).
- */
-#define HAVE_FSYNC_WRITETHROUGH
-#define FSYNC_WRITETHROUGH_IS_FSYNC
-
 #define USES_WINSOCK
 
 /*