summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorTom Lane2011-05-27 18:13:38 +0000
committerTom Lane2011-05-27 18:13:38 +0000
commit0bae3bc9be4a025df089f0a0c2f547fa538a97bc (patch)
treeffff2221aac49de5774db989178229b0a36104a8 /src/bin
parent90857b48e1f69dbca52f498bd444190d36dbd73f (diff)
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.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_ctl/pg_ctl.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 98bbaefd8c..7af3b913ff 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -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)