aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/pg_basebackup/receivelog.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.c
index e51cac9b87b..1b8a5ad15ce 100644
--- a/src/bin/pg_basebackup/receivelog.c
+++ b/src/bin/pg_basebackup/receivelog.c
@@ -1020,6 +1020,25 @@ ProcessKeepaliveMsg(PGconn *conn, char *copybuf, int len,
/* If the server requested an immediate reply, send one. */
if (replyRequested && still_sending)
{
+ if (reportFlushPosition && lastFlushPosition < blockpos &&
+ walfile != 1)
+ {
+ /*
+ * If a valid flush location needs to be reported,
+ * flush the current WAL file so that the latest flush
+ * location is sent back to the server. This is necessary to
+ * see whether the last WAL data has been successfully
+ * replicated or not, at the normal shutdown of the server.
+ */
+ if (fsync(walfile) != 0)
+ {
+ fprintf(stderr, _("%s: could not fsync file \"%s\": %s\n"),
+ progname, current_walfile_name, strerror(errno));
+ return false;
+ }
+ lastFlushPosition = blockpos;
+ }
+
now = feGetCurrentTimestamp();
if (!sendFeedback(conn, blockpos, now, false))
return false;