Skip to content
Telemetry
Database reliability SQL recipe

Measure database connection timeouts and churn

Compare connection opens, closes, acquisition timeouts, and affected requests by service and region.

Intermediatedatabase_connection_eventsReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . We checked the SQL syntax, required event fields, sample results, and limits on using the query. Who reviews this page

Question answered

Which services and regions show unhealthy database connection churn?

Pool saturation shows current pressure; connection lifecycle events explain whether clients are repeatedly reconnecting or timing out before work begins.

Event schema

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampConnection lifecycle event time.
serviceUtf8Application service.
regionUtf8Deployment region.
event_nameUtf8opened, closed, acquisition_timeout, or connection_error.
request_idUtf8Safe affected request identifier.
acquisition_msFloat64Pool acquisition duration when available.
DataFusion SQL

Copy the query

sql
SELECT
  service,
  region,
  SUM(CASE WHEN event_name = 'opened' THEN 1 ELSE 0 END) AS opened,
  SUM(CASE WHEN event_name = 'closed' THEN 1 ELSE 0 END) AS closed,
  SUM(CASE WHEN event_name = 'acquisition_timeout' THEN 1 ELSE 0 END)
    AS acquisition_timeouts,
  SUM(CASE WHEN event_name = 'connection_error' THEN 1 ELSE 0 END)
    AS connection_errors,
  COUNT(DISTINCT CASE
    WHEN event_name IN ('acquisition_timeout', 'connection_error') THEN request_id
  END) AS affected_requests
FROM database_connection_events
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
GROUP BY service, region
ORDER BY acquisition_timeouts DESC, connection_errors DESC;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. We review the synthetic sample output separately. Check field types, thresholds, and counting rules against your own data. Read the testing methodology.

Query result

Connection acquisition timeouts

Checkout in us-east has the highest timeout count and lifecycle volume.

serviceregionopenedclosedacquisition_timeoutsconnection_errorsaffected_requests
checkout-apius-east1,8401,7929118104
query-apieu-west62061412416

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

Connection acquisition timeouts: static chart of synthetic acquisition_timeouts values from the Measure database connection timeouts and churn example result
Download this SVG chart of the sample results for an article, runbook, or design review. Please credit Telemetry.

Reproduce the example

Download the sample data

The JSON bundle includes the event schema with field types, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1Lifecycle counts reveal reconnect churn beside timeout symptoms.
  2. 2Service and region preserve routing and ownership context.
  3. 3Affected requests keeps infrastructure activity tied to application impact.

Edge cases to check

  • Normal autoscaling creates expected opens and closes.
  • A request ID may be absent for background pool maintenance.
  • Pool metrics and database connection limits are complementary evidence.

Recommended dashboard

  • Bars: acquisition_timeouts by service
  • Trend: opened and closed by region
  • Table: affected_requests and connection errors

Alert guidance

Alert on sustained acquisition timeouts with affected requests, not normal lifecycle volume alone.

Read alert setup

Set up the events this query needs

Related instrumentation and guides

Continue the analysis

Run it on your 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