Why HikariCP might not be enough and where PgBouncer steps in.

1. Why are Connections Expensive in PostgreSQL?

PostgreSQL forks a separate process at the operating system level for each new connection. This differs from the thread-based model of other databases like MySQL. Each idle connection consumes approximately 5–10 MB of RAM (with default work_mem; this value can be much higher for active queries).

Consequently, the math is simple:

PostgreSQL’s default max_connections value is 100. While increasing this might work in the short term, it directly increases RAM consumption and complicates PostgreSQL’s shared memory management. The correct way to scale the number of connections is to use fewer connections but use them efficiently — that’s exactly where a connection pooler comes in.