hi,
I am trying to do a haproxy setup with PostgreSQL and Patroni. Following is my configuration.
global
log stdout local0 info
defaults
log global
mode http
option httplog
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
listen stats
mode http
bind *:7000
stats enable
stats uri /
listen pgReadWrite
bind *:5000
option pgsql-check user postgres
default-server inter 3s fall 3
server is1 is1:5432 check port 5432
server is2 is2:5432 check port 5432
listen pgReadOnly
bind *:5001
option pgsql-check user postgres
default-server inter 3s fall 3
server is1 is1:5432 check port 5432
server is2 is2:5432 check port 5432
When I execute psql command with -p 5000/5001 option it is not returning any error/success. Also I am not able to get log from haproxy whether the DB connection is proper. Is there any way to update the log level(to get more logs) in order to debug this issue? thank you for the support in advance.
The default works for most systems:
global
log /dev/log local0
log /dev/log local1 notice
On Debian, this outputs to /var/log/haproxy.log
.
thank you for the update. I am using haproxy with postgreSQL and getting following error when trying to connect using
$ psql -h localhost -p 5000 -U postgres
psql: error: received invalid response to SSL negotiation: H
Following log is observed from haproxy.
<134>Feb 9 07:50:26 haproxy[189356]: 127.0.0.1:56212 [09/Feb/2023:07:50:26.604] pgReadWrite pgReadWrite/ -1/-1/-1/-1/0 400 211 - - PR-- 1/1/0/0/3 0/0 “”
Any information on this error will be helpful.
PR--
means that HAProxy blocked/denied your request. In TCP mode, this might mean that your servers are not healthy. Do you have additional logs from starting HAProxy that show if is1
and is2
are healthy?
PR The proxy blocked the client's HTTP request, either because of an
invalid HTTP syntax, in which case it returned an HTTP 400 error to
the client, or because a deny filter matched, in which case it
returned an HTTP 403 error. It may also be due to an HTTP header
rewrite failure on the request. In this case, an HTTP 500 error is
sent (see "tune.maxrewrite" and "http-request strict-mode" for more
inforomation).
Source: HAProxy version 2.6.8-4 - Configuration Manual - Session state at disconnection
thank you for the explanation.
I commented out ‘mode http’ in the defaults section and it starts connecting like below.
[core@is1 ~]$ psql -U postgres -h 127.0.0.1 -p 5001
psql (13.7)
Type “help” for help.
postgres=#
Didn’t understand why http request is blocking connection to PostgreSQL ?
Short answer: because PostgreSQL doesn’t speak HTTP. It’s is like pointing a browser at Postgres. Databases cannot respond directly to HTTP requests. They need an application to do that.