PostgreSQL (Patroni, HAProxy, or external load balancer) configuration

Scenario

A cluster of PostgreSQL nodes is managed by Patroni, and is typically accessed through a load balancer (LB) or a virtual IP (VIP).

Best practice

Use a validation query to ensure that the connection has not been silently interrupted by the load balancer. The following example shows the XML configuration:

<dataSource id="twsdb" jndiName="jdbc/twsdb">
                <connectionManager 
                minPoolSize="5" 
                maxPoolSize="50" 
                preTestConnection="true"/>
                <properties.postgresql 
                serverName="pg-load-balancer.example.com" 
                portNumber="5432" 
                databaseName="TWS"/>
                </dataSource>
Note: For PostgreSQL databases accessed by using a load balancer, always set the agedTimeout property in the connectionManager element to a value lower than the idle timeout of the load balancer. For example, if the load balancer timeout is 30 minutes, set agedTimeout="25m".