From 7b02ba62e9ffad5b14c24756a0c2aeae839c9d05 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Mon, 10 Jul 2017 12:28:57 +0300 Subject: Allow multiple hostaddrs to go with multiple hostnames. Also fix two other issues, while we're at it: * In error message on connection failure, if multiple network addresses were given as the host option, as in "host=127.0.0.1,127.0.0.2", the error message printed the address twice. * If there were many more ports than hostnames, the error message would always claim that there was one port too many, even if there was more than one. For example, if you gave 2 hostnames and 5 ports, the error message claimed that you gave 2 hostnames and 3 ports. Discussion: https://www.postgresql.org/message-id/10badbc6-4d5a-a769-623a-f7ada43e14dd@iki.fi --- doc/src/sgml/libpq.sgml | 55 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index f0167a64bc9..124c21bed74 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -887,6 +887,42 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname host will be tried in turn until a connection is successfully established. + + + Specifying Multiple Hosts + + + It is possible to specify multiple hosts to connect to, so that they are + tried in the given order. In the Keyword/Value format, the host, + hostaddr, and port options accept a comma-separated + list of values. The same number of elements must be given in each option, such + that e.g. the first hostaddr corresponds to the first host name, + the second hostaddr corresponds to the second host name, and so + forth. As an exception, if only one port is specified, it + applies to all the hosts. + + + + In the connection URI format, you can list multiple host:port pairs + separated by commas, in the host component of the URI. In either + format, a single hostname can also translate to multiple network addresses. A + common example of this is a host that has both an IPv4 and an IPv6 address. + + + + When multiple hosts are specified, or when a single hostname is + translated to multiple addresses, all the hosts and addresses will be + tried in order, until one succeeds. If none of the hosts can be reached, + the connection fails. If a connection is established successfully, but + authentication fails, the remaining hosts in the list are not tried. + + + + If a password file is used, you can have different passwords for + different hosts. All the other connection options are the same for every + host, it is not possible to e.g. specify a different username for + different hosts. + @@ -900,7 +936,7 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname host - Comma-separated list of host names.host name + Name of host to connect to.host name If a host name begins with a slash, it specifies Unix-domain communication rather than TCP/IP communication; the value is the name of the directory in which the socket file is stored. If @@ -912,6 +948,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname when PostgreSQL was built). On machines without Unix-domain sockets, the default is to connect to localhost. + + A comma-separated list of host names is also accepted, in which case + each host name in the list is tried in order. See + for details. + @@ -965,6 +1006,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname ). + + A comma-separated list of hostaddrs is also accepted, in + which case each host in the list is tried in order. See + for details. + Without either a host name or host address, libpq will connect using a @@ -981,9 +1027,10 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname Port number to connect to at the server host, or socket file name extension for Unix-domain connections.port - If the host parameter included multiple, comma-separated - hosts, this parameter may specify a list of ports of equal length, - or it may specify a single port number to be used for all hosts. + If multiple hosts were given in the host or + hostaddr parameters, this parameter may specify a list + of ports of equal length, or it may specify a single port number to + be used for all hosts. -- cgit v1.2.3