Be more verbose when the postmaster unexpectedly quits.
authorTom Lane
Sun, 23 May 2021 14:50:21 +0000 (10:50 -0400)
committerTom Lane
Sun, 23 May 2021 14:50:21 +0000 (10:50 -0400)
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

src/backend/postmaster/postmaster.c

index 53278594722a63bae6cb6146c0c3628c0d5c8287..5a050898fec79a26edc23c79d516c1c3f22de86d 100644 (file)
@@ -3973,7 +3973,11 @@ PostmasterStateMachine(void)
            if (ReachedNormalRunning)
                CancelBackup();
 
-           /* Normal exit from the postmaster is here */
+           /*
+            * Normal exit from the postmaster is here.  We don't need to log
+            * anything here, since the UnlinkLockFiles proc_exit callback
+            * will do so, and that should be the last user-visible action.
+            */
            ExitPostmaster(0);
        }
    }
@@ -3985,9 +3989,21 @@ PostmasterStateMachine(void)
     * startup process fails, because more than likely it will just fail again
     * and we will keep trying forever.
     */
-   if (pmState == PM_NO_CHILDREN &&
-       (StartupStatus == STARTUP_CRASHED || !restart_after_crash))
-       ExitPostmaster(1);
+   if (pmState == PM_NO_CHILDREN)
+   {
+       if (StartupStatus == STARTUP_CRASHED)
+       {
+           ereport(LOG,
+                   (errmsg("shutting down due to startup process failure")));
+           ExitPostmaster(1);
+       }
+       if (!restart_after_crash)
+       {
+           ereport(LOG,
+                   (errmsg("shutting down because restart_after_crash is off")));
+           ExitPostmaster(1);
+       }
+   }
 
    /*
     * If we need to recover from a crash, wait for all non-syslogger children
@@ -5439,8 +5455,7 @@ StartChildProcess(AuxProcType type)
        MemoryContextDelete(PostmasterContext);
        PostmasterContext = NULL;
 
-       AuxiliaryProcessMain(ac, av);
-       ExitPostmaster(0);
+       AuxiliaryProcessMain(ac, av);   /* does not return */
    }
 #endif                         /* EXEC_BACKEND */