global log /dev/log local0 maxconn 5000 stats socket /run/haproxy/admin.sock mode 660 level admin defaults mode tcp timeout connect 5s timeout client 30s timeout server 30s timeout check 5s log global option tcplog retries 3 listen stats bind 0.0.0.0:8404 mode http stats enable stats uri /stats stats refresh 10s stats auth admin:admin # ============================ # SCHREIBZUGRIFFE (nur Leader/Primary) # ============================ frontend postgres_write #bind *:5432 bind *:5433 # Port zum schreiben default_backend pg_leader backend pg_leader mode tcp option httpchk http-check send meth GET uri /primary ver HTTP/1.1 hdr Host localhost http-check expect status 200 default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions server pg1 pg-knoten-01:5432 check port 8008 maxconn 100 server pg2 pg-knoten-02:5432 check port 8008 maxconn 100 server pg3 pg-knoten-03:5432 check port 8008 maxconn 100 # ============================ # LESEZUGRIFFE (alle, lastverteilung) # ============================ # [~]# curl -s "http://admin:admin@localhost:8404/stats;csv" | grep -E 'pg_leader|pg_replicas' | awk -F',' '{print $2, $18, $56}' # pg1 UP -1 # pg2 DOWN -1 # pg3 DOWN -1 # BACKEND UP -1 # pg1 DOWN -1 # pg2 UP -1 # pg3 UP -1 # BACKEND UP -1 frontend postgres_read bind *:5443 # Port zum lesen #default_backend pg_replicas # bei Ausfall von 2 Knoten, kein lesen mehr möglich # # Wenn mindestens eine Replica gesund ist → Replicas use_backend pg_replicas if { nbsrv(pg_replicas) gt 0 } # # Andernfalls automatisch zum Leader default_backend pg_leader backend pg_replicas mode tcp option httpchk balance leastconn # Verteilt nach geringster Last http-check send meth GET uri /replica ver HTTP/1.1 hdr Host localhost http-check expect status 200 default-server inter 3s fall 3 rise 2 server pg1 pg-knoten-01:5432 check port 8008 maxconn 100 server pg2 pg-knoten-02:5432 check port 8008 maxconn 100 server pg3 pg-knoten-03:5432 check port 8008 maxconn 100