Skip to content

Commit 0c4b468

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 817d870 commit 0c4b468

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
@@ -376,10 +376,12 @@ SyncRepReleaseWaiters(void)
376376
/*
377377
* If this WALSender is serving a standby that is not on the list of
378378
* potential standbys then we have nothing to do. If we are still starting
379-
* up or still running base backup, then leave quickly also.
379+
* up, still running base backup or the current flush position is still
380+
* invalid, then leave quickly also.
380381
*/
381382
if (MyWalSnd->sync_standby_priority == 0 ||
382-
MyWalSnd->state < WALSNDSTATE_STREAMING)
383+
MyWalSnd->state < WALSNDSTATE_STREAMING ||
384+
XLogRecPtrIsInvalid(MyWalSnd->flush))
383385
return;
384386

385387
/*
@@ -399,7 +401,8 @@ SyncRepReleaseWaiters(void)
399401
walsnd->state == WALSNDSTATE_STREAMING &&
400402
walsnd->sync_standby_priority > 0 &&
401403
(priority == 0 ||
402-
priority > walsnd->sync_standby_priority))
404+
priority > walsnd->sync_standby_priority) &&
405+
!XLogRecPtrIsInvalid(walsnd->flush))
403406
{
404407
priority = walsnd->sync_standby_priority;
405408
syncWalSnd = walsnd;

src/backend/replication/walreceiver.c

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

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

src/backend/replication/walsender.c

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

15111511
if (walsnd->pid != 0)
15121512
{
1513-
sync_priority[i] = walsnd->sync_standby_priority;
1513+
/*
1514+
* Treat a standby such as a pg_basebackup background process
1515+
* which always returns an invalid flush location, as an
1516+
* asynchronous standby.
1517+
*/
1518+
sync_priority[i] = XLogRecPtrIsInvalid(walsnd->flush) ?
1519+
0 : walsnd->sync_standby_priority;
15141520

15151521
if (walsnd->state == WALSNDSTATE_STREAMING &&
15161522
walsnd->sync_standby_priority > 0 &&
15171523
(priority == 0 ||
1518-
priority > walsnd->sync_standby_priority))
1524+
priority > walsnd->sync_standby_priority) &&
1525+
!XLogRecPtrIsInvalid(walsnd->flush))
15191526
{
15201527
priority = walsnd->sync_standby_priority;
15211528
sync_standby = i;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy