mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Add wal_sync_method=fdatasync for Windows.
Windows 10 gained support for flushing NTFS files with fdatasync() semantics. The main advantage over open_datasync (in Windows API terms FILE_FLAG_WRITE_THROUGH) is that the latter does not flush SATA drive caches. The default setting is not changed, so users have to opt in to this. Discussion: https://postgr.es/m/CA%2BhUKGJZJVO%3DiX%2Beb-PXi2_XS9ZRqnn_4URh0NUQOwt6-_51xQ%40mail.gmail.com
This commit is contained in:
53
src/port/fdatasync.c
Normal file
53
src/port/fdatasync.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* fdatasync.c
|
||||
* Win32 fdatasync() replacement
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/port/fdatasync.c
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define UMDF_USING_NTSTATUS
|
||||
|
||||
#ifdef FRONTEND
|
||||
#include "postgres_fe.h"
|
||||
#else
|
||||
#include "postgres.h"
|
||||
#endif
|
||||
|
||||
#include "port/win32ntdll.h"
|
||||
|
||||
int
|
||||
fdatasync(int fd)
|
||||
{
|
||||
IO_STATUS_BLOCK iosb;
|
||||
NTSTATUS status;
|
||||
HANDLE handle;
|
||||
|
||||
handle = (HANDLE) _get_osfhandle(fd);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (initialize_ntdll() < 0)
|
||||
return -1;
|
||||
|
||||
memset(&iosb, 0, sizeof(iosb));
|
||||
status = pg_NtFlushBuffersFileEx(handle,
|
||||
FLUSH_FLAGS_FILE_DATA_SYNC_ONLY,
|
||||
NULL,
|
||||
0,
|
||||
&iosb);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
return 0;
|
||||
|
||||
_dosmaperr(pg_RtlNtStatusToDosError(status));
|
||||
return -1;
|
||||
}
|
@@ -20,6 +20,8 @@
|
||||
#include "port/win32ntdll.h"
|
||||
|
||||
RtlGetLastNtStatus_t pg_RtlGetLastNtStatus;
|
||||
RtlNtStatusToDosError_t pg_RtlNtStatusToDosError;
|
||||
NtFlushBuffersFileEx_t pg_NtFlushBuffersFileEx;
|
||||
|
||||
typedef struct NtDllRoutine
|
||||
{
|
||||
@@ -28,7 +30,9 @@ typedef struct NtDllRoutine
|
||||
} NtDllRoutine;
|
||||
|
||||
static const NtDllRoutine routines[] = {
|
||||
{"RtlGetLastNtStatus", (pg_funcptr_t *) &pg_RtlGetLastNtStatus}
|
||||
{"RtlGetLastNtStatus", (pg_funcptr_t *) &pg_RtlGetLastNtStatus},
|
||||
{"RtlNtStatusToDosError", (pg_funcptr_t *) &pg_RtlNtStatusToDosError},
|
||||
{"NtFlushBuffersFileEx", (pg_funcptr_t *) &pg_NtFlushBuffersFileEx}
|
||||
};
|
||||
|
||||
static bool initialized;
|
||||
|
Reference in New Issue
Block a user