@@ -239,13 +239,13 @@ static bool RecoveryError = false; /* T if WAL recovery failed */
239
239
* hot standby during archive recovery.
240
240
*
241
241
* When the startup process is ready to start archive recovery, it signals the
242
- * postmaster, and we switch to PM_RECOVERY state. The background writer is
243
- * launched, while the startup process continues applying WAL. If Hot Standby
244
- * is enabled, then, after reaching a consistent point in WAL redo, startup
245
- * process signals us again, and we switch to PM_HOT_STANDBY state and
246
- * begin accepting connections to perform read-only queries. When archive
247
- * recovery is finished, the startup process exits with exit code 0 and we
248
- * switch to PM_RUN state.
242
+ * postmaster, and we switch to PM_RECOVERY state. The background writer and
243
+ * checkpointer are launched, while the startup process continues applying WAL.
244
+ * If Hot Standby is enabled, then, after reaching a consistent point in WAL
245
+ * redo, startup process signals us again, and we switch to PM_HOT_STANDBY
246
+ * state and begin accepting connections to perform read-only queries. When
247
+ * archive recovery is finished, the startup process exits with exit code 0
248
+ * and we switch to PM_RUN state.
249
249
*
250
250
* Normal child backends can only be launched when we are in PM_RUN or
251
251
* PM_HOT_STANDBY state. (We also allow launch of normal
@@ -1038,7 +1038,7 @@ PostmasterMain(int argc, char *argv[])
1038
1038
* handling setup of child processes. See tcop/postgres.c,
1039
1039
* bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
1040
1040
* postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/pgstat.c,
1041
- * postmaster/syslogger.c and postmaster/checkpointer.c
1041
+ * postmaster/syslogger.c and postmaster/checkpointer.c.
1042
1042
*/
1043
1043
pqinitmask ();
1044
1044
PG_SETMASK (& BlockSig );
@@ -1373,10 +1373,10 @@ ServerLoop(void)
1373
1373
/*
1374
1374
* If no background writer process is running, and we are not in a
1375
1375
* state that prevents it, start one. It doesn't matter if this
1376
- * fails, we'll just try again later.
1376
+ * fails, we'll just try again later. Likewise for the checkpointer.
1377
1377
*/
1378
1378
if (pmState == PM_RUN || pmState == PM_RECOVERY ||
1379
- pmState == PM_HOT_STANDBY )
1379
+ pmState == PM_HOT_STANDBY )
1380
1380
{
1381
1381
if (BgWriterPID == 0 )
1382
1382
BgWriterPID = StartBackgroundWriter ();
@@ -1386,7 +1386,8 @@ ServerLoop(void)
1386
1386
1387
1387
/*
1388
1388
* Likewise, if we have lost the walwriter process, try to start a new
1389
- * one.
1389
+ * one. But this is needed only in normal operation (else we cannot
1390
+ * be writing any new WAL).
1390
1391
*/
1391
1392
if (WalWriterPID == 0 && pmState == PM_RUN )
1392
1393
WalWriterPID = StartWalWriter ();
@@ -2131,11 +2132,12 @@ pmdie(SIGNAL_ARGS)
2131
2132
/* and the autovac launcher too */
2132
2133
if (AutoVacPID != 0 )
2133
2134
signal_child (AutoVacPID , SIGTERM );
2135
+ /* and the bgwriter too */
2136
+ if (BgWriterPID != 0 )
2137
+ signal_child (BgWriterPID , SIGTERM );
2134
2138
/* and the walwriter too */
2135
2139
if (WalWriterPID != 0 )
2136
2140
signal_child (WalWriterPID , SIGTERM );
2137
- if (BgWriterPID != 0 )
2138
- signal_child (BgWriterPID , SIGTERM );
2139
2141
2140
2142
/*
2141
2143
* If we're in recovery, we can't kill the startup process
@@ -2174,13 +2176,17 @@ pmdie(SIGNAL_ARGS)
2174
2176
2175
2177
if (StartupPID != 0 )
2176
2178
signal_child (StartupPID , SIGTERM );
2177
- if (WalReceiverPID != 0 )
2178
- signal_child (WalReceiverPID , SIGTERM );
2179
2179
if (BgWriterPID != 0 )
2180
2180
signal_child (BgWriterPID , SIGTERM );
2181
+ if (WalReceiverPID != 0 )
2182
+ signal_child (WalReceiverPID , SIGTERM );
2181
2183
if (pmState == PM_RECOVERY )
2182
2184
{
2183
- /* only checkpointer is active in this state */
2185
+ /*
2186
+ * Only startup, bgwriter, and checkpointer should be active
2187
+ * in this state; we just signaled the first two, and we don't
2188
+ * want to kill checkpointer yet.
2189
+ */
2184
2190
pmState = PM_WAIT_BACKENDS ;
2185
2191
}
2186
2192
else if (pmState == PM_RUN ||
@@ -2362,21 +2368,21 @@ reaper(SIGNAL_ARGS)
2362
2368
}
2363
2369
2364
2370
/*
2365
- * Crank up background tasks, if we didn't do that already
2371
+ * Crank up the background tasks, if we didn't do that already
2366
2372
* when we entered consistent recovery state. It doesn't matter
2367
2373
* if this fails, we'll just try again later.
2368
2374
*/
2369
2375
if (BgWriterPID == 0 )
2370
2376
BgWriterPID = StartBackgroundWriter ();
2371
2377
if (CheckpointerPID == 0 )
2372
2378
CheckpointerPID = StartCheckpointer ();
2379
+ if (WalWriterPID == 0 )
2380
+ WalWriterPID = StartWalWriter ();
2373
2381
2374
2382
/*
2375
2383
* Likewise, start other special children as needed. In a restart
2376
2384
* situation, some of them may be alive already.
2377
2385
*/
2378
- if (WalWriterPID == 0 )
2379
- WalWriterPID = StartWalWriter ();
2380
2386
if (!IsBinaryUpgrade && AutoVacuumingActive () && AutoVacPID == 0 )
2381
2387
AutoVacPID = StartAutoVacLauncher ();
2382
2388
if (XLogArchivingActive () && PgArchPID == 0 )
@@ -2392,7 +2398,9 @@ reaper(SIGNAL_ARGS)
2392
2398
}
2393
2399
2394
2400
/*
2395
- * Was it the bgwriter?
2401
+ * Was it the bgwriter? Normal exit can be ignored; we'll start a
2402
+ * new one at the next iteration of the postmaster's main loop, if
2403
+ * necessary. Any other exit condition is treated as a crash.
2396
2404
*/
2397
2405
if (pid == BgWriterPID )
2398
2406
{
@@ -4228,13 +4236,13 @@ sigusr1_handler(SIGNAL_ARGS)
4228
4236
FatalError = false;
4229
4237
4230
4238
/*
4231
- * Crank up the background writers. It doesn't matter if this fails,
4239
+ * Crank up the background tasks. It doesn't matter if this fails,
4232
4240
* we'll just try again later.
4233
4241
*/
4234
- Assert (CheckpointerPID == 0 );
4235
- CheckpointerPID = StartCheckpointer ();
4236
4242
Assert (BgWriterPID == 0 );
4237
4243
BgWriterPID = StartBackgroundWriter ();
4244
+ Assert (CheckpointerPID == 0 );
4245
+ CheckpointerPID = StartCheckpointer ();
4238
4246
4239
4247
pmState = PM_RECOVERY ;
4240
4248
}
0 commit comments