Skip to content

Commit cd85ae1

Browse files
committed
Improve pg_ctl's message for shutdown after recovery.
If pg_ctl tries to start the postmaster, but the postmaster shuts down because it completed a point-in-time recovery, pg_ctl used to report a message that indicated a failure. It's not really a failure, so instead say "server shut down because of recovery target settings". Zhao Junwang, Crisp Lee, Laurenz Albe Discussion: https://postgr.es/m/CAGHPtV7GttPZ-HvxZuYRy70jLGQMEm5=LQc4fKGa=J74m2VZbg@mail.gmail.com
1 parent 56c6be5 commit cd85ae1

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef enum
4545
{
4646
POSTMASTER_READY,
4747
POSTMASTER_STILL_STARTING,
48+
POSTMASTER_SHUTDOWN_IN_RECOVERY,
4849
POSTMASTER_FAILED,
4950
} WaitPMResult;
5051

@@ -657,17 +658,24 @@ wait_for_postmaster_start(pid_t pm_pid, bool do_checkpoint)
657658
* On Windows, we may be checking the postmaster's parent shell, but
658659
* that's fine for this purpose.
659660
*/
660-
#ifndef WIN32
661661
{
662+
bool pm_died;
663+
#ifndef WIN32
662664
int exitstatus;
663665

664-
if (waitpid(pm_pid, &exitstatus, WNOHANG) == pm_pid)
665-
return POSTMASTER_FAILED;
666-
}
666+
pm_died = (waitpid(pm_pid, &exitstatus, WNOHANG) == pm_pid);
667667
#else
668-
if (WaitForSingleObject(postmasterProcess, 0) == WAIT_OBJECT_0)
669-
return POSTMASTER_FAILED;
668+
pm_died = (WaitForSingleObject(postmasterProcess, 0) == WAIT_OBJECT_0);
670669
#endif
670+
if (pm_died)
671+
{
672+
/* See if postmaster terminated intentionally */
673+
if (get_control_dbstate() == DB_SHUTDOWNED_IN_RECOVERY)
674+
return POSTMASTER_SHUTDOWN_IN_RECOVERY;
675+
else
676+
return POSTMASTER_FAILED;
677+
}
678+
}
671679

672680
/* Startup still in process; wait, printing a dot once per second */
673681
if (i % WAITS_PER_SEC == 0)
@@ -991,6 +999,10 @@ do_start(void)
991999
progname);
9921000
exit(1);
9931001
break;
1002+
case POSTMASTER_SHUTDOWN_IN_RECOVERY:
1003+
print_msg(_(" done\n"));
1004+
print_msg(_("server shut down because of recovery target settings\n"));
1005+
break;
9941006
case POSTMASTER_FAILED:
9951007
print_msg(_(" stopped waiting\n"));
9961008
write_stderr(_("%s: could not start server\n"

0 commit comments

Comments
 (0)