*** a/src/backend/replication/syncrep.c --- b/src/backend/replication/syncrep.c *************** *** 376,385 **** SyncRepReleaseWaiters(void) /* * If this WALSender is serving a standby that is not on the list of * potential standbys then we have nothing to do. If we are still starting ! * up or still running base backup, then leave quickly also. */ if (MyWalSnd->sync_standby_priority == 0 || ! MyWalSnd->state < WALSNDSTATE_STREAMING) return; /* --- 376,387 ---- /* * If this WALSender is serving a standby that is not on the list of * potential standbys then we have nothing to do. If we are still starting ! * up, still running base backup or the current flush position is still ! * invalid, then leave quickly also. */ if (MyWalSnd->sync_standby_priority == 0 || ! MyWalSnd->state < WALSNDSTATE_STREAMING || ! XLogRecPtrIsInvalid(MyWalSnd->flush)) return; /* *************** *** 399,405 **** SyncRepReleaseWaiters(void) walsnd->state == WALSNDSTATE_STREAMING && walsnd->sync_standby_priority > 0 && (priority == 0 || ! priority > walsnd->sync_standby_priority)) { priority = walsnd->sync_standby_priority; syncWalSnd = walsnd; --- 401,408 ---- walsnd->state == WALSNDSTATE_STREAMING && walsnd->sync_standby_priority > 0 && (priority == 0 || ! priority > walsnd->sync_standby_priority) && ! !XLogRecPtrIsInvalid(walsnd->flush)) { priority = walsnd->sync_standby_priority; syncWalSnd = walsnd; *** a/src/backend/replication/walreceiver.c --- b/src/backend/replication/walreceiver.c *************** *** 281,286 **** WalReceiverMain(void) --- 281,291 ---- walrcv_connect(conninfo, startpoint); DisableWalRcvImmediateExit(); + /* Initialize LogstreamResult, reply_message and feedback_message */ + LogstreamResult.Write = LogstreamResult.Flush = GetXLogReplayRecPtr(NULL); + MemSet(&reply_message, 0, sizeof(reply_message)); + MemSet(&feedback_message, 0, sizeof(feedback_message)); + /* Loop until end-of-streaming or error */ for (;;) { *** a/src/backend/replication/walsender.c --- b/src/backend/replication/walsender.c *************** *** 1510,1521 **** pg_stat_get_wal_senders(PG_FUNCTION_ARGS) if (walsnd->pid != 0) { ! sync_priority[i] = walsnd->sync_standby_priority; if (walsnd->state == WALSNDSTATE_STREAMING && walsnd->sync_standby_priority > 0 && (priority == 0 || ! priority > walsnd->sync_standby_priority)) { priority = walsnd->sync_standby_priority; sync_standby = i; --- 1510,1528 ---- if (walsnd->pid != 0) { ! /* ! * Treat the standby like pg_basebackup background process ! * which always returns an invalid flush location, as an ! * asynchronous standby. ! */ ! sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ? ! 0 : walsnd->sync_standby_priority; if (walsnd->state == WALSNDSTATE_STREAMING && walsnd->sync_standby_priority > 0 && (priority == 0 || ! priority > walsnd->sync_standby_priority) && ! !XLogRecPtrIsInvalid(walsnd->flush)) { priority = walsnd->sync_standby_priority; sync_standby = i; *** a/src/bin/pg_basebackup/receivelog.c --- b/src/bin/pg_basebackup/receivelog.c *************** *** 264,270 **** localTimestampDifferenceExceeds(TimestampTz start_time, * Note: The log position *must* be at a log segment start! */ bool ! ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysidentifier, char *basedir, stream_stop_callback stream_stop, int standby_message_timeout, bool rename_partial) { char query[128]; char current_walfile_name[MAXPGPATH]; --- 264,273 ---- * Note: The log position *must* be at a log segment start! */ bool ! ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, ! char *sysidentifier, char *basedir, ! stream_stop_callback stream_stop, ! int standby_message_timeout, bool rename_partial) { char query[128]; char current_walfile_name[MAXPGPATH]; *************** *** 359,365 **** ReceiveXlogStream(PGconn *conn, XLogRecPtr startpos, uint32 timeline, char *sysi char replybuf[sizeof(StandbyReplyMessage) + 1]; StandbyReplyMessage *replymsg = (StandbyReplyMessage *) (replybuf + 1); ! replymsg->write = InvalidXLogRecPtr; replymsg->flush = InvalidXLogRecPtr; replymsg->apply = InvalidXLogRecPtr; replymsg->sendTime = now; --- 362,368 ---- char replybuf[sizeof(StandbyReplyMessage) + 1]; StandbyReplyMessage *replymsg = (StandbyReplyMessage *) (replybuf + 1); ! replymsg->write = blockpos; replymsg->flush = InvalidXLogRecPtr; replymsg->apply = InvalidXLogRecPtr; replymsg->sendTime = now;