Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vlako-00036r-Tu for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Nov 2013 08:45:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vlako-0008Gw-CP for pgsql-bugs@arkaria.postgresql.org; Wed, 27 Nov 2013 08:45:50 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vlakn-0008Gp-9f for pgsql-bugs@postgresql.org; Wed, 27 Nov 2013 08:45:49 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VlakC-0005qS-4b for pgsql-bugs@postgresql.org; Wed, 27 Nov 2013 08:45:48 +0000 Received: from andres.at.anarazel.de.authenticated.anarazel.de by mail.anarazel.de (Postfix) with ESMTPSA id 1375D4E8003 for ; Wed, 27 Nov 2013 09:45:06 +0100 (CET) Date: Wed, 27 Nov 2013 09:44:51 +0100 From: Andres Freund To: pgsql-bugs@postgresql.org Subject: PQconninfo() doesn't return anything for host=/socket/directory Message-ID: <20131127084451.GA28863@alap2.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="bg08WKrSYDhXBjb5" Content-Disposition: inline X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --bg08WKrSYDhXBjb5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, Programs that use PQconninfo() to build a new connection string, like in my case pg_basebackup --write-recovery-conf, fail to do anything for non-default socket directories leading to the newly built connection string being unusable for connecting. The reason for that is the following tidbit from fe-connect.c:connectOptions2() /* * Allow unix socket specification in the host name */ if (conn->pghost && is_absolute_path(conn->pghost)) { if (conn->pgunixsocket) free(conn->pgunixsocket); conn->pgunixsocket = conn->pghost; conn->pghost = NULL; } This strikes me as unfortunate. Note that PQhost() does the right thing... I've attached a hack that fixes this, but I pretty much dislike the direction it's going. Maybe the better fix is to simply not unset pghost above and make connectDBStart() more intelligent? Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services --bg08WKrSYDhXBjb5 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pqconninfo-socket-directory.diff" diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 8dd1a59..f03e12e 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -196,6 +196,10 @@ static const internalPQconninfoOption PQconninfoOptions[] = { "Database-Host", "", 40, offsetof(struct pg_conn, pghost)}, + {"unix_socket_directory", NULL, NULL, NULL, + "Socket Directory", "", 40, + offsetof(struct pg_conn, pgunixsocket)}, + {"hostaddr", "PGHOSTADDR", NULL, NULL, "Database-Host-IP-Address", "", 45, offsetof(struct pg_conn, pghostaddr)}, @@ -5034,6 +5038,14 @@ conninfo_storeval(PQconninfoOption *connOptions, value = "prefer"; } + /* + * Can only be configured via host= externally. + */ + if (strcmp(keyword, "unix_socket_directory") == 0) + { + keyword = "host"; + } + option = conninfo_find(connOptions, keyword); if (option == NULL) { --bg08WKrSYDhXBjb5 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --bg08WKrSYDhXBjb5--