diff --git a/roles/haproxy/templates/haproxy.cfg.j2 b/roles/haproxy/templates/haproxy.cfg.j2 index 98b64da17..2e74ba765 100644 --- a/roles/haproxy/templates/haproxy.cfg.j2 +++ b/roles/haproxy/templates/haproxy.cfg.j2 @@ -116,3 +116,35 @@ server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hos {% endfor %} {% endif %} +{% if with_haproxy_direct_connections|bool and pgbouncer_install|bool %} +listen master_direct +{% if cluster_vip is defined and cluster_vip | length > 0 %} + bind {{ cluster_vip }}:{{ haproxy_listen_port.master_direct }} +{% else %} + bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.master_direct }} +{% endif %} + maxconn {{ haproxy_maxconn.master }} + option tcplog + option httpchk OPTIONS /primary + http-check expect status 200 + default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions + {% for host in groups['postgres_cluster'] %} +server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }} + {% endfor %} + +listen replicas_direct +{% if cluster_vip is defined and cluster_vip | length > 0 %} + bind {{ cluster_vip }}:{{ haproxy_listen_port.replicas_direct }} +{% else %} + bind {{ hostvars[inventory_hostname]['inventory_hostname'] }}:{{ haproxy_listen_port.replicas_direct }} +{% endif %} + maxconn {{ haproxy_maxconn.replica }} + option tcplog + option httpchk OPTIONS /replica + balance roundrobin + http-check expect status 200 + default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions + {% for host in groups['postgres_cluster'] %} +server {{ hostvars[host]['ansible_hostname'] }} {{ hostvars[host]['inventory_hostname'] }}:{{ postgresql_port }} check port {{ patroni_restapi_port }} + {% endfor %} +{% endif %} diff --git a/vars/main.yml b/vars/main.yml index dc7e2a758..483843bf6 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -28,11 +28,14 @@ synchronous_node_count: 1 # number of synchronous standby databases # Load Balancing with_haproxy_load_balancing: false # or 'true' if you want to install and configure the load-balancing +with_haproxy_direct_connections: false # or 'true' if you want to enable haproxy ports that skip pgbouncer (and if pgbouncer_install is 'true') haproxy_listen_port: master: 5000 + master_direct: 6000 replicas: 5001 replicas_sync: 5002 replicas_async: 5003 + replicas_direct: 6001 stats: 7000 haproxy_maxconn: global: 100000