From fbf61c6536b7060e5c6745c8221a5a4fb9a53c92 Mon Sep 17 00:00:00 2001
From: Marti Raudsepp <marti@juffo.org>
Date: Fri, 5 Nov 2010 17:40:22 +0200
Subject: [PATCH] Revert default wal_sync_method to fdatasync on Linux 2.6.33+

Linux kernel headers from 2.6.33 (and later) change the behavior of the
O_SYNC flag. Previously O_SYNC was aliased to O_DSYNC, which caused
PostgreSQL to use fdatasync as the default instead.

Starting with kernels 2.6.33 and later, the definitions of O_DSYNC and
O_SYNC differ. When built with headers from these newer kernels,
PostgreSQL will default to using open_datasync. This patch reverts the
Linux default to fdatasync, which has had much more testing over time
and also significantly better performance.
---
 src/include/access/xlogdefs.h |    5 +++++
 src/include/port/linux.h      |    9 +++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/include/access/xlogdefs.h b/src/include/access/xlogdefs.h
index 18b214e..7ed1bde 100644
--- a/src/include/access/xlogdefs.h
+++ b/src/include/access/xlogdefs.h
@@ -13,6 +13,7 @@
 #define XLOG_DEFS_H
 
 #include <fcntl.h>				/* need open() flags */
+#include "pg_config_os.h"
 
 /*
  * Pointer to a location in the XLOG.  These pointers are 64 bits wide,
@@ -123,6 +124,9 @@ typedef uint32 TimeLineID;
 #endif
 #endif
 
+#if defined(PLATFORM_DEFAULT_SYNC_METHOD)
+#define DEFAULT_SYNC_METHOD PLATFORM_DEFAULT_SYNC_METHOD
+#else							/* !defined(PLATFORM_DEFAULT_SYNC_METHOD) */
 #if defined(OPEN_DATASYNC_FLAG)
 #define DEFAULT_SYNC_METHOD		SYNC_METHOD_OPEN_DSYNC
 #elif defined(HAVE_FDATASYNC)
@@ -132,6 +136,7 @@ typedef uint32 TimeLineID;
 #else
 #define DEFAULT_SYNC_METHOD		SYNC_METHOD_FSYNC
 #endif
+#endif
 
 /*
  * Limitation of buffer-alignment for direct IO depends on OS and filesystem,
diff --git a/src/include/port/linux.h b/src/include/port/linux.h
index b9498b2..5a88590 100644
--- a/src/include/port/linux.h
+++ b/src/include/port/linux.h
@@ -12,3 +12,12 @@
  * to have a kernel version test here.
  */
 #define HAVE_LINUX_EIDRM_BUG
+
+/*
+ * The definition of O_SYNC changed in Linux kernel headers starting with
+ * 2.6.33.  This caused PostgreSQL to change the wal_sync_method default from
+ * fdatasync to open_datasync.  Since fdatasync is more tested on Linux and has
+ * better performance, default to fdatasync on Linux.
+ */
+#define PLATFORM_DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
+
-- 
1.7.3.2

