mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-12-21 08:29:39 +08:00
Improve corner cases in pg_ctl's new wait-for-postmaster-startup code.
With "-w -t 0", we should report "still starting up", not "ok". If we fall out of the loop without ever being able to call PQping (because we were never able to construct a connection string), report "no response", not "ok". This gets rid of corner cases in which we'd claim the server had started even though it had not. Also, if the postmaster.pid file is not there at any point after we've waited 5 seconds, assume the postmaster has failed and report that, rather than almost-certainly-fruitlessly continuing to wait. The pidfile should appear almost instantly even when there is extensive startup work to do, so 5 seconds is already a very conservative figure. This part is per a gripe from MauMau --- there might be better ways to do it, but nothing simple enough to get done for 9.1.
This commit is contained in:
parent
90857b48e1
commit
0bae3bc9be
@ -411,10 +411,14 @@ start_postmaster(void)
|
||||
static PGPing
|
||||
test_postmaster_connection(bool do_checkpoint)
|
||||
{
|
||||
PGPing ret = PQPING_OK; /* assume success for wait == zero */
|
||||
PGPing ret = PQPING_NO_RESPONSE;
|
||||
char connstr[MAXPGPATH * 2 + 256];
|
||||
int i;
|
||||
|
||||
/* if requested wait time is zero, return "still starting up" code */
|
||||
if (wait_seconds <= 0)
|
||||
return PQPING_REJECT;
|
||||
|
||||
connstr[0] = '\0';
|
||||
|
||||
for (i = 0; i < wait_seconds; i++)
|
||||
@ -538,6 +542,19 @@ test_postmaster_connection(bool do_checkpoint)
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* The postmaster should create postmaster.pid very soon after being
|
||||
* started. If it's not there after we've waited 5 or more seconds,
|
||||
* assume startup failed and give up waiting.
|
||||
*/
|
||||
if (i >= 5)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (stat(pid_file, &statbuf) != 0)
|
||||
return PQPING_NO_RESPONSE;
|
||||
}
|
||||
|
||||
/* No response, or startup still in process; wait */
|
||||
#if defined(WIN32)
|
||||
if (do_checkpoint)
|
||||
|
Loading…
Reference in New Issue
Block a user