Skip to content

Commit b1f57d8

Browse files
committed
Change Win32 O_SYNC method to O_DSYNC because that is what the method
currently does. This is now the default Win32 wal sync method because we perfer o_datasync to fsync. Also, change Win32 fsync to a new wal sync method called fsync_writethrough because that is the behavior of _commit, which is what is used for fsync on Win32. Backpatch to 8.0.X.
1 parent 0275b3f commit b1f57d8

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

doc/src/sgml/runtime.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.310 2005/03/19 23:27:04 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/runtime.sgml,v 1.311 2005/03/24 04:36:17 momjian Exp $
33
-->
44

55
<chapter Id="runtime">
@@ -1587,6 +1587,7 @@ SET ENABLE_SEQSCAN TO OFF;
15871587
values are
15881588
<literal>fsync</> (call <function>fsync()</> at each commit),
15891589
<literal>fdatasync</> (call <function>fdatasync()</> at each commit),
1590+
<literal>fsync_writethrough</> (call <function>_commit()</> at each commit on Windows),
15901591
<literal>open_sync</> (write WAL files with <function>open()</> option <symbol>O_SYNC</>), and
15911592
<literal>open_datasync</> (write WAL files with <function>open()</> option <symbol>O_DSYNC</>).
15921593
Not all of these choices are available on all platforms.

src/backend/access/transam/xlog.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.181 2005/02/12 23:53:37 momjian Exp $
10+
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.182 2005/03/24 04:36:17 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -63,8 +63,13 @@
6363
#endif
6464
#endif
6565

66+
#if defined(O_DSYNC)
6667
#if defined(OPEN_SYNC_FLAG)
67-
#if defined(O_DSYNC) && (O_DSYNC != OPEN_SYNC_FLAG)
68+
#if O_DSYNC != OPEN_SYNC_FLAG
69+
#define OPEN_DATASYNC_FLAG O_DSYNC
70+
#endif
71+
#else /* !defined(OPEN_SYNC_FLAG) */
72+
/* Win32 only has O_DSYNC */
6873
#define OPEN_DATASYNC_FLAG O_DSYNC
6974
#endif
7075
#endif
@@ -79,7 +84,11 @@
7984
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FDATASYNC
8085
#define DEFAULT_SYNC_FLAGBIT 0
8186
#else
87+
#ifndef FSYNC_IS_WRITE_THROUGH
8288
#define DEFAULT_SYNC_METHOD_STR "fsync"
89+
#else
90+
#define DEFAULT_SYNC_METHOD_STR "fsync_writethrough"
91+
#endif
8392
#define DEFAULT_SYNC_METHOD SYNC_METHOD_FSYNC
8493
#define DEFAULT_SYNC_FLAGBIT 0
8594
#endif
@@ -5154,7 +5163,12 @@ assign_xlog_sync_method(const char *method, bool doit, GucSource source)
51545163
int new_sync_method;
51555164
int new_sync_bit;
51565165

5166+
#ifndef FSYNC_IS_WRITE_THROUGH
51575167
if (pg_strcasecmp(method, "fsync") == 0)
5168+
#else
5169+
/* Win32 fsync() == _commit(0, which writes through a write cache */
5170+
if (pg_strcasecmp(method, "fsync_writethrough") == 0)
5171+
#endif
51585172
{
51595173
new_sync_method = SYNC_METHOD_FSYNC;
51605174
new_sync_bit = 0;

src/backend/utils/misc/postgresql.conf.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114

115115
#fsync = true # turns forced synchronization on or off
116116
#wal_sync_method = fsync # the default varies across platforms:
117-
# fsync, fdatasync, open_sync, or open_datasync
117+
# fsync, fdatasync, fsync_writethrough,
118+
# open_sync, open_datasync
118119
#wal_buffers = 8 # min 4, 8KB each
119120
#commit_delay = 0 # range 0-100000, in microseconds
120121
#commit_siblings = 5 # range 1-1000

src/include/port/win32.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.43 2005/02/27 00:53:29 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.44 2005/03/24 04:36:19 momjian Exp $ */
22

33
/* undefine and redefine after #include */
44
#undef mkdir
@@ -17,6 +17,7 @@
1717

1818

1919
#define fsync(a) _commit(a)
20+
#define FSYNC_IS_WRITE_THROUGH
2021
#define ftruncate(a,b) chsize(a,b)
2122

2223
#define USES_WINSOCK
@@ -189,7 +190,7 @@ typedef int pid_t;
189190
* to ensure that we don't collide with a future definition. It means
190191
* we cannot use _O_NOINHERIT ourselves.
191192
*/
192-
#define O_SYNC 0x0080
193+
#define O_DSYNC 0x0080
193194

194195
/*
195196
* Supplement to <errno.h>.

src/port/open.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
*
9-
* $PostgreSQL: pgsql/src/port/open.c,v 1.8 2005/02/27 00:53:29 momjian Exp $
9+
* $PostgreSQL: pgsql/src/port/open.c,v 1.9 2005/03/24 04:36:20 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -63,7 +63,7 @@ win32_open(const char *fileName, int fileFlags,...)
6363
/* Check that we can handle the request */
6464
assert((fileFlags & ((O_RDONLY | O_WRONLY | O_RDWR) | O_APPEND |
6565
(O_RANDOM | O_SEQUENTIAL | O_TEMPORARY) |
66-
_O_SHORT_LIVED | O_SYNC |
66+
_O_SHORT_LIVED | O_DSYNC |
6767
(O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags);
6868

6969
sa.nLength = sizeof(sa);
@@ -83,7 +83,7 @@ win32_open(const char *fileName, int fileFlags,...)
8383
((fileFlags & O_SEQUENTIAL) ? FILE_FLAG_SEQUENTIAL_SCAN : 0) |
8484
((fileFlags & _O_SHORT_LIVED) ? FILE_ATTRIBUTE_TEMPORARY : 0) |
8585
((fileFlags & O_TEMPORARY) ? FILE_FLAG_DELETE_ON_CLOSE : 0)|
86-
((fileFlags & O_SYNC) ? FILE_FLAG_WRITE_THROUGH : 0),
86+
((fileFlags & O_DSYNC) ? FILE_FLAG_WRITE_THROUGH : 0),
8787
NULL)) == INVALID_HANDLE_VALUE)
8888
{
8989
switch (GetLastError())

0 commit comments

Comments
 (0)