pgsql: libpq: Allow connection strings and URIs to specify multiple hos

Started by Robert Haasover 9 years ago2 messageshackers
Jump to latest
#1Robert Haas
robertmhaas@gmail.com

libpq: Allow connection strings and URIs to specify multiple hosts.

It's also possible to specify a separate port for each host.

Previously, we'd loop over every address returned by looking up the
host name; now, we'll try every address for every host name.

Patch by me. Victor Wagner wrote an earlier patch for this feature,
which I read, but I didn't use any of his code. Review by Mithun Cy.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/274bb2b3857cc987cfa21d14775cae9b0dababa5

Modified Files
--------------
doc/src/sgml/libpq.sgml | 38 ++-
src/interfaces/libpq/fe-auth.c | 28 +-
src/interfaces/libpq/fe-connect.c | 607 ++++++++++++++++++++++++++------------
src/interfaces/libpq/libpq-int.h | 41 ++-
4 files changed, 506 insertions(+), 208 deletions(-)

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

#2Michael Paquier
michael@paquier.xyz
In reply to: Robert Haas (#1)
Re: [COMMITTERS] pgsql: libpq: Allow connection strings and URIs to specify multiple hos

On Thu, Nov 3, 2016 at 10:46 PM, Robert Haas <rhaas@postgresql.org> wrote:

libpq: Allow connection strings and URIs to specify multiple hosts.

It's also possible to specify a separate port for each host.

Previously, we'd loop over every address returned by looking up the
host name; now, we'll try every address for every host name.

Patch by me. Victor Wagner wrote an earlier patch for this feature,
which I read, but I didn't use any of his code. Review by Mithun Cy.

While testing this feature I have bumped into the following restrictions:
$ psql -d "port=5432,5433"
psql: could not match 2 port numbers to 1 hosts
$ psql -d "port=5432,5433 host=/tmp"
psql: could not match 2 port numbers to 1 hosts

However this works:
$ psql -d "port=5432,5433 host=/tmp,/tmp"
psql: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5433"?

That's really user-unfriendly. Shouldn't libpq try in both cases to
use the single entry provided by the user or the default available? I
would imagine that for most users it would make sense to specify a
single PGHOST but try to different ports, not all users run a single
instance by server (though they should not).

This makes me think that we should have a set of regression tests to
test libpq URIs and connection strings, and the multi-host support in
connection strings gives a stronger reason to have one IMO.
--
Michael

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