HAProxy with SQL2019 AlwaysOn

Hello,

I tried to make a config with MS SQL 2019 Always On.
I have 2 SQL nodes in my cluster Always On, and I Have multiples Always On groups.
IP xx.xx.xx.248 is for one listener in one of my Always On group.
IP xx.xx.xx.11 and 12 are my two nodes.

Here is my config :

global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 6000
user haproxy
group haproxy
daemon
stats socket /var/run/haproxy.sock mode 666 level admin
stats timeout 2m

defaults
mode http
log global
option dontlognull
option http-server-close
option redispatch
retries 3
timeout http-request 10s
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 6000

frontend sqldev
bind xx.xx.xx.248:1433
mode tcp
use_backend sqldev

backend sqldev
mode tcp
option log-health-checks
option redispatch
log global
balance roundrobin
timeout connect 10s
timeout server 1m
server DEVSQL1 xx.xx.xx.11:1433 check
server DEVSQL2 xx.xx.xx.12:1433 check

At this step, my connexions are redirected to my secondary node in read only :frowning: I don’t know how to redirect the write connexions only to the primary server and the read connexion to one of this two nodes.

I think HAProxy doesn’t know which is the primary node.

What is the good configuration to work with SQL 2019 Always On groups and listener ?

Thanks