From 98a35ca025776528014703cffc0c6e2ba06ba453 Mon Sep 17 00:00:00 2001 From: Thomas Munro Date: Sat, 15 Jul 2023 11:41:52 +1200 Subject: [PATCH v2 1/2] Make wal_sync_method=fdatasync the default on all OSes. Previously, fdatasync was the default level on Linux and FreeBSD by special rules, and on OpenBSD and DragonflyBSD because they didn't have O_DSYNC != O_SYNC or O_DSYNC at all. For every other system, we'd choose open_datasync. Use fdatasync everywhere, for consistency. This became possible after commit 9430fb40 added support for Windows, the last known system not to have it. This means that we'll now flush caches on consumer drives by default on Windows, where previously we didn't, which seems like a better default for crash safety. Users who want the older behavior can still request it with wal_sync_method=open_datasync. It's entirely likely that we'll reintroduce per-platform choices in future, but this commit reverses our previous assumption that open_datasync is the best choice unless we hear otherwise. Reviewed-by: Anton A. Melnikov Discussion: https://postgr.es/m/CA%2BhUKG%2BF0EL4Up6yVYbbcWse4xKaqW4wc2xpw67Pq9FjmByWVg%40mail.gmail.com Discussion: https://postgr.es/m/20221123014224.xisi44byq3cf5psi%40awork3.anarazel.de --- doc/src/sgml/config.sgml | 5 ++--- src/backend/utils/misc/postgresql.conf.sample | 9 ++------- src/bin/pg_test_fsync/pg_test_fsync.c | 4 ++-- src/include/access/xlogdefs.h | 16 ++-------------- src/include/port/freebsd.h | 7 ------- src/include/port/linux.h | 8 -------- 6 files changed, 8 insertions(+), 41 deletions(-) diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index 43b1a132a2..9235caa0c0 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -3206,9 +3206,8 @@ include_dir 'conf.d' Not all of these choices are available on all platforms. - The default is the first method in the above list that is supported - by the platform, except that fdatasync is the default on - Linux and FreeBSD. The default is not necessarily ideal; it might be + The default is fdatasync. + The default is not necessarily ideal; it might be necessary to change this setting or other aspects of your system configuration in order to create a crash-safe configuration or achieve optimal performance. diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample index edcc0282b2..9b6765ceb5 100644 --- a/src/backend/utils/misc/postgresql.conf.sample +++ b/src/backend/utils/misc/postgresql.conf.sample @@ -224,13 +224,8 @@ # unrecoverable data corruption) #synchronous_commit = on # synchronization level; # off, local, remote_write, remote_apply, or on -#wal_sync_method = fsync # the default is the first option - # supported by the operating system: - # open_datasync - # fdatasync (default on Linux and FreeBSD) - # fsync - # fsync_writethrough - # open_sync +#wal_sync_method = fdatasync # fsync, fdatasync, fsync_writethrough, + # open_sync, open_datasync #full_page_writes = on # recover from partial page writes #wal_log_hints = off # also do full page writes of non-critical updates # (change requires restart) diff --git a/src/bin/pg_test_fsync/pg_test_fsync.c b/src/bin/pg_test_fsync/pg_test_fsync.c index 5c0da425fb..04dcd77152 100644 --- a/src/bin/pg_test_fsync/pg_test_fsync.c +++ b/src/bin/pg_test_fsync/pg_test_fsync.c @@ -298,7 +298,7 @@ test_sync(int writes_per_op) printf(_("\nCompare file sync methods using one %dkB write:\n"), XLOG_BLCKSZ_K); else printf(_("\nCompare file sync methods using two %dkB writes:\n"), XLOG_BLCKSZ_K); - printf(_("(in wal_sync_method preference order, except fdatasync is Linux's default)\n")); + printf(_("(fdatasync is the default)\n")); /* * Test open_datasync if available @@ -332,7 +332,7 @@ test_sync(int writes_per_op) #endif /* - * Test fdatasync if available + * Test fdatasync */ printf(LABEL_FORMAT, "fdatasync"); fflush(stdout); diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h index 3009798952..0c0dce91c7 100644 --- a/src/include/access/xlogdefs.h +++ b/src/include/access/xlogdefs.h @@ -64,19 +64,7 @@ typedef uint32 TimeLineID; */ typedef uint16 RepOriginId; -/* - * This chunk of hackery attempts to determine which file sync methods - * are available on the current platform, and to choose an appropriate - * default method. - * - * Note that we define our own O_DSYNC on Windows, but not O_SYNC. - */ -#if defined(PLATFORM_DEFAULT_WAL_SYNC_METHOD) -#define DEFAULT_WAL_SYNC_METHOD PLATFORM_DEFAULT_WAL_SYNC_METHOD -#elif defined(O_DSYNC) && (!defined(O_SYNC) || O_DSYNC != O_SYNC) -#define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_OPEN_DSYNC -#else -#define DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC -#endif +/* Default synchronization method for WAL. */ +#define DEFAULT_WAL_SYNC_METHOD SYNC_METHOD_FDATASYNC #endif /* XLOG_DEFS_H */ diff --git a/src/include/port/freebsd.h b/src/include/port/freebsd.h index c604187acd..2e36d3da4f 100644 --- a/src/include/port/freebsd.h +++ b/src/include/port/freebsd.h @@ -1,8 +1 @@ /* src/include/port/freebsd.h */ - -/* - * Set the default wal_sync_method to fdatasync. xlogdefs.h's normal rules - * would prefer open_datasync on FreeBSD 13+, but that is not a good choice on - * many systems. - */ -#define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC diff --git a/src/include/port/linux.h b/src/include/port/linux.h index 8101af2b93..acd867606c 100644 --- a/src/include/port/linux.h +++ b/src/include/port/linux.h @@ -12,11 +12,3 @@ * to have a kernel version test here. */ #define HAVE_LINUX_EIDRM_BUG - -/* - * Set the default wal_sync_method to fdatasync. With recent Linux versions, - * xlogdefs.h's normal rules will prefer open_datasync, which (a) doesn't - * perform better and (b) causes outright failures on ext4 data=journal - * filesystems, because those don't support O_DIRECT. - */ -#define PLATFORM_DEFAULT_WAL_SYNC_METHOD WAL_SYNC_METHOD_FDATASYNC -- 2.39.3 (Apple Git-145)