Default to wal_sync_method=fdatasync on FreeBSD.
authorThomas Munro <[email protected]>
Mon, 15 Feb 2021 02:43:39 +0000 (15:43 +1300)
committerThomas Munro <[email protected]>
Mon, 15 Feb 2021 03:09:14 +0000 (16:09 +1300)
FreeBSD 13 gained O_DSYNC, which would normally cause wal_sync_method to
choose open_datasync as its default value.  That may not be a good
choice for all systems, and performs worse than fdatasync in some
scenarios.  Let's preserve the existing default behavior for now.

Like commit 576477e73c4, which did the same for Linux, back-patch to all
supported releases.

Discussion: https://postgr.es/m/CA%2BhUKGLsAMXBQrCxCXoW-JsUYmdOL8ALYvaX%3DCrHqWxm-nWbGA%40mail.gmail.com

doc/src/sgml/config.sgml
src/backend/utils/misc/postgresql.conf.sample
src/include/port/freebsd.h

index b2dd54f5acb651b36d59a337b43d0db477150c36..25e6751590edfffcb37fa1eea09c9b092035608f 100644 (file)
@@ -2471,8 +2471,8 @@ include_dir 'conf.d'
         The <literal>open_</>* options also use <literal>O_DIRECT</> if available.
         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 <literal>fdatasync</> is the default on
-        Linux.  The default is not necessarily ideal; it might be
+        by the platform, except that <literal>fdatasync</literal> is the default on
+        Linux and FreeBSD.  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.
index 8650e77167297558344c991c77037441e5b82027..27e22835b21a042bb47a11ec3e5f1e5fc62ae480 100644 (file)
 #wal_sync_method = fsync       # the default is the first option
                    # supported by the operating system:
                    #   open_datasync
-                   #   fdatasync (default on Linux)
+                   #   fdatasync (default on Linux and FreeBSD)
                    #   fsync
                    #   fsync_writethrough
                    #   open_sync
index 2e36d3da4f4a83a45dd3431f6c764e3974db672a..2e2e749a6b65b9305fb480669299b6f75c28505d 100644 (file)
@@ -1 +1,10 @@
 /* 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.
+ */
+#ifdef HAVE_FDATASYNC
+#define PLATFORM_DEFAULT_SYNC_METHOD   SYNC_METHOD_FDATASYNC
+#endif