How it works...
This recipe is essentially a mild reconfiguration of both HAProxy and PgBouncer. We start by reconfiguring HAProxy to bind to port 5433 rather than our earlier recommendation of 5432. We do this because HAProxy isn't going to be the only component between the application and the PostgreSQL nodes.
Next, we have to slightly modify two sections of the pgbouncer.ini file in order to work with HAProxy. Rather than configuring which backend PgBouncer connects to, we simply connect to the HAProxy node itself. This can either be the local server or the hostname of the proxy server; either way, PgBouncer should no longer directly contact any PostgreSQL nodes.
The connection target should always be handled by HAProxy since it can automatically ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access