*** a/src/backend/replication/walsender.c --- b/src/backend/replication/walsender.c *************** *** 27,33 **** * If the server is shut down, postmaster sends us SIGUSR2 after all * regular backends have exited and the shutdown checkpoint has been written. * This instruct walsender to send any outstanding WAL, including the ! * shutdown checkpoint record, and then exit. * * * Portions Copyright (c) 2010-2013, PostgreSQL Global Development Group --- 27,34 ---- * If the server is shut down, postmaster sends us SIGUSR2 after all * regular backends have exited and the shutdown checkpoint has been written. * This instruct walsender to send any outstanding WAL, including the ! * shutdown checkpoint record, wait for it to be replicated to the standby, ! * and then exit. * * * Portions Copyright (c) 2010-2013, PostgreSQL Global Development Group *************** *** 1045,1051 **** WalSndLoop(void) /* * When SIGUSR2 arrives, we send any outstanding logs up to the ! * shutdown checkpoint record (i.e., the latest record) and exit. * This may be a normal termination at shutdown, or a promotion, * the walsender is not sure which. */ --- 1046,1053 ---- /* * When SIGUSR2 arrives, we send any outstanding logs up to the ! * shutdown checkpoint record (i.e., the latest record), wait ! * for them to be replicated to the standby, and exit. * This may be a normal termination at shutdown, or a promotion, * the walsender is not sure which. */ *************** *** 1053,1059 **** WalSndLoop(void) { /* ... let's just be real sure we're caught up ... */ XLogSend(&caughtup); ! if (caughtup && !pq_is_send_pending()) { /* Inform the standby that XLOG streaming is done */ EndCommand("COPY 0", DestRemote); --- 1055,1062 ---- { /* ... let's just be real sure we're caught up ... */ XLogSend(&caughtup); ! if (caughtup && !pq_is_send_pending() && ! sentPtr == MyWalSnd->flush) { /* Inform the standby that XLOG streaming is done */ EndCommand("COPY 0", DestRemote); *************** *** 1728,1734 **** WalSndLastCycleHandler(SIGNAL_ARGS) /* * If replication has not yet started, die like with SIGTERM. If * replication is active, only set a flag and wake up the main loop. It ! * will send any outstanding WAL, and then exit gracefully. */ if (!replication_active) kill(MyProcPid, SIGTERM); --- 1731,1738 ---- /* * If replication has not yet started, die like with SIGTERM. If * replication is active, only set a flag and wake up the main loop. It ! * will send any outstanding WAL, wait for it to be replicated to ! * the standby, and then exit gracefully. */ if (!replication_active) kill(MyProcPid, SIGTERM);