Index: src/bin/pg_ctl/pg_ctl.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/pg_ctl/pg_ctl.c,v retrieving revision 1.32 diff -u -r1.32 pg_ctl.c --- src/bin/pg_ctl/pg_ctl.c 7 Oct 2004 15:21:55 -0000 1.32 +++ src/bin/pg_ctl/pg_ctl.c 10 Oct 2004 06:22:02 -0000 @@ -347,6 +347,7 @@ int i; char portstr[32]; char *p; + char *errMsg; *portstr = '\0'; @@ -414,23 +415,42 @@ for (i = 0; i < wait_seconds; i++) { - if ((conn = PQsetdbLogin(NULL, portstr, NULL, NULL, - "template1", NULL, NULL)) != NULL && - PQstatus(conn) == CONNECTION_OK) - { - PQfinish(conn); - success = true; - break; - } - else - { - if (!silence_echo) + if ((conn = PQsetdbLogin(NULL, portstr, NULL, NULL, "template1", NULL, NULL)) != NULL) { + if (PQstatus(conn) == CONNECTION_OK) { - printf("."); - fflush(stdout); + PQfinish(conn); + success = true; + break; + } + else + { + /* Try a little harder to see if the + * backend is up. The connection may + * be bad, but if we're getting a + * valid response from the backend, + * then assume the backend is up. + * There has to be a better way of + * doing this than looking at the + * error string, but maybe not for + * pg_ctl(1)'s purpose. */ + errMsg = PQerrorMessage(conn); + if (errMsg && strcmp(errMsg, "fe_sendauth: no password supplied\n") == 0) { + PQfinish(conn); + success = true; + break; + } + else if (!silence_echo) + { + printf("."); + + fflush(stdout); + } + pg_usleep(1000000); /* 1 sec */ } - pg_usleep(1000000); /* 1 sec */ } + + if (conn) + PQfinish(conn); } return success;