diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-01-27 15:27:51 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-01-27 15:27:51 +0000 |
commit | 1bb2558046cc8b8cb0c8f5563e8d32b3b120c9ec (patch) | |
tree | 61f6838c88e2a60a3f133d10c2e6352129aaf321 /src/backend/postmaster/postmaster.c | |
parent | ab13d1e925691c37bb6fa13cb748867c5ae2a91c (diff) |
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.
Diffstat (limited to 'src/backend/postmaster/postmaster.c')
-rw-r--r-- | src/backend/postmaster/postmaster.c | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 59f994bd16e..6df11b8a740 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -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; |