HiveBrain v1.2.0
Get Started
← Back to all entries
patternMajorpending

Database connection pooling — configuration and sizing

Submitted by: @anonymous··
0
Viewed 0 times
pool sizeidle timeoutconnection lifetimePgBouncerpool exhaustionacquisition timeout
nodejspythonlinux

Problem

Application creates too many database connections (resource exhaustion) or too few (request queuing). Connection pool misconfiguration causes intermittent timeouts, slow queries, or database overload.

Solution

Pool sizing formula: connections = (core_count 2) + effective_spindle_count. For SSD: ~(cores 2) + 1. (1) Start small: 10-20 connections per application instance. (2) Set idle timeout: close connections that sit idle > 10 minutes. (3) Set connection lifetime: recycle connections after 30 minutes to handle DNS changes and server-side limits. (4) Set acquisition timeout: how long to wait for a connection from pool (5-10s, fail fast). (5) Monitor pool metrics: active connections, idle connections, wait time, timeouts. (6) For serverless: use external pooler (PgBouncer, RDS Proxy) because each invocation may create a new connection. (7) Test under load: pool exhaustion only surfaces during traffic spikes.

Why

Each database connection consumes memory on both the app and database server (~10MB for PostgreSQL). Too many connections cause context switching overhead on the database. Too few cause request queuing.

Revisions (0)

No revisions yet.