Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit866f2dd

Browse files
committed
Don't launch new child processes after we've been told to shut down.
Once we've received a shutdown signal (SIGINT or SIGTERM), we should notlaunch any more child processes, even if we get signals requesting such.The normal code path for spawning backends has always understood that,but the postmaster's infrastructure for hot standby and autovacuum didn'tget the memo. As reported by Hari Babu in bug #7643, this could lead tofailure to shut down at all in some cases, such as when SIGINT is receivedjust before the startup process sends PMSIGNAL_RECOVERY_STARTED: we'dlaunch a bgwriter and checkpointer, and then those processes would have noidea that they ought to quit. Similarly, launching a new autovacuum workerwould result in waiting till it finished before shutting down.Also, switch the order of the code blocks in reaper() that detect startupprocess crash versus shutdown termination. Once we've sent it a signal,we should not consider that exit(1) is surprising. This is just a cosmeticfix since shutdown occurs correctly anyway, but better not to log a phonycomplaint about startup process crash.Back-patch to 9.0. Some parts of this might be applicable before that,but given the lack of prior complaints I'm not going to worry too muchabout older branches.
1 parent4387cc9 commit866f2dd

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,18 @@ reaper(SIGNAL_ARGS)
23752375
{
23762376
StartupPID=0;
23772377

2378+
/*
2379+
* Startup process exited in response to a shutdown request (or it
2380+
* completed normally regardless of the shutdown request).
2381+
*/
2382+
if (Shutdown>NoShutdown&&
2383+
(EXIT_STATUS_0(exitstatus)||EXIT_STATUS_1(exitstatus)))
2384+
{
2385+
pmState=PM_WAIT_BACKENDS;
2386+
/* PostmasterStateMachine logic does the rest */
2387+
continue;
2388+
}
2389+
23782390
/*
23792391
* Unexpected exit of startup process (including FATAL exit)
23802392
* during PM_STARTUP is treated as catastrophic. There are no
@@ -2389,18 +2401,6 @@ reaper(SIGNAL_ARGS)
23892401
ExitPostmaster(1);
23902402
}
23912403

2392-
/*
2393-
* Startup process exited in response to a shutdown request (or it
2394-
* completed normally regardless of the shutdown request).
2395-
*/
2396-
if (Shutdown>NoShutdown&&
2397-
(EXIT_STATUS_0(exitstatus)||EXIT_STATUS_1(exitstatus)))
2398-
{
2399-
pmState=PM_WAIT_BACKENDS;
2400-
/* PostmasterStateMachine logic does the rest */
2401-
continue;
2402-
}
2403-
24042404
/*
24052405
* After PM_STARTUP, any unexpected exit (including FATAL exit) of
24062406
* the startup process is catastrophic, so kill other children,
@@ -4241,7 +4241,7 @@ sigusr1_handler(SIGNAL_ARGS)
42414241
* first. We don't want to go back to recovery in that case.
42424242
*/
42434243
if (CheckPostmasterSignal(PMSIGNAL_RECOVERY_STARTED)&&
4244-
pmState==PM_STARTUP)
4244+
pmState==PM_STARTUP&&Shutdown==NoShutdown)
42454245
{
42464246
/* WAL redo has started. We're out of reinitialization. */
42474247
FatalError= false;
@@ -4256,7 +4256,7 @@ sigusr1_handler(SIGNAL_ARGS)
42564256
pmState=PM_RECOVERY;
42574257
}
42584258
if (CheckPostmasterSignal(PMSIGNAL_BEGIN_HOT_STANDBY)&&
4259-
pmState==PM_RECOVERY)
4259+
pmState==PM_RECOVERY&&Shutdown==NoShutdown)
42604260
{
42614261
/*
42624262
* Likewise, start other special children as needed.
@@ -4287,7 +4287,8 @@ sigusr1_handler(SIGNAL_ARGS)
42874287
signal_child(SysLoggerPID,SIGUSR1);
42884288
}
42894289

4290-
if (CheckPostmasterSignal(PMSIGNAL_START_AUTOVAC_LAUNCHER))
4290+
if (CheckPostmasterSignal(PMSIGNAL_START_AUTOVAC_LAUNCHER)&&
4291+
Shutdown==NoShutdown)
42914292
{
42924293
/*
42934294
* Start one iteration of the autovacuum daemon, even if autovacuuming
@@ -4301,7 +4302,8 @@ sigusr1_handler(SIGNAL_ARGS)
43014302
start_autovac_launcher= true;
43024303
}
43034304

4304-
if (CheckPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER))
4305+
if (CheckPostmasterSignal(PMSIGNAL_START_AUTOVAC_WORKER)&&
4306+
Shutdown==NoShutdown)
43054307
{
43064308
/* The autovacuum launcher wants us to start a worker process. */
43074309
StartAutovacuumWorker();
@@ -4310,7 +4312,8 @@ sigusr1_handler(SIGNAL_ARGS)
43104312
if (CheckPostmasterSignal(PMSIGNAL_START_WALRECEIVER)&&
43114313
WalReceiverPID==0&&
43124314
(pmState==PM_STARTUP||pmState==PM_RECOVERY||
4313-
pmState==PM_HOT_STANDBY||pmState==PM_WAIT_READONLY))
4315+
pmState==PM_HOT_STANDBY||pmState==PM_WAIT_READONLY)&&
4316+
Shutdown==NoShutdown)
43144317
{
43154318
/* Startup Process wants us to start the walreceiver process. */
43164319
WalReceiverPID=StartWalReceiver();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp