diff options
author | Magnus Hagander <magnus@hagander.net> | 2012-07-04 15:10:46 +0200 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2012-07-04 15:14:42 +0200 |
commit | 0c4b468692804a232e324962d968e61c1837a13a (patch) | |
tree | 157d42fdd8ae3caf83abf87119c87121c1291902 /src | |
parent | 817d870cf990698cbc6672068e6af5405c2ae7a4 (diff) | |
download | postgresql-0c4b468692804a232e324962d968e61c1837a13a.tar.gz postgresql-0c4b468692804a232e324962d968e61c1837a13a.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/replication/syncrep.c | 9 | ||||
-rw-r--r-- | src/backend/replication/walreceiver.c | 5 | ||||
-rw-r--r-- | src/backend/replication/walsender.c | 11 |
3 files changed, 20 insertions, 5 deletions
diff --git a/src/backend/replication/syncrep.c b/src/backend/replication/syncrep.c index 0bb4145cb0c..a61725eed69 100644 --- a/src/backend/replication/syncrep.c +++ b/src/backend/replication/syncrep.c @@ -376,10 +376,12 @@ 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. + * 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) + MyWalSnd->state < WALSNDSTATE_STREAMING || + XLogRecPtrIsInvalid(MyWalSnd->flush)) return; /* @@ -399,7 +401,8 @@ SyncRepReleaseWaiters(void) walsnd->state == WALSNDSTATE_STREAMING && walsnd->sync_standby_priority > 0 && (priority == 0 || - priority > walsnd->sync_standby_priority)) + priority > walsnd->sync_standby_priority) && + !XLogRecPtrIsInvalid(walsnd->flush)) { priority = walsnd->sync_standby_priority; syncWalSnd = walsnd; diff --git a/src/backend/replication/walreceiver.c b/src/backend/replication/walreceiver.c index f3de9bdf466..eb96f6dd331 100644 --- a/src/backend/replication/walreceiver.c +++ b/src/backend/replication/walreceiver.c @@ -281,6 +281,11 @@ WalReceiverMain(void) 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 (;;) { diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 912ce9d4503..d007f5f6fa1 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1510,12 +1510,19 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS) if (walsnd->pid != 0) { - sync_priority[i] = walsnd->sync_standby_priority; + /* + * Treat a standby such as a 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)) + priority > walsnd->sync_standby_priority) && + !XLogRecPtrIsInvalid(walsnd->flush)) { priority = walsnd->sync_standby_priority; sync_standby = i; |