diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index 3e02dce..b6eebb8 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -406,6 +406,16 @@ pg_flush_data(int fd, off_t offset, off_t nbytes)
 	if (!enableFsync)
 		return;
 
+	/* Flush whole file. */
+	if ((offset == 0) && (nbytes == 0))
+	{
+		if (pg_fdatasync(fd) != 0)
+			ereport(WARNING,
+					(errcode_for_file_access(),
+					 errmsg("could not flush dirty data: %m")));
+		return;
+	}
+
 	/*
 	 * XXX: compile all alternatives, to find portability problems more easily
 	 */
