PostgresDB-Load-balancing-pooling-with-pgBouncer-HAProxy
A PostgreSQL high-availability setup combining pgBouncer for connection pooling and HAProxy for load balancing across database replicas. The configuration enables horizontal scalability by distributing client requests to multiple PostgreSQL servers through a proxy layer. Key components include pgBouncer, a lightweight connection pooler that manages and reduces PostgreSQL connection overhead. It is configured via pgbouncer.ini with database connection settings and authentication through password hashing using pgmd5. HAProxy handles load balancing using roundrobin distribution, listening on a configurable port and forwarding connections to backend PostgreSQL replica servers on port 5432. Health checks using pgsql-check ensure failed servers are automatically bypassed. The setup workflow involves installing and configuring pgBouncer with authentication, installing HAProxy and mapping replica servers, then restarting services. Testing involves running queries, taking down a replica, and confirming traffic reroute