Skip to content

Commit bc2a389

Browse files
committed
Be more verbose when the postmaster unexpectedly quits.
Emit a LOG message when the postmaster stops because of a failure in the startup process. There already is a similar message if we exit for that reason during PM_STARTUP phase, so it seems inconsistent that there was none if the startup process fails later on. Also emit a LOG message when the postmaster stops after a crash because restart_after_crash is disabled. This seems potentially helpful in case DBAs (or developers) forget that that's set. Also, it was the only remaining place where the postmaster would do an abnormal exit without any comment as to why. In passing, remove an unreachable call of ExitPostmaster(0). Discussion: https://postgr.es/m/194914.1621641288@sss.pgh.pa.us
1 parent 8f73ed6 commit bc2a389

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/backend/postmaster/postmaster.c

+21-6
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,11 @@ PostmasterStateMachine(void)
39733973
if (ReachedNormalRunning)
39743974
CancelBackup();
39753975

3976-
/* Normal exit from the postmaster is here */
3976+
/*
3977+
* Normal exit from the postmaster is here. We don't need to log
3978+
* anything here, since the UnlinkLockFiles proc_exit callback
3979+
* will do so, and that should be the last user-visible action.
3980+
*/
39773981
ExitPostmaster(0);
39783982
}
39793983
}
@@ -3985,9 +3989,21 @@ PostmasterStateMachine(void)
39853989
* startup process fails, because more than likely it will just fail again
39863990
* and we will keep trying forever.
39873991
*/
3988-
if (pmState == PM_NO_CHILDREN &&
3989-
(StartupStatus == STARTUP_CRASHED || !restart_after_crash))
3990-
ExitPostmaster(1);
3992+
if (pmState == PM_NO_CHILDREN)
3993+
{
3994+
if (StartupStatus == STARTUP_CRASHED)
3995+
{
3996+
ereport(LOG,
3997+
(errmsg("shutting down due to startup process failure")));
3998+
ExitPostmaster(1);
3999+
}
4000+
if (!restart_after_crash)
4001+
{
4002+
ereport(LOG,
4003+
(errmsg("shutting down because restart_after_crash is off")));
4004+
ExitPostmaster(1);
4005+
}
4006+
}
39914007

39924008
/*
39934009
* If we need to recover from a crash, wait for all non-syslogger children
@@ -5439,8 +5455,7 @@ StartChildProcess(AuxProcType type)
54395455
MemoryContextDelete(PostmasterContext);
54405456
PostmasterContext = NULL;
54415457

5442-
AuxiliaryProcessMain(ac, av);
5443-
ExitPostmaster(0);
5458+
AuxiliaryProcessMain(ac, av); /* does not return */
54445459
}
54455460
#endif /* EXEC_BACKEND */
54465461

0 commit comments

Comments
 (0)