Telemetry
Database reliability SQL recipe

Analyze Database Errors by SQLSTATE and Release

Group database failures by portable SQLSTATE class, application operation, and release.

Beginnerdatabase_error_eventsReviewed 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 database error classes increased after an application release?

Raw error messages are unstable and may contain sensitive values. SQLSTATE plus a controlled operation name supports release comparison and routing to the correct owner.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampDatabase failure time.
database_systemUtf8Database system.
operation_nameUtf8Controlled application operation.
sqlstateUtf8Portable SQLSTATE code when available.
releaseUtf8Application release.
request_idUtf8Safe parent request identifier.
DataFusion SQL

Copy the query

sql
SELECT
  database_system,
  release,
  operation_name,
  sqlstate,
  COUNT(*) AS failures,
  COUNT(DISTINCT request_id) AS affected_requests
FROM database_error_events
WHERE timestamp_utc >= now() - INTERVAL '7 days'
GROUP BY database_system, release, operation_name, sqlstate
ORDER BY failures DESC, affected_requests 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

Database failures by SQLSTATE

Serialization failures in checkout dominate the release's database errors.

database_systemreleaseoperation_namesqlstatefailuresaffected_requests
postgresqlapi-88checkout40001184176
postgresqlapi-88project-create235056262

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

Database failures by SQLSTATE: static chart of synthetic failures values from the Analyze Database Errors by SQLSTATE and Release 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, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1SQLSTATE is safer and more stable than grouping raw error strings.
  2. 2Operation name preserves application ownership.
  3. 3Distinct requests estimates customer-facing impact.

Edge cases to decide

  • Not every driver exposes SQLSTATE consistently.
  • The same SQLSTATE can have different causes.
  • Store sanitized error categories, not full statement values or server messages.

Recommended dashboard

  • Bars: failures by SQLSTATE
  • Trend: failures by release
  • Table: affected operations and request counts

Alert guidance

Alert on a new high-volume SQLSTATE after release or a known critical class such as connection failure.

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