postgres.git / summary / log / commit / refs

commit    65e8dbb1869db542c93333fc809f34c7d3f7d9bd
Author:   Fujii Masao <fujii@postgresql.org>
Date:     Mon Mar 17 11:42:35 2014 +0000
First released in: 9.4.0, 9.1.13, 9.2.8, 9.3.4

    Fix bug in clean shutdown of walsender that pg_receiving is connecting to.
    
    On clean shutdown, walsender waits for all WAL to be replicated to a standby,
    and exits. It determined whether that replication had been completed by
    checking whether its sent location had been equal to a standby's flush
    location. Unfortunately this condition never becomes true when the standby
    such as pg_receivexlog which always returns an invalid flush location is
    connecting to walsender, and then walsender waits forever.
    
    This commit changes walsender so that it just checks a standby's write
    location if a flush location is invalid.
    
    Back-patch to 9.1 where enough infrastructure for this exists.


src/backend/replication/walsender.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index 7b44f9b0443..b6bf6333378 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -775,9 +775,20 @@ WalSndLoop(void) */ if (walsender_ready_to_stop) { + XLogRecPtr replicatedPtr; + /* ... let's just be real sure we're caught up ... */ XLogSend(output_message, &caughtup); - if (caughtup && XLByteEQ(sentPtr, MyWalSnd->flush) && + + /* + * Check a write location to see whether all the WAL have + * successfully been replicated if this walsender is connecting + * to a standby such as pg_receivexlog which always returns + * an invalid flush location. Otherwise, check a flush location. + */ + replicatedPtr = XLogRecPtrIsInvalid(MyWalSnd->flush) ? + MyWalSnd->write : MyWalSnd->flush; + if (caughtup && XLByteEQ(sentPtr, replicatedPtr) && !pq_is_send_pending()) { walsender_shutdown_requested = true; [parent: f84997c7e668]