mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Make standby server continuously retry restoring the next WAL segment with
restore_command, if the connection to the primary server is lost. This ensures that the standby can recover automatically, if the connection is lost for a long time and standby falls behind so much that the required WAL segments have been archived and deleted in the master. This also makes standby_mode useful without streaming replication; the server will keep retrying restore_command every few seconds until the trigger file is found. That's the same basic functionality pg_standby offers, but without the bells and whistles. To implement that, refactor the ReadRecord/FetchRecord functions. The FetchRecord() function introduced in the original streaming replication patch is removed, and all the retry logic is now in a new function called XLogReadPage(). XLogReadPage() is now responsible for executing restore_command, launching walreceiver, and waiting for new WAL to arrive from primary, as required. This also changes the life cycle of walreceiver. When launched, it now only tries to connect to the master once, and exits if the connection fails, or is lost during streaming for any reason. The startup process detects the death, and re-launches walreceiver if necessary.
This commit is contained in:
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.601 2010/01/15 09:19:02 heikki Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.602 2010/01/27 15:27:50 heikki Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@ -224,9 +224,6 @@ static int Shutdown = NoShutdown;
|
||||
static bool FatalError = false; /* T if recovering from backend crash */
|
||||
static bool RecoveryError = false; /* T if WAL recovery failed */
|
||||
|
||||
/* If WalReceiverActive is true, restart walreceiver if it dies */
|
||||
static bool WalReceiverActive = false;
|
||||
|
||||
/*
|
||||
* We use a simple state machine to control startup, shutdown, and
|
||||
* crash recovery (which is rather like shutdown followed by startup).
|
||||
@ -1469,11 +1466,6 @@ ServerLoop(void)
|
||||
if (PgStatPID == 0 && pmState == PM_RUN)
|
||||
PgStatPID = pgstat_start();
|
||||
|
||||
/* If we have lost walreceiver, try to start a new one */
|
||||
if (WalReceiverPID == 0 && WalReceiverActive &&
|
||||
(pmState == PM_RECOVERY || pmState == PM_RECOVERY_CONSISTENT))
|
||||
WalReceiverPID = StartWalReceiver();
|
||||
|
||||
/* If we need to signal the autovacuum launcher, do so now */
|
||||
if (avlauncher_needs_signal)
|
||||
{
|
||||
@ -4167,16 +4159,9 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
WalReceiverPID == 0)
|
||||
{
|
||||
/* Startup Process wants us to start the walreceiver process. */
|
||||
WalReceiverActive = true;
|
||||
WalReceiverPID = StartWalReceiver();
|
||||
}
|
||||
|
||||
if (CheckPostmasterSignal(PMSIGNAL_SHUTDOWN_WALRECEIVER))
|
||||
{
|
||||
/* The walreceiver process doesn't want to be restarted anymore */
|
||||
WalReceiverActive = false;
|
||||
}
|
||||
|
||||
PG_SETMASK(&UnBlockSig);
|
||||
|
||||
errno = save_errno;
|
||||
|
Reference in New Issue
Block a user