Skip to content

Commit

Permalink
haproxy: enable direct connections apart from pgbouncer ones (vitabak…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimnydev committed Jan 10, 2024
1 parent 05475e1 commit 73879bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions roles/haproxy/templates/haproxy.cfg.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 73879bb

Please sign in to comment.