diff -ru pgsql.orig/src/bin/pg_ctl/pg_ctl.c pgsql/src/bin/pg_ctl/pg_ctl.c
--- pgsql.orig/src/bin/pg_ctl/pg_ctl.c	2006-09-27 14:57:20.000000000 -0700
+++ pgsql/src/bin/pg_ctl/pg_ctl.c	2006-09-27 14:58:02.000000000 -0700
@@ -387,9 +387,13 @@
 	bool		success = false;
 	int			i;
 	char		portstr[32];
+	char		sockdirstr[256];
+	char		*loginhost;
 	char	   *p;
 
 	*portstr = '\0';
+	*sockdirstr = '\0';
+	loginhost = NULL;
 
 	/* post_opts */
 	for (p = post_opts; *p;)
@@ -443,6 +447,37 @@
 			}
 		}
 	}
+	if (!*sockdirstr)
+	{
+		char	  **optlines;
+
+		optlines = readfile(conf_file);
+		if (optlines != NULL)
+		{
+			for (; *optlines != NULL; optlines++)
+			{
+				p = *optlines;
+
+				while (isspace((unsigned char) *p))
+					p++;
+				if (strncmp(p, "unix_socket_directory", strlen("unix_socket_directory")) != 0)
+					continue;
+				p += strlen("unix_socket_directory");
+				while (isspace((unsigned char) *p))
+					p++;
+				if (*p != '=')
+					continue;
+				p++;
+				while (isspace((unsigned char) *p))
+					p++;
+				p++; /* skip first single quote */
+				StrNCpy(sockdirstr, p, Min(strcspn(p, "'") + 1,
+										sizeof(sockdirstr)));
+				/* keep looking, maybe there is another */
+			}
+		}
+		loginhost = sockdirstr;
+	}
 
 	/* environment */
 	if (!*portstr && getenv("PGPORT") != NULL)
@@ -454,7 +489,7 @@
 
 	for (i = 0; i < wait_seconds; i++)
 	{
-		if ((conn = PQsetdbLogin(NULL, portstr, NULL, NULL,
+		if ((conn = PQsetdbLogin(loginhost, portstr, NULL, NULL,
 								 "postgres", NULL, NULL)) != NULL &&
 			(PQstatus(conn) == CONNECTION_OK ||
 			 (strcmp(PQerrorMessage(conn),
Only in pgsql/src/bin/pg_ctl: pg_ctl.c.orig
