Commit 13f75e37 authored by Tom Lane's avatar Tom Lane

Use postmaster_is_alive() check in pg_ctl restart as well as pg_ctl status,

so that restart doesn't fail when old postmaster died unbetimes.
parent a5ed98ba
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* *
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.56 2005/04/20 23:10:16 tgl Exp $ * $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.57 2005/05/04 22:35:15 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -116,6 +116,7 @@ static pgpid_t get_pgpid(void); ...@@ -116,6 +116,7 @@ static pgpid_t get_pgpid(void);
static char **readfile(const char *path); static char **readfile(const char *path);
static int start_postmaster(void); static int start_postmaster(void);
static bool test_postmaster_connection(void); static bool test_postmaster_connection(void);
static bool postmaster_is_alive(pid_t pid);
static char def_postopts_file[MAXPGPATH]; static char def_postopts_file[MAXPGPATH];
static char postopts_file[MAXPGPATH]; static char postopts_file[MAXPGPATH];
...@@ -683,7 +684,8 @@ do_restart(void) ...@@ -683,7 +684,8 @@ do_restart(void)
if (pid == 0) /* no pid file */ if (pid == 0) /* no pid file */
{ {
write_stderr(_("%s: PID file \"%s\" does not exist\n"), progname, pid_file); write_stderr(_("%s: PID file \"%s\" does not exist\n"),
progname, pid_file);
write_stderr(_("Is postmaster running?\n")); write_stderr(_("Is postmaster running?\n"));
write_stderr(_("starting postmaster anyway\n")); write_stderr(_("starting postmaster anyway\n"));
do_start(); do_start();
...@@ -692,13 +694,18 @@ do_restart(void) ...@@ -692,13 +694,18 @@ do_restart(void)
else if (pid < 0) /* standalone backend, not postmaster */ else if (pid < 0) /* standalone backend, not postmaster */
{ {
pid = -pid; pid = -pid;
if (postmaster_is_alive((pid_t) pid))
{
write_stderr(_("%s: cannot restart postmaster; " write_stderr(_("%s: cannot restart postmaster; "
"postgres is running (PID: %ld)\n"), "postgres is running (PID: %ld)\n"),
progname, pid); progname, pid);
write_stderr(_("Please terminate postgres and try again.\n")); write_stderr(_("Please terminate postgres and try again.\n"));
exit(1); exit(1);
} }
}
if (postmaster_is_alive((pid_t) pid))
{
if (kill((pid_t) pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
write_stderr(_("%s: could not send stop signal (PID: %ld): %s\n"), progname, pid, write_stderr(_("%s: could not send stop signal (PID: %ld): %s\n"), progname, pid,
...@@ -731,6 +738,14 @@ do_restart(void) ...@@ -731,6 +738,14 @@ do_restart(void)
print_msg(_(" done\n")); print_msg(_(" done\n"));
printf(_("postmaster stopped\n")); printf(_("postmaster stopped\n"));
}
else
{
write_stderr(_("%s: old postmaster process (PID: %ld) seems to be gone\n"),
progname, pid);
write_stderr(_("starting postmaster anyway\n"));
}
do_start(); do_start();
} }
...@@ -841,8 +856,8 @@ do_kill(pgpid_t pid) ...@@ -841,8 +856,8 @@ do_kill(pgpid_t pid)
{ {
if (kill((pid_t) pid, sig) != 0) if (kill((pid_t) pid, sig) != 0)
{ {
write_stderr(_("%s: could not send signal %d (PID: %ld): %s\n"), progname, sig, pid, write_stderr(_("%s: could not send signal %d (PID: %ld): %s\n"),
strerror(errno)); progname, sig, pid, strerror(errno));
exit(1); exit(1);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment