I have made a setup of multi-master replication of PostgreSQL using BDR (Bi-Directional Replication) among 4 nodes (virtual machines).
Now i want to put a load-balancer for High Availability. For this i have installed and configured "HAProxy" on a different virtual machine, which is listening over 5432/tcp to connect. The haproxy configuration is as follows:
listen pgsql_bdr *:5432
mode tcp
option httpchk
balance roundrobin
server master 192.168.123.1:5432 check backup
server slave1 192.168.123.2:5432 check
server slave2 192.168.123.3:5432 check
server slave3 192.168.123.4:5432 check
The ip address of HAProxy server is 192.168.123.5
I have use the IP address of HAproxy server in my application to connect with the database (that must redirect the connection to actual database servers). But at that time i am getting following error:
Error connecting to the server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.
And note that i have try to resolve the problem using 2 manner. 1st I disabled the firewall on all servers (HAProxy and all postgres servers) and also i try to replace configuration with the following:
listen pgsql_bdr 0.0.0.0:5432
or
listen pgsql_bdr 127.0.0.1:5432
or
listen pgsql_bdr localhost:5432
But all was not working in my case.
Please help me to solve the problem. what i am doing wrong in this scenario?
Thanks in advance!
Check your haproxy
/stats
, I am guessing that all backends are marked down, due to wrong check - postgres probably won't respond with 200 -option httpchk
. Use pgsql-checkAlso I am not aware of BDR requirements/limitations, but it is common in slaves setups, to have some pooler e.g. pgbouncer - next to client, or in front of each backend, or whatever that is needed.
edit
To check stats you can use stats socket:
As I tested with postgres 9.4, (some slaves, no BDR), haproxy 1.5.14, no checks
And I was able to connect without any issue:
Queries are running, data is coming, seems OK.
But again, I'm not able to test BDR at the moment.
Thanks to all. I have solved the problem by executing the following command:
sudo setsebool -P haproxy_connect_any=1