From d0c28601efaa8b04f11a19506f3371bba8438acc Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Fri, 14 Jul 2023 11:59:07 +1200 Subject: [PATCH] Remove wal_sync_method=fsync_writethrough on Windows. 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 Discussion: https://postgr.es/m/CA%2BhUKGJ2CG2SouPv2mca2WCTOJxYumvBARRcKPraFMB6GSEMcA%40mail.gmail.com --- doc/src/sgml/wal.sgml | 5 ++--- src/backend/storage/file/fd.c | 6 ++---- src/bin/pg_test_fsync/pg_test_fsync.c | 4 +--- src/include/port/win32_port.h | 8 -------- 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/doc/src/sgml/wal.sgml b/doc/src/sgml/wal.sgml index ed7929cbcd..4aad0e1a07 100644 --- a/doc/src/sgml/wal.sgml +++ b/doc/src/sgml/wal.sgml @@ -109,9 +109,8 @@ open_datasync (the default), write caching can be disabled by unchecking My Computer\Open\disk drive\Properties\Hardware\Properties\Policies\Enable write caching on the disk. Alternatively, set wal_sync_method to - fdatasync (NTFS only), fsync or - fsync_writethrough, which prevent - write caching. + fdatasync (NTFS only) or fsync, + which prevent write caching. diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 3c2a2fbef7..a027a8aabc 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -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; diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 435df8d808..14fa4acae2 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -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; diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h index 0e6d608330..27a11c7868 100644 --- a/src/include/port/win32_port.h +++ b/src/include/port/win32_port.h @@ -84,14 +84,6 @@ /* 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 /*