From a06928b00c2a9dfa0863208196ead8c0eec87afe Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Thu, 9 Mar 2017 11:10:01 +0800
Subject: [PATCH 2/3] Start sendpos for logical walsender from restart_lsn

In logical streaming mode the walsender would initialize its internal
sentPos to the slot's confirmed_flush position, and the sentPos exposed
to shmem to the slot's restart_lsn. Subseqent updates to both would
use the last-decoded WAL record.

Since we overwrite the internal sentPos before using it, this is clearly an
oversight from an earlier iteration of the logical decoding patch set.
Initialize both to restart_lsn instead.
---
 src/backend/replication/walsender.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index dd3a936..ec5d9db 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -942,14 +942,14 @@ StartLogicalReplication(StartReplicationCmd *cmd)
 	 * Report the location after which we'll send out further commits as the
 	 * current sentPtr.
 	 */
-	sentPtr = MyReplicationSlot->data.confirmed_flush;
+	sentPtr = MyReplicationSlot->data.restart_lsn;
 
 	/* Also update the sent position status in shared memory */
 	{
 		WalSnd	   *walsnd = MyWalSnd;
 
 		SpinLockAcquire(&walsnd->mutex);
-		walsnd->sentPtr = MyReplicationSlot->data.restart_lsn;
+		walsnd->sentPtr = sentPtr;
 		SpinLockRelease(&walsnd->mutex);
 	}
 
-- 
2.5.5

