Postgresql – Advantages of using PgBouncer vs HAProxy

clusteringpostgresql

Are there any advantages for using one over the other? I'm only looking at options to hide the actual IP address of the master and slave servers from my processes, and not having to restart them if the master fails.

If Nagios detects a failing master, I still want to get involved to do the failover, including telling HAproxy / PgBouncer about the new master.

Best Answer

HAProxy is a low lewel high availability and load balancing solution. PgBouncer combines a very good connection pooler and a very limited load balancing for PostgreSQL.

So both has different goals and can not be compared like "vs" in my opinion. Though they can be used in a combination with each other, eg. if one needs to load balance read only queries between several replicas with HAProxy and these replicas are served by their own PgBouncer instances to get pooling advantages.

More about what PgBouncer is and what it is not in is perfectly described in this blog post.