Skip to content

Commit 8c8adf4

Browse files
committed
Always treat a standby returning an an invalid flush location as async
This ensures that a standby such as pg_receivexlog will not be selected as sync standby - which would cause the master to block waiting for a location that could never happen. Fujii Masao
1 parent 5c5d548 commit 8c8adf4

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/backend/replication/syncrep.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,12 @@ SyncRepReleaseWaiters(void)
377377
/*
378378
* If this WALSender is serving a standby that is not on the list of
379379
* potential standbys then we have nothing to do. If we are still starting
380-
* up or still running base backup, then leave quickly also.
380+
* up, still running base backup or the current flush position is still
381+
* invalid, then leave quickly also.
381382
*/
382383
if (MyWalSnd->sync_standby_priority == 0 ||
383-
MyWalSnd->state < WALSNDSTATE_STREAMING)
384+
MyWalSnd->state < WALSNDSTATE_STREAMING ||
385+
XLogRecPtrIsInvalid(MyWalSnd->flush))
384386
return;
385387

386388
/*
@@ -400,7 +402,8 @@ SyncRepReleaseWaiters(void)
400402
walsnd->state == WALSNDSTATE_STREAMING &&
401403
walsnd->sync_standby_priority > 0 &&
402404
(priority == 0 ||
403-
priority > walsnd->sync_standby_priority))
405+
priority > walsnd->sync_standby_priority) &&
406+
!XLogRecPtrIsInvalid(walsnd->flush))
404407
{
405408
priority = walsnd->sync_standby_priority;
406409
syncWalSnd = walsnd;

src/backend/replication/walreceiver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ WalReceiverMain(void)
280280
walrcv_connect(conninfo, startpoint);
281281
DisableWalRcvImmediateExit();
282282

283+
/* Initialize LogstreamResult, reply_message and feedback_message */
284+
LogstreamResult.Write = LogstreamResult.Flush = GetXLogReplayRecPtr(NULL);
285+
MemSet(&reply_message, 0, sizeof(reply_message));
286+
MemSet(&feedback_message, 0, sizeof(feedback_message));
287+
283288
/* Loop until end-of-streaming or error */
284289
for (;;)
285290
{

src/backend/replication/walsender.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,12 +1530,19 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
15301530

15311531
if (walsnd->pid != 0)
15321532
{
1533-
sync_priority[i] = walsnd->sync_standby_priority;
1533+
/*
1534+
* Treat a standby such as a pg_basebackup background process
1535+
* which always returns an invalid flush location, as an
1536+
* asynchronous standby.
1537+
*/
1538+
sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ?
1539+
0 : walsnd->sync_standby_priority;
15341540

15351541
if (walsnd->state == WALSNDSTATE_STREAMING &&
15361542
walsnd->sync_standby_priority > 0 &&
15371543
(priority == 0 ||
1538-
priority > walsnd->sync_standby_priority))
1544+
priority > walsnd->sync_standby_priority) &&
1545+
!XLogRecPtrIsInvalid(walsnd->flush))
15391546
{
15401547
priority = walsnd->sync_standby_priority;
15411548
sync_standby = i;

0 commit comments

Comments
 (0)