Connection Pool Configuration
Each service has a configured connection pool size based on its workload. Set viaDB_MAX_CONNS and DB_MIN_CONNS environment variables per service.
Connection Budget Formula
Tuning
Ifdb_pool_active_connections exceeds 80% of MaxConns or db_pool_acquire_duration_seconds p99 exceeds 1s:
- Check if queries are slow (see Statement Timeout Runbook below)
- Increase
DB_MAX_CONNSfor the affected service - Recalculate connection budget to ensure it stays under
max_connections - If total budget exceeds PostgreSQL limits, deploy PgBouncer
Statement Timeouts
Per-service statement timeouts prevent runaway queries from holding connections. Set viaDB_STATEMENT_TIMEOUT environment variable.
When a query exceeds the timeout, PostgreSQL cancels it and returns error code
57014. The application logs the timeout and the request fails with an appropriate error.
Adjusting timeouts: If legitimate queries are timing out, investigate the root cause before increasing the timeout. See the Statement Timeout Runbook below.
PostgreSQL Configuration Requirements
pg_stat_statements (Required)
Enable in PostgreSQL configuration:Slow Query Logging
Query Performance SLOs (p95)
Application-Side Metrics
The following Prometheus metrics are automatically emitted by all services via the shared database connection setup:Alert Thresholds
Statement Timeout Runbook
When statement timeouts trigger frequently:-
Identify the query: Check
hoodcloud_db_statement_timeout_totalmetric labels for the service. Cross-reference withpg_stat_statementsfor recently degraded queries. -
Check for lock contention:
Health evaluator batch updates and API server reads can contend.
-
Check for table bloat:
The
nodesandnode_health_statetables are high-write and bloat-prone. -
Check for missing indexes:
Run
EXPLAIN ANALYZEon the timed-out query. Verify indexes exist on all JOIN and WHERE columns. -
Check for data growth: If node count has grown significantly,
ListSnapshotsmay need pagination or the health evaluator’s statement timeout may need adjustment. -
Temporary mitigation: If a single runaway query is causing cascading timeouts, identify and
pg_cancel_backend()it. Do NOT increase statement timeouts without understanding root cause. - Escalation: If timeouts persist after steps 1-6, this may indicate the scale trigger for PgBouncer or a health read replica.