EMZETT.
Login

Connection pooling

In short: A connection pool keeps a handful of already opened database connections ready and lends them briefly to requests, instead of opening a new connection for every request.

In more detail: A new database connection costs time (network, TLS, login) and memory on the server. The pool saves that by reusing connections. If none is free, the request waits briefly in a queue.

In Depth

  • Size: Too small means waiting, too large overloads the database. A few connections per server core is a starting point.
  • Serverless: Many short-lived instances quickly exhaust the database limit. Poolers such as PgBouncer or HTTP-based drivers help there.
  • Leaks: If a connection is never returned (missing release), the pool runs dry and everything hangs.
  • Timeouts: Maximum wait and idle times prevent hanging requests.
  • Transactions: A transaction holds its connection until the end.

See also: N+1 problem