diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-13 17:16:58 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-07-13 17:16:58 -0400 |
commit | b966dd6c4228d696b291c1cdcb5ab8c8475fefa8 (patch) | |
tree | 327dfeb260b8d4523ceb6d793debe86af50d8df2 /src/backend/storage/file/fd.c | |
parent | 1a9405d26537c6d95269bf48f5ea80fbf7967260 (diff) | |
download | postgresql-b966dd6c4228d696b291c1cdcb5ab8c8475fefa8.tar.gz postgresql-b966dd6c4228d696b291c1cdcb5ab8c8475fefa8.zip |
Add fsync capability to initdb, and use sync_file_range() if available.
Historically we have not worried about fsync'ing anything during initdb
(in fact, initdb intentionally passes -F to each backend launch to prevent
it from fsync'ing). But with filesystems getting more aggressive about
caching data, that's not such a good plan anymore. Make initdb do a pass
over the finished data directory tree to fsync everything. For testing
purposes, the -N/--nosync flag can be used to restore the old behavior.
Also, testing shows that on Linux, sync_file_range() is much faster than
posix_fadvise() for hinting to the kernel that an fsync is coming,
apparently because the latter blocks on a rather small request queue while
the former doesn't. So use this function if available in initdb, and also
in the backend's pg_flush_data() (where it currently will affect only the
speed of CREATE DATABASE's cloning step).
We will later make pg_regress invoke initdb with the --nosync flag
to avoid slowing down cases such as "make check" in contrib. But
let's not do so until we've shaken out any portability issues in this
patch.
Jeff Davis, reviewed by Andres Freund
Diffstat (limited to 'src/backend/storage/file/fd.c')
-rw-r--r-- | src/backend/storage/file/fd.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index f79f4c6a36e..9724f481dc0 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -336,12 +336,15 @@ pg_fdatasync(int fd) /* * pg_flush_data --- advise OS that the data described won't be needed soon * - * Not all platforms have posix_fadvise; treat as noop if not available. + * Not all platforms have sync_file_range or posix_fadvise; treat as no-op + * if not available. */ int pg_flush_data(int fd, off_t offset, off_t amount) { -#if defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED) +#if defined(HAVE_SYNC_FILE_RANGE) + return sync_file_range(fd, offset, amount, SYNC_FILE_RANGE_WRITE); +#elif defined(USE_POSIX_FADVISE) && defined(POSIX_FADV_DONTNEED) return posix_fadvise(fd, offset, amount, POSIX_FADV_DONTNEED); #else return 0; |