As33
@periodic/
arsenic
connection_pool_exhaustion
🔴 Critical

Database connection pool nearing or at capacity

The connection pool is under pressure. This leads to connection timeouts, failed requests, and cascading failures. Under high load, this can bring down an entire service.

Common Causes

  • Too many concurrent requests for pool size
  • Connection leaks — connections not returned to pool
  • Slow queries holding connections too long
  • Misconfigured pool size for workload

How to Fix

  1. 1.Increase pool size in DB config
  2. 2.Investigate connection leaks
  3. 3.Add connection timeout configuration
  4. 4.Use PgBouncer or equivalent pooler

Cascading failure risk

Pool exhaustion causes all new requests to queue or timeout simultaneously. One slow upstream query can exhaust the pool and take down your entire service.

Example

typescript
// Mongoose — configure pool size
mongoose.connect(uri, {
  maxPoolSize: 20,        // Increase from default 5
  serverSelectionTimeoutMS: 5000,
  socketTimeoutMS: 45000,
});

// pg — configure pool
const pool = new Pool({
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});

Monitoring pool health

typescript
const monitor = createMonitor({
  exporter: (event) => {
    if (event.signals.includes('connection_pool_exhaustion')) {
      metrics.gauge('db.pool.utilization', event.metadata?.poolUtilization);
      if (event.metadata?.poolUtilization > 0.8) {
        alertOncall('DB pool above 80% — risk of exhaustion');
      }
    }
  },
});

// Prisma — configure pool size explicitly
const prisma = new PrismaClient({
  datasources: {
    db: { url: process.env.DATABASE_URL + '?connection_limit=20&pool_timeout=10' },
  },
});