diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 807d7023a9..07b3f0c9c8 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -599,6 +599,25 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint) char **optlines; int numlines; + /* + * Check whether the child postmaster process is still alive. This + * lets us exit early if the postmaster fails during startup. + * + * On Windows, we may be checking the postmaster's parent shell, but + * that's fine for this purpose. + */ +#ifndef WIN32 + { + int exitstatus; + + if (waitpid(pm_pid, &exitstatus, WNOHANG) == pm_pid) + return POSTMASTER_FAILED; + } +#else + if (WaitForSingleObject(postmasterProcess, 0) == WAIT_OBJECT_0) + return POSTMASTER_FAILED; +#endif + /* * Try to read the postmaster.pid file. If it's not valid, or if the * status line isn't there yet, just keep waiting. @@ -619,6 +638,7 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint) */ pmpid = atol(optlines[LOCK_FILE_LINE_PID - 1]); pmstart = atol(optlines[LOCK_FILE_LINE_START_TIME - 1]); + if (pmstart >= start_time - 2 && #ifndef WIN32 pmpid == pm_pid @@ -651,25 +671,6 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint) */ free_readfile(optlines); - /* - * Check whether the child postmaster process is still alive. This - * lets us exit early if the postmaster fails during startup. - * - * On Windows, we may be checking the postmaster's parent shell, but - * that's fine for this purpose. - */ -#ifndef WIN32 - { - int exitstatus; - - if (waitpid(pm_pid, &exitstatus, WNOHANG) == pm_pid) - return POSTMASTER_FAILED; - } -#else - if (WaitForSingleObject(postmasterProcess, 0) == WAIT_OBJECT_0) - return POSTMASTER_FAILED; -#endif - /* Startup still in process; wait, printing a dot once per second */ if (i % WAITS_PER_SEC == 0) {