From 08b05ac2dea84aa0de4d018065d69009186d70be Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 17 Mar 2016 22:46:56 +0900 Subject: [PATCH 2/3] fsync properly files modified by pg_rewind Files updated by pg_rewind may have their changes lost in case of crashes if those are not flushed correctly to disk, making a potential PGDATA directory corrupted. --- src/bin/pg_rewind/file_ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_rewind/file_ops.c b/src/bin/pg_rewind/file_ops.c index 32eab3a..51cdf2b 100644 --- a/src/bin/pg_rewind/file_ops.c +++ b/src/bin/pg_rewind/file_ops.c @@ -74,12 +74,18 @@ close_target_file(void) if (dstfd == -1) return; + if (fsync(dstfd) != 0) + { + close(dstfd); + pg_fatal("could not fsync file \"%s\": %s\n", + dstpath, strerror(errno)); + } + if (close(dstfd) != 0) pg_fatal("could not close target file \"%s\": %s\n", dstpath, strerror(errno)); dstfd = -1; - /* fsync? */ } void -- 2.7.3