Commit d0c231d1 authored by Tom Lane's avatar Tom Lane

Cosmetic adjustments for postmaster's handling of checkpointer.

Correct some comments, order some operations a bit more consistently.
No functional changes.
parent 2cfb1c6f
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
* The bgwriter is started by the postmaster as soon as the startup subprocess * The bgwriter is started by the postmaster as soon as the startup subprocess
* finishes, or as soon as recovery begins if we are doing archive recovery. * finishes, or as soon as recovery begins if we are doing archive recovery.
* It remains alive until the postmaster commands it to terminate. * It remains alive until the postmaster commands it to terminate.
* Normal termination is by SIGUSR2, which instructs the bgwriter to exit(0). * Normal termination is by SIGTERM, which instructs the bgwriter to exit(0).
* Emergency termination is by SIGQUIT; like any * Emergency termination is by SIGQUIT; like any backend, the bgwriter will
* backend, the bgwriter will simply abort and exit on SIGQUIT. * simply abort and exit on SIGQUIT.
* *
* If the bgwriter exits unexpectedly, the postmaster treats that the same * If the bgwriter exits unexpectedly, the postmaster treats that the same
* as a backend crash: shared memory may be corrupted, so remaining backends * as a backend crash: shared memory may be corrupted, so remaining backends
......
...@@ -239,13 +239,13 @@ static bool RecoveryError = false; /* T if WAL recovery failed */ ...@@ -239,13 +239,13 @@ static bool RecoveryError = false; /* T if WAL recovery failed */
* hot standby during archive recovery. * hot standby during archive recovery.
* *
* When the startup process is ready to start archive recovery, it signals the * When the startup process is ready to start archive recovery, it signals the
* postmaster, and we switch to PM_RECOVERY state. The background writer is * postmaster, and we switch to PM_RECOVERY state. The background writer and
* launched, while the startup process continues applying WAL. If Hot Standby * checkpointer are launched, while the startup process continues applying WAL.
* is enabled, then, after reaching a consistent point in WAL redo, startup * If Hot Standby is enabled, then, after reaching a consistent point in WAL
* process signals us again, and we switch to PM_HOT_STANDBY state and * redo, startup process signals us again, and we switch to PM_HOT_STANDBY
* begin accepting connections to perform read-only queries. When archive * state and begin accepting connections to perform read-only queries. When
* recovery is finished, the startup process exits with exit code 0 and we * archive recovery is finished, the startup process exits with exit code 0
* switch to PM_RUN state. * and we switch to PM_RUN state.
* *
* Normal child backends can only be launched when we are in PM_RUN or * Normal child backends can only be launched when we are in PM_RUN or
* PM_HOT_STANDBY state. (We also allow launch of normal * PM_HOT_STANDBY state. (We also allow launch of normal
...@@ -1038,7 +1038,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -1038,7 +1038,7 @@ PostmasterMain(int argc, char *argv[])
* handling setup of child processes. See tcop/postgres.c, * handling setup of child processes. See tcop/postgres.c,
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c, * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c, * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
* postmaster/syslogger.c and postmaster/checkpointer.c * postmaster/syslogger.c and postmaster/checkpointer.c.
*/ */
pqinitmask(); pqinitmask();
PG_SETMASK(&BlockSig); PG_SETMASK(&BlockSig);
...@@ -1373,7 +1373,7 @@ ServerLoop(void) ...@@ -1373,7 +1373,7 @@ ServerLoop(void)
/* /*
* If no background writer process is running, and we are not in a * If no background writer process is running, and we are not in a
* state that prevents it, start one. It doesn't matter if this * state that prevents it, start one. It doesn't matter if this
* fails, we'll just try again later. * fails, we'll just try again later. Likewise for the checkpointer.
*/ */
if (pmState == PM_RUN || pmState == PM_RECOVERY || if (pmState == PM_RUN || pmState == PM_RECOVERY ||
pmState == PM_HOT_STANDBY) pmState == PM_HOT_STANDBY)
...@@ -1386,7 +1386,8 @@ ServerLoop(void) ...@@ -1386,7 +1386,8 @@ ServerLoop(void)
/* /*
* Likewise, if we have lost the walwriter process, try to start a new * Likewise, if we have lost the walwriter process, try to start a new
* one. * one. But this is needed only in normal operation (else we cannot
* be writing any new WAL).
*/ */
if (WalWriterPID == 0 && pmState == PM_RUN) if (WalWriterPID == 0 && pmState == PM_RUN)
WalWriterPID = StartWalWriter(); WalWriterPID = StartWalWriter();
...@@ -2131,11 +2132,12 @@ pmdie(SIGNAL_ARGS) ...@@ -2131,11 +2132,12 @@ pmdie(SIGNAL_ARGS)
/* and the autovac launcher too */ /* and the autovac launcher too */
if (AutoVacPID != 0) if (AutoVacPID != 0)
signal_child(AutoVacPID, SIGTERM); signal_child(AutoVacPID, SIGTERM);
/* and the bgwriter too */
if (BgWriterPID != 0)
signal_child(BgWriterPID, SIGTERM);
/* and the walwriter too */ /* and the walwriter too */
if (WalWriterPID != 0) if (WalWriterPID != 0)
signal_child(WalWriterPID, SIGTERM); signal_child(WalWriterPID, SIGTERM);
if (BgWriterPID != 0)
signal_child(BgWriterPID, SIGTERM);
/* /*
* If we're in recovery, we can't kill the startup process * If we're in recovery, we can't kill the startup process
...@@ -2174,13 +2176,17 @@ pmdie(SIGNAL_ARGS) ...@@ -2174,13 +2176,17 @@ pmdie(SIGNAL_ARGS)
if (StartupPID != 0) if (StartupPID != 0)
signal_child(StartupPID, SIGTERM); signal_child(StartupPID, SIGTERM);
if (WalReceiverPID != 0)
signal_child(WalReceiverPID, SIGTERM);
if (BgWriterPID != 0) if (BgWriterPID != 0)
signal_child(BgWriterPID, SIGTERM); signal_child(BgWriterPID, SIGTERM);
if (WalReceiverPID != 0)
signal_child(WalReceiverPID, SIGTERM);
if (pmState == PM_RECOVERY) if (pmState == PM_RECOVERY)
{ {
/* only checkpointer is active in this state */ /*
* Only startup, bgwriter, and checkpointer should be active
* in this state; we just signaled the first two, and we don't
* want to kill checkpointer yet.
*/
pmState = PM_WAIT_BACKENDS; pmState = PM_WAIT_BACKENDS;
} }
else if (pmState == PM_RUN || else if (pmState == PM_RUN ||
...@@ -2362,7 +2368,7 @@ reaper(SIGNAL_ARGS) ...@@ -2362,7 +2368,7 @@ reaper(SIGNAL_ARGS)
} }
/* /*
* Crank up background tasks, if we didn't do that already * Crank up the background tasks, if we didn't do that already
* when we entered consistent recovery state. It doesn't matter * when we entered consistent recovery state. It doesn't matter
* if this fails, we'll just try again later. * if this fails, we'll just try again later.
*/ */
...@@ -2370,13 +2376,13 @@ reaper(SIGNAL_ARGS) ...@@ -2370,13 +2376,13 @@ reaper(SIGNAL_ARGS)
BgWriterPID = StartBackgroundWriter(); BgWriterPID = StartBackgroundWriter();
if (CheckpointerPID == 0) if (CheckpointerPID == 0)
CheckpointerPID = StartCheckpointer(); CheckpointerPID = StartCheckpointer();
if (WalWriterPID == 0)
WalWriterPID = StartWalWriter();
/* /*
* Likewise, start other special children as needed. In a restart * Likewise, start other special children as needed. In a restart
* situation, some of them may be alive already. * situation, some of them may be alive already.
*/ */
if (WalWriterPID == 0)
WalWriterPID = StartWalWriter();
if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0) if (!IsBinaryUpgrade && AutoVacuumingActive() && AutoVacPID == 0)
AutoVacPID = StartAutoVacLauncher(); AutoVacPID = StartAutoVacLauncher();
if (XLogArchivingActive() && PgArchPID == 0) if (XLogArchivingActive() && PgArchPID == 0)
...@@ -2392,7 +2398,9 @@ reaper(SIGNAL_ARGS) ...@@ -2392,7 +2398,9 @@ reaper(SIGNAL_ARGS)
} }
/* /*
* Was it the bgwriter? * Was it the bgwriter? Normal exit can be ignored; we'll start a
* new one at the next iteration of the postmaster's main loop, if
* necessary. Any other exit condition is treated as a crash.
*/ */
if (pid == BgWriterPID) if (pid == BgWriterPID)
{ {
...@@ -4228,13 +4236,13 @@ sigusr1_handler(SIGNAL_ARGS) ...@@ -4228,13 +4236,13 @@ sigusr1_handler(SIGNAL_ARGS)
FatalError = false; FatalError = false;
/* /*
* Crank up the background writers. It doesn't matter if this fails, * Crank up the background tasks. It doesn't matter if this fails,
* we'll just try again later. * we'll just try again later.
*/ */
Assert(CheckpointerPID == 0);
CheckpointerPID = StartCheckpointer();
Assert(BgWriterPID == 0); Assert(BgWriterPID == 0);
BgWriterPID = StartBackgroundWriter(); BgWriterPID = StartBackgroundWriter();
Assert(CheckpointerPID == 0);
CheckpointerPID = StartCheckpointer();
pmState = PM_RECOVERY; pmState = PM_RECOVERY;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment