@@ -887,6 +887,42 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
887
887
host will be tried in turn until a connection is successfully established.
888
888
</para>
889
889
</sect3>
890
+
891
+ <sect3 id="libpq-multiple-hosts">
892
+ <title>Specifying Multiple Hosts</title>
893
+
894
+ <para>
895
+ It is possible to specify multiple hosts to connect to, so that they are
896
+ tried in the given order. In the Keyword/Value format, the <literal>host</>,
897
+ <literal>hostaddr</>, and <literal>port</> options accept a comma-separated
898
+ list of values. The same number of elements must be given in each option, such
899
+ that e.g. the first <literal>hostaddr</> corresponds to the first host name,
900
+ the second <literal>hostaddr</> corresponds to the second host name, and so
901
+ forth. As an exception, if only one <literal>port</literal> is specified, it
902
+ applies to all the hosts.
903
+ </para>
904
+
905
+ <para>
906
+ In the connection URI format, you can list multiple <literal>host:port</> pairs
907
+ separated by commas, in the <literal>host</> component of the URI. In either
908
+ format, a single hostname can also translate to multiple network addresses. A
909
+ common example of this is a host that has both an IPv4 and an IPv6 address.
910
+ </para>
911
+
912
+ <para>
913
+ When multiple hosts are specified, or when a single hostname is
914
+ translated to multiple addresses, all the hosts and addresses will be
915
+ tried in order, until one succeeds. If none of the hosts can be reached,
916
+ the connection fails. If a connection is established successfully, but
917
+ authentication fails, the remaining hosts in the list are not tried.
918
+ </para>
919
+
920
+ <para>
921
+ If a password file is used, you can have different passwords for
922
+ different hosts. All the other connection options are the same for every
923
+ host, it is not possible to e.g. specify a different username for
924
+ different hosts.
925
+ </para>
890
926
</sect2>
891
927
892
928
<sect2 id="libpq-paramkeywords">
@@ -900,7 +936,7 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
900
936
<term><literal>host</literal></term>
901
937
<listitem>
902
938
<para>
903
- Comma-separated list of host names .<indexterm><primary>host name</></>
939
+ Name of host to connect to .<indexterm><primary>host name</></>
904
940
If a host name begins with a slash, it specifies Unix-domain
905
941
communication rather than TCP/IP communication; the value is the
906
942
name of the directory in which the socket file is stored. If
@@ -912,6 +948,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
912
948
when <productname>PostgreSQL</> was built). On machines without
913
949
Unix-domain sockets, the default is to connect to <literal>localhost</>.
914
950
</para>
951
+ <para>
952
+ A comma-separated list of host names is also accepted, in which case
953
+ each host name in the list is tried in order. See
954
+ <xref linkend="libpq-multiple-hosts"> for details.
955
+ </para>
915
956
</listitem>
916
957
</varlistentry>
917
958
@@ -965,6 +1006,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
965
1006
<xref linkend="libpq-pgpass">).
966
1007
</para>
967
1008
1009
+ <para>
1010
+ A comma-separated list of <literal>hostaddrs</> is also accepted, in
1011
+ which case each host in the list is tried in order. See
1012
+ <xref linkend="libpq-multiple-hosts"> for details.
1013
+ </para>
968
1014
<para>
969
1015
Without either a host name or host address,
970
1016
<application>libpq</application> will connect using a
@@ -981,9 +1027,10 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
981
1027
Port number to connect to at the server host, or socket file
982
1028
name extension for Unix-domain
983
1029
connections.<indexterm><primary>port</></>
984
- If the <literal>host</> parameter included multiple, comma-separated
985
- hosts, this parameter may specify a list of ports of equal length,
986
- or it may specify a single port number to be used for all hosts.
1030
+ If multiple hosts were given in the <literal>host</literal> or
1031
+ <literal>hostaddr</> parameters, this parameter may specify a list
1032
+ of ports of equal length, or it may specify a single port number to
1033
+ be used for all hosts.
987
1034
</para>
988
1035
</listitem>
989
1036
</varlistentry>
0 commit comments