aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/file/copydir.c8
-rw-r--r--src/backend/storage/file/fd.c14
2 files changed, 15 insertions, 7 deletions
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index dc89442041a..cf47708a797 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -98,7 +98,11 @@ copydir(char *fromdir, char *todir, bool recurse)
/*
* Be paranoid here and fsync all files to ensure the copy is really done.
+ * But if fsync is disabled, we're done.
*/
+ if (!enableFsync)
+ return;
+
xldir = AllocateDir(todir);
if (xldir == NULL)
ereport(ERROR,
@@ -200,9 +204,9 @@ copy_file(char *fromfile, char *tofile)
/*
* We fsync the files later but first flush them to avoid spamming the
* cache and hopefully get the kernel to start writing them out before
- * the fsync comes.
+ * the fsync comes. Ignore any error, since it's only a hint.
*/
- pg_flush_data(dstfd, offset, nbytes);
+ (void) pg_flush_data(dstfd, offset, nbytes);
}
if (close(dstfd))
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 9724f481dc0..1e54715056c 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -337,18 +337,22 @@ pg_fdatasync(int fd)
* pg_flush_data --- advise OS that the data described won't be needed soon
*
* Not all platforms have sync_file_range or posix_fadvise; treat as no-op
- * if not available.
+ * if not available. Also, treat as no-op if enableFsync is off; this is
+ * because the call isn't free, and some platforms such as Linux will actually
+ * block the requestor until the write is scheduled.
*/
int
pg_flush_data(int fd, off_t offset, off_t amount)
{
+ if (enableFsync)
+ {
#if defined(HAVE_SYNC_FILE_RANGE)
- return sync_file_range(fd, offset, amount, SYNC_FILE_RANGE_WRITE);
+ 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;
+ return posix_fadvise(fd, offset, amount, POSIX_FADV_DONTNEED);
#endif
+ }
+ return 0;
}