DEV Community

Ahmed ElFirgany
Ahmed ElFirgany

Posted on

How do you size a database connection pool?

Traffic went up a little, and the database started refusing connections. The app server itself was fine.

The cause was simple. Every request opened a new connection, and the database has a hard limit.

A pool removes the opening cost. The harder part is the number. One rule holds up well. Add up every pool in every process, and keep the total under max_connections. Leave room for migrations and admin tools.

So with 4 workers and a limit of 100, each pool gets about 20, not 50.

How do you pick yours: a load test, a formula, or small pools you grow?

60-second version, Arabic voice-over with English terms: https://youtube.com/shorts/aKlQrHIGmZ4

Top comments (0)