*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 6803,6819 **** GetInsertRecPtr(void)
  }
  
  /*
!  * GetWriteRecPtr -- Returns the current write position.
   */
  XLogRecPtr
! GetWriteRecPtr(void)
  {
  	/* use volatile pointer to prevent code rearrangement */
  	volatile XLogCtlData *xlogctl = XLogCtl;
  	XLogRecPtr	recptr;
  
  	SpinLockAcquire(&xlogctl->info_lck);
! 	recptr = xlogctl->LogwrtResult.Write;
  	SpinLockRelease(&xlogctl->info_lck);
  
  	return recptr;
--- 6803,6819 ----
  }
  
  /*
!  * GetFlushRecPtr -- Returns the current flush position.
   */
  XLogRecPtr
! GetFlushRecPtr(void)
  {
  	/* use volatile pointer to prevent code rearrangement */
  	volatile XLogCtlData *xlogctl = XLogCtl;
  	XLogRecPtr	recptr;
  
  	SpinLockAcquire(&xlogctl->info_lck);
! 	recptr = xlogctl->LogwrtResult.Flush;
  	SpinLockRelease(&xlogctl->info_lck);
  
  	return recptr;
*** a/src/backend/replication/walsender.c
--- b/src/backend/replication/walsender.c
***************
*** 641,647 **** XLogRead(char *buf, XLogRecPtr recptr, Size nbytes)
  }
  
  /*
!  * Read up to MAX_SEND_SIZE bytes of WAL that's been written to disk,
   * but not yet sent to the client, and send it.
   *
   * msgbuf is a work area in which the output message is constructed.  It's
--- 641,647 ----
  }
  
  /*
!  * Read up to MAX_SEND_SIZE bytes of WAL that's been flushed to disk,
   * but not yet sent to the client, and send it.
   *
   * msgbuf is a work area in which the output message is constructed.  It's
***************
*** 663,673 **** XLogSend(char *msgbuf, bool *caughtup)
  	WalDataMessageHeader msghdr;
  
  	/*
! 	 * Attempt to send all data that's already been written out from WAL
! 	 * buffers (note it might not yet be fsync'd to disk).  We cannot go
! 	 * further than that given the current implementation of XLogRead().
  	 */
! 	SendRqstPtr = GetWriteRecPtr();
  
  	/* Quick exit if nothing to do */
  	if (XLByteLE(SendRqstPtr, sentPtr))
--- 663,673 ----
  	WalDataMessageHeader msghdr;
  
  	/*
! 	 * Attempt to send all data that's already been written out and
! 	 * fsync'd from WAL buffers.  We cannot go further than that given
! 	 * the current implementation of XLogRead().
  	 */
! 	SendRqstPtr = GetFlushRecPtr();
  
  	/* Quick exit if nothing to do */
  	if (XLByteLE(SendRqstPtr, sentPtr))
*** a/src/include/access/xlog.h
--- b/src/include/access/xlog.h
***************
*** 294,300 **** extern bool CreateRestartPoint(int flags);
  extern void XLogPutNextOid(Oid nextOid);
  extern XLogRecPtr GetRedoRecPtr(void);
  extern XLogRecPtr GetInsertRecPtr(void);
! extern XLogRecPtr GetWriteRecPtr(void);
  extern void GetNextXidAndEpoch(TransactionId *xid, uint32 *epoch);
  extern TimeLineID GetRecoveryTargetTLI(void);
  
--- 294,300 ----
  extern void XLogPutNextOid(Oid nextOid);
  extern XLogRecPtr GetRedoRecPtr(void);
  extern XLogRecPtr GetInsertRecPtr(void);
! extern XLogRecPtr GetFlushRecPtr(void);
  extern void GetNextXidAndEpoch(TransactionId *xid, uint32 *epoch);
  extern TimeLineID GetRecoveryTargetTLI(void);
  
