pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: pgsql-bugs@postgresql.org
Subject: PQconninfo() doesn't return anything for host=/socket/directory
Date: Wed, 27 Nov 2013 09:44:51 +0100
Message-ID: <20131127084451.GA28863@alap2.anarazel.de> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

pqconninfo-socket-directory.diff (text/x-diff, 904B) download 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) {

Message-ID: <20131127084451.GA28863@alap2.anarazel.de>
Permalink:  ../20131127084451.GA28863@alap2.anarazel.de/
Also on:    postgresql.org/message-id/20131127084451.GA28863@alap2.anarazel.de

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@2ndquadrant.com
  Subject: Re: PQconninfo() doesn't return anything for host=/socket/directory
  In-Reply-To: <20131127084451.GA28863@alap2.anarazel.de>
  References: <20131127084451.GA28863@alap2.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox