@@ -756,8 +756,10 @@ PGPing PQping(const char *conninfo);
756
756
Several <application>libpq</> functions parse a user-specified string to obtain
757
757
connection parameters. There are two accepted formats for these strings:
758
758
plain <literal>keyword = value</literal> strings
759
- and <ulink url="http://www.ietf.org/rfc/rfc3986.txt">RFC
760
- 3986</ulink> URIs.
759
+ and URIs. URIs generally follow
760
+ <ulink url="http://www.ietf.org/rfc/rfc3986.txt">RFC
761
+ 3986</ulink>, except that multi-host connection strings are allowed
762
+ as further described below.
761
763
</para>
762
764
763
765
<sect3>
@@ -792,7 +794,7 @@ host=localhost port=5432 dbname=mydb connect_timeout=10
792
794
<para>
793
795
The general form for a connection <acronym>URI</acronym> is:
794
796
<synopsis>
795
- postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]
797
+ postgresql://[user[:password]@][netloc][:port][,...][ /dbname][?param1=value1&...]
796
798
</synopsis>
797
799
</para>
798
800
@@ -809,6 +811,7 @@ postgresql://localhost/mydb
809
811
postgresql://user@localhost
810
812
postgresql://user:secret@localhost
811
813
postgresql://other@localhost/otherdb?connect_timeout=10&application_name=myapp
814
+ postgresql://host1:123,host2:456/somedb
812
815
</programlisting>
813
816
Components of the hierarchical part of the <acronym>URI</acronym> can also
814
817
be given as parameters. For example:
@@ -856,6 +859,15 @@ postgresql:///dbname?host=/var/lib/postgresql
856
859
postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
857
860
</programlisting>
858
861
</para>
862
+
863
+ <para>
864
+ It is possible to specify multiple host components, each with an optional
865
+ port component, in a single URI. A URI of the form
866
+ <literal>postgresql://host1:port1,host2:port2,host3:port3/</literal>
867
+ is equivalent to a connection string of the form
868
+ <literal>host=host1,host2,host3 port=port1,port2,port3</literal>. Each
869
+ host will be tried in turn until a connection is successfully established.
870
+ </para>
859
871
</sect3>
860
872
</sect2>
861
873
@@ -870,12 +882,13 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
870
882
<term><literal>host</literal></term>
871
883
<listitem>
872
884
<para>
873
- Name of host to connect to .<indexterm><primary>host name</></>
874
- If this begins with a slash, it specifies Unix-domain
885
+ Comma-separated list of host names .<indexterm><primary>host name</></>
886
+ If a host name begins with a slash, it specifies Unix-domain
875
887
communication rather than TCP/IP communication; the value is the
876
- name of the directory in which the socket file is stored. The
877
- default behavior when <literal>host</literal> is not specified
878
- is to connect to a Unix-domain
888
+ name of the directory in which the socket file is stored. If
889
+ multiple host names are specified, each will be tried in turn in
890
+ the order given. The default behavior when <literal>host</literal> is
891
+ not specified is to connect to a Unix-domain
879
892
socket<indexterm><primary>Unix domain socket</></> in
880
893
<filename>/tmp</filename> (or whatever socket directory was specified
881
894
when <productname>PostgreSQL</> was built). On machines without
@@ -950,6 +963,9 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
950
963
Port number to connect to at the server host, or socket file
951
964
name extension for Unix-domain
952
965
connections.<indexterm><primary>port</></>
966
+ If the <literal>host</> parameter included multiple, comma-separated
967
+ hosts, this parameter may specify a list of ports of equal length,
968
+ or it may specify a single port number to be used for all hosts.
953
969
</para>
954
970
</listitem>
955
971
</varlistentry>
@@ -1394,7 +1410,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
1394
1410
1395
1411
<para>
1396
1412
The following functions return parameter values established at connection.
1397
- These values are fixed for the life of the <structname>PGconn</> object.
1413
+ These values are fixed for the life of the connection. If a multi-host
1414
+ connection string is used, the values of <function>PQhost</>,
1415
+ <function>PQport</>, and <function>PQpass</> can change if a new connection
1416
+ is established using the same <structname>PGconn</> object. Other values
1417
+ are fixed for the lifetime of the <structname>PGconn</> object.
1398
1418
1399
1419
<variablelist>
1400
1420
<varlistentry id="libpq-pqdb">
0 commit comments