Database connection pooling configuration

191
0

Properly configured connection pools prevent ActiveRecord::ConnectionTimeoutError during traffic spikes while avoiding resource waste. The pool size should match your application's concurrency needs—for Puma with 5 threads per worker, I set pool: 5 in database.yml. I also configure checkout_timeout to fail fast when the pool is exhausted rather than blocking indefinitely. In containerized environments, I calculate the total pool size across all instances to stay under the database's connection limit. The reaping_frequency setting helps recover leaked connections that weren't properly released. Monitoring active connections and pool saturation reveals whether I need to scale horizontally or tune query performance.