|
|
699f87 |
diff --git a/contrib/pg_upgrade/server.c b/contrib/pg_upgrade/server.c
|
|
|
699f87 |
index c5ecb84..a519a9e 100644
|
|
|
699f87 |
--- a/contrib/pg_upgrade/server.c
|
|
|
699f87 |
+++ b/contrib/pg_upgrade/server.c
|
|
|
699f87 |
@@ -166,7 +166,6 @@ static void
|
|
|
699f87 |
stop_postmaster_atexit(void)
|
|
|
699f87 |
{
|
|
|
699f87 |
stop_postmaster(true);
|
|
|
699f87 |
-
|
|
|
699f87 |
}
|
|
|
699f87 |
|
|
|
699f87 |
|
|
|
699f87 |
@@ -235,7 +234,23 @@ start_postmaster(ClusterInfo *cluster)
|
|
|
699f87 |
false,
|
|
|
699f87 |
"%s", cmd);
|
|
|
699f87 |
|
|
|
699f87 |
- /* Check to see if we can connect to the server; if not, report it. */
|
|
|
699f87 |
+ /*
|
|
|
699f87 |
+ * We set this here to make sure atexit() shuts down the server,
|
|
|
699f87 |
+ * but only if we started the server successfully. We do it
|
|
|
699f87 |
+ * before checking for connectivity in case the server started but
|
|
|
699f87 |
+ * there is a connectivity failure. If pg_ctl did not return success,
|
|
|
699f87 |
+ * we will exit below.
|
|
|
699f87 |
+ */
|
|
|
699f87 |
+ if (pg_ctl_return)
|
|
|
699f87 |
+ os_info.running_cluster = cluster;
|
|
|
699f87 |
+
|
|
|
699f87 |
+ /*
|
|
|
699f87 |
+ * pg_ctl -w might have failed because the server couldn't be started,
|
|
|
699f87 |
+ * or there might have been a connection problem in _checking_ if the
|
|
|
699f87 |
+ * server has started. Therefore, even if pg_ctl failed, we continue
|
|
|
699f87 |
+ * and test for connectivity in case we get a connection reason for the
|
|
|
699f87 |
+ * failure.
|
|
|
699f87 |
+ */
|
|
|
699f87 |
if ((conn = get_db_conn(cluster, "template1")) == NULL ||
|
|
|
699f87 |
PQstatus(conn) != CONNECTION_OK)
|
|
|
699f87 |
{
|
|
|
699f87 |
@@ -249,12 +264,13 @@ start_postmaster(ClusterInfo *cluster)
|
|
|
699f87 |
}
|
|
|
699f87 |
PQfinish(conn);
|
|
|
699f87 |
|
|
|
699f87 |
- /* If the connection didn't fail, fail now */
|
|
|
699f87 |
+ /*
|
|
|
699f87 |
+ * If pg_ctl failed, and the connection didn't fail, fail now. This
|
|
|
699f87 |
+ * could happen if the server was already running.
|
|
|
699f87 |
+ */
|
|
|
699f87 |
if (!pg_ctl_return)
|
|
|
699f87 |
pg_log(PG_FATAL, "pg_ctl failed to start the %s server, or connection failed\n",
|
|
|
699f87 |
CLUSTER_NAME(cluster));
|
|
|
699f87 |
-
|
|
|
699f87 |
- os_info.running_cluster = cluster;
|
|
|
699f87 |
}
|
|
|
699f87 |
|
|
|
699f87 |
|