mirror of
https://github.com/postgres/postgres.git
synced 2025-05-09 18:21:05 +03:00
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.
This commit is contained in:
parent
a5ed98ba5a
commit
13f75e378e
@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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);
|
||||
static char **readfile(const char *path);
|
||||
static int start_postmaster(void);
|
||||
static bool test_postmaster_connection(void);
|
||||
static bool postmaster_is_alive(pid_t pid);
|
||||
|
||||
static char def_postopts_file[MAXPGPATH];
|
||||
static char postopts_file[MAXPGPATH];
|
||||
@ -683,7 +684,8 @@ do_restart(void)
|
||||
|
||||
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(_("starting postmaster anyway\n"));
|
||||
do_start();
|
||||
@ -692,13 +694,18 @@ do_restart(void)
|
||||
else if (pid < 0) /* standalone backend, not postmaster */
|
||||
{
|
||||
pid = -pid;
|
||||
if (postmaster_is_alive((pid_t) pid))
|
||||
{
|
||||
write_stderr(_("%s: cannot restart postmaster; "
|
||||
"postgres is running (PID: %ld)\n"),
|
||||
progname, pid);
|
||||
write_stderr(_("Please terminate postgres and try again.\n"));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (postmaster_is_alive((pid_t) pid))
|
||||
{
|
||||
if (kill((pid_t) pid, sig) != 0)
|
||||
{
|
||||
write_stderr(_("%s: could not send stop signal (PID: %ld): %s\n"), progname, pid,
|
||||
@ -731,6 +738,14 @@ do_restart(void)
|
||||
|
||||
print_msg(_(" done\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();
|
||||
}
|
||||
|
||||
@ -841,8 +856,8 @@ do_kill(pgpid_t pid)
|
||||
{
|
||||
if (kill((pid_t) pid, sig) != 0)
|
||||
{
|
||||
write_stderr(_("%s: could not send signal %d (PID: %ld): %s\n"), progname, sig, pid,
|
||||
strerror(errno));
|
||||
write_stderr(_("%s: could not send signal %d (PID: %ld): %s\n"),
|
||||
progname, sig, pid, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user