Telemetry
Database reliability SQL recipe

Measure Database Connection-Pool Saturation

Measure average pool utilization, queued acquisition waits, timeouts, and idle capacity by application service.

Beginnerdatabase_pool_samplesReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . SQL compatibility, event contract, synthetic output, and operational caveats. Editorial ownership

Question answered

Which application pools are making callers wait for a database connection?

A full pool is not automatically unhealthy, but sustained utilization plus queued callers and acquisition timeouts is a strong sign that database access is delaying application work.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampPool sample time in UTC.
serviceUtf8Application service that owns the pool.
pool_nameUtf8Stable logical pool name.
active_connectionsInt64Connections currently checked out.
idle_connectionsInt64Open connections currently idle.
max_connectionsInt64Configured maximum pool size.
wait_msFloat64Observed connection-acquisition wait for this sample.
timed_outBooleanWhether acquisition exceeded the client timeout.
environmentUtf8Deployment environment.
DataFusion SQL

Copy the query

sql
SELECT
  service,
  pool_name,
  COUNT(*) AS samples,
  100.0 * AVG(active_connections)
    / NULLIF(MAX(max_connections), 0) AS average_utilization_pct,
  SUM(CASE WHEN wait_ms > 0 THEN 1 ELSE 0 END) AS waited_samples,
  100.0 * SUM(CASE WHEN wait_ms > 0 THEN 1 ELSE 0 END)
    / NULLIF(COUNT(*), 0) AS wait_rate_pct,
  AVG(wait_ms) AS average_wait_ms,
  SUM(CASE WHEN timed_out THEN 1 ELSE 0 END) AS timeouts
FROM database_pool_samples
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
  AND environment = 'production'
GROUP BY service, pool_name
HAVING COUNT(*) >= 10
ORDER BY wait_rate_pct DESC, average_utilization_pct DESC;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.

Query result

Connection acquisition wait rate

Checkout callers wait in two-thirds of the samples and also experience acquisition timeouts.

servicepool_namesamplesaverage_utilization_pctwaited_sampleswait_rate_pctaverage_wait_mstimeouts
checkout-apiprimary1289.17866.67118.752
analytics-apireporting1245433.3312.50

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

Connection acquisition wait rate: static chart of synthetic wait_rate_pct values from the Measure Database Connection-Pool Saturation example result
Indexable SVG of the deterministic example output. Download it for an article, runbook, or design review with attribution.

Reproduce the example

Download the public fixture

The JSON bundle includes the typed event contract, reproducible input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1Average utilization provides capacity context but is not used alone as a failure signal.
  2. 2The waited-sample rate shows how frequently callers encounter contention even when the wait remains short.
  3. 3Timeouts remain explicit because an average can hide a smaller set of requests that never acquire a connection.

Edge cases to decide

  • Sampling frequency must remain stable before comparing rates across services.
  • Serverless concurrency can create many independent pools; include an instance or runtime dimension when aggregation would hide that shape.
  • Increasing pool size can move contention into the database. Check database capacity before changing the client limit.

Recommended dashboard

  • Bars: wait_rate_pct and average_utilization_pct by service
  • Trend: active, idle, and waiting connections
  • Stat: connection-acquisition timeouts

Alert guidance

Alert when wait rate and timeouts remain elevated across consecutive samples, then validate database capacity before increasing the pool.

Read alert setup

Put the recipe to work

Related instrumentation and guides

Continue the analysis

Run it on real events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key