Blame SOURCES/postgresql-9.2.4-upgrade-and-perm-problems.patch

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