*** a/doc/src/sgml/func.sgml
--- b/doc/src/sgml/func.sgml
***************
*** 14131,14140 **** postgres=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup());
         <entry><type>text</type></entry>
         <entry>Get last transaction log location received and synced to disk by
          streaming replication. While streaming replication is in progress
!         this will increase monotonically. But when streaming replication is
!         restarted this will back off to the replication starting position,
!         typically the beginning of the WAL file containing the current
!         replay location.  If recovery has completed this will remain static at
          the value of the last WAL record received and synced to disk during
          recovery. If streaming replication is disabled, or if it has not yet
          started, the function returns NULL.
--- 14131,14138 ----
         <entry><type>text</type></entry>
         <entry>Get last transaction log location received and synced to disk by
          streaming replication. While streaming replication is in progress
!         this will increase monotonically. If recovery has completed this will
!         remain static at
          the value of the last WAL record received and synced to disk during
          recovery. If streaming replication is disabled, or if it has not yet
          started, the function returns NULL.
*** a/src/backend/replication/walreceiver.c
--- b/src/backend/replication/walreceiver.c
***************
*** 12,18 ****
   * in the primary server), and then keeps receiving XLOG records and
   * writing them to the disk as long as the connection is alive. As XLOG
   * records are received and flushed to disk, it updates the
!  * WalRcv->receivedUpTo variable in shared memory, to inform the startup
   * process of how far it can proceed with XLOG replay.
   *
   * Normal termination is by SIGTERM, which instructs the walreceiver to
--- 12,18 ----
   * in the primary server), and then keeps receiving XLOG records and
   * writing them to the disk as long as the connection is alive. As XLOG
   * records are received and flushed to disk, it updates the
!  * WalRcv->receivedUpto variable in shared memory, to inform the startup
   * process of how far it can proceed with XLOG replay.
   *
   * Normal termination is by SIGTERM, which instructs the walreceiver to
***************
*** 207,213 **** WalReceiverMain(void)
  
  	/* Fetch information required to start streaming */
  	strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
! 	startpoint = walrcv->receivedUpto;
  	SpinLockRelease(&walrcv->mutex);
  
  	/* Arrange to clean up at walreceiver exit */
--- 207,213 ----
  
  	/* Fetch information required to start streaming */
  	strlcpy(conninfo, (char *) walrcv->conninfo, MAXCONNINFO);
! 	startpoint = walrcv->receiveStart;
  	SpinLockRelease(&walrcv->mutex);
  
  	/* Arrange to clean up at walreceiver exit */
***************
*** 526,533 **** XLogWalRcvFlush(void)
  
  		/* Update shared-memory status */
  		SpinLockAcquire(&walrcv->mutex);
! 		walrcv->latestChunkStart = walrcv->receivedUpto;
! 		walrcv->receivedUpto = LogstreamResult.Flush;
  		SpinLockRelease(&walrcv->mutex);
  
  		/* Signal the startup process that new WAL has arrived */
--- 526,536 ----
  
  		/* Update shared-memory status */
  		SpinLockAcquire(&walrcv->mutex);
! 		if (XLByteLT(walrcv->receivedUpto, LogstreamResult.Flush))
! 		{
! 			walrcv->latestChunkStart = walrcv->receivedUpto;
! 			walrcv->receivedUpto = LogstreamResult.Flush;
! 		}
  		SpinLockRelease(&walrcv->mutex);
  
  		/* Signal the startup process that new WAL has arrived */
*** a/src/backend/replication/walreceiverfuncs.c
--- b/src/backend/replication/walreceiverfuncs.c
***************
*** 199,206 **** RequestXLogStreaming(XLogRecPtr recptr, const char *conninfo)
  	walrcv->walRcvState = WALRCV_STARTING;
  	walrcv->startTime = now;
  
! 	walrcv->receivedUpto = recptr;
! 	walrcv->latestChunkStart = recptr;
  
  	SpinLockRelease(&walrcv->mutex);
  
--- 199,215 ----
  	walrcv->walRcvState = WALRCV_STARTING;
  	walrcv->startTime = now;
  
! 	/*
! 	 * If this is the first startup of walreceiver, we initialize
! 	 * receivedUpto and latestChunkStart to receiveStart.
! 	 */
! 	if (walrcv->receiveStart.xlogid == 0 &&
! 		walrcv->receiveStart.xrecoff == 0)
! 	{
! 		walrcv->receivedUpto = recptr;
! 		walrcv->latestChunkStart = recptr;
! 	}
! 	walrcv->receiveStart = recptr;
  
  	SpinLockRelease(&walrcv->mutex);
  
*** a/src/include/replication/walreceiver.h
--- b/src/include/replication/walreceiver.h
***************
*** 50,60 **** typedef struct
  	pg_time_t	startTime;
  
  	/*
  	 * receivedUpto-1 is the last byte position that has already been
! 	 * received.  When startup process starts the walreceiver, it sets
! 	 * receivedUpto to the point where it wants the streaming to begin. After
! 	 * that, walreceiver updates this whenever it flushes the received WAL to
! 	 * disk.
  	 */
  	XLogRecPtr	receivedUpto;
  
--- 50,66 ----
  	pg_time_t	startTime;
  
  	/*
+ 	 * receiveStart is the first byte position that will be received.
+ 	 * When startup process starts the walreceiver, it sets receiveStart
+ 	 * to the point where it wants the streaming to begin.
+ 	 */
+ 	XLogRecPtr	receiveStart;
+ 
+ 	/*
  	 * receivedUpto-1 is the last byte position that has already been
! 	 * received.  At the first startup of walreceiver, receivedUpto is
! 	 * set to receiveStart. After that, walreceiver updates this whenever
! 	 * it flushes the received WAL to disk.
  	 */
  	XLogRecPtr	receivedUpto;
  
