Skip to content

Commit c9c8f01

Browse files
author
avandras
committed
Describe connection options
1 parent 8d066fc commit c9c8f01

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

docs/multisite.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,19 @@ Applications should be ready to try to connect to the new primary. See 'Connect
185185
Connecting to a multisite cluster
186186
---------------------------------
187187

188-
# TODO: multi-host connstring, HAProxy (differences from a normal Patroni), possible use of vip-manager (one endpoint per site)
188+
There are multiple ways one could set up application connections to a multisite Patroni cluster. We consider here connecting to the primary instance - connections to replicas can be solved with sloght modifications.
189+
190+
1. Single IP address using HAProxy
191+
192+
This is the simplest from the application standpoint, but setting it up is the most complex of all listed solutions (extra node(s) for HAProxy itself, and `keepalived` for ensuring HAProxy's availability). Unless you need the load balancing features HAProxy provides, you should probably choose one of the other methods.
193+
194+
2. Multi-host connection strings
195+
196+
With this solution, all potential primary instances are listed in the connection string. To ensure connections land on the primary, the connection failover feature of the DB driver should be used (`targetServerType=primary` for [JDBC](https://jdbc.postgresql.org/documentation/use/#connection-fail-over), `target_session_attrs="read-write"` for [libpq](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS), `TargetSessionAttributes.Primary` for .NET's [Npgsql](https://www.npgsql.org/doc/failover-and-load-balancing.html?tabs=7)). The big advantage of this solution is that it doesn't require any extra setup on the DB side. A disadvantage can be that with many nodes (e.g. two sites with three nodes each) it can take a while to have a connection opened. This is less of a problem when using connection poolers.
197+
198+
3. Per-site endpoint IP combined with multi-host connection strings
199+
200+
[vip-manager](https://github.com/cybertec-postgresql/vip-manager/) provides a relatively easy way of maintaining a single IP address that always points to the leader of a single site. One could set it up for each site, and then use the endpoint IPs in a multi-host connection string as described above. As the number of addresses to check is less than in (2), establishing a connection is faster on average. The downside is the added complexity (vip-manager has to be installed on the Patroni nodes, and configured to pull the necessary information from DCS).
189201

190202

191203
Transforming an existing setup into multisite

0 commit comments

Comments
 (0)