Add to your .env file:
# Basic Configuration (Development)
DATABASE_POOL_MAX=5
DATABASE_POOL_MIN=1
DATABASE_IDLE_TIMEOUT=30000
DATABASE_CONNECTION_TIMEOUT=10000
# Production Configuration
# DATABASE_POOL_MAX=20
# DATABASE_POOL_MIN=5
# DATABASE_IDLE_TIMEOUT=30000
# DATABASE_CONNECTION_TIMEOUT=10000
# DATABASE_ACQUIRE_TIMEOUT=60000npm run start:devConnection pooling is automatically enabled!
Check pool health:
curl http://localhost:3000/database/pool/healthExpected response:
{
"healthy": true,
"stats": {
"totalConnections": 5,
"activeConnections": 1,
"idleConnections": 4,
"waitingRequests": 0,
"utilizationPercent": 20,
"timestamp": "2024-01-01T00:00:00.000Z"
}
}Get current stats:
curl http://localhost:3000/database/pool/statsGet average utilization:
curl http://localhost:3000/database/pool/utilization?minutes=5npm run test -- connection-pool.load.spec.tsYour database now has:
- ✅ Connection pooling enabled
- ✅ Automatic monitoring
- ✅ Circuit breaker protection
- ✅ Health check endpoints
Increase DATABASE_POOL_MAX in .env
Decrease DATABASE_POOL_MIN in .env
See CONNECTION_POOLING_README.md
- Health:
GET /database/pool/health - Stats:
GET /database/pool/stats - History:
GET /database/pool/stats/recent?count=10 - Utilization:
GET /database/pool/utilization?minutes=5 - Circuit Breaker:
GET /database/pool/circuit-breaker
| Environment | MAX | MIN |
|---|---|---|
| Development | 5 | 1 |
| Staging | 15 | 2 |
| Production | 20 | 5 |
| High-Load | 50 | 10 |
Questions? Check the docs: