Telemetry
SQL recipe collection

Database reliability SQL recipes

Analyze slow query fingerprints, connection-pool pressure, transaction rollbacks, lock contention, replication lag, and migration outcomes from safe application and database-adjacent events.

Common event contract

Fields that keep these queries reusable

  • timestamp_utc, service, database_name, environment, and release
  • query_fingerprint, transaction_id, pool_name, consumer_name, and migration_id
  • duration_ms, wait_ms, lag_seconds, status, error_type, and capacity fields

Definitions before SQL

Decisions the query cannot make for you

  1. 1Normalize query operations before collection instead of storing raw SQL and parameters.
  2. 2Separate client pool wait, database execution, lock wait, and downstream replication delay.
  3. 3Tie database symptoms to an application service, release, and user-visible workflow.

Recommended sequence

Build detection first, then diagnosis

Analysis patterns

Make the result explain a decision

Instrument the client boundary

Record the safe operation fingerprint, service, final status, and phase durations where the application receives the database outcome.

Pair pressure with impact

A full pool or temporary lock becomes actionable when callers wait, time out, roll back, or fail a user-visible workflow.

Preserve rollout context

Keep release, migration, replica, and region fields so a regression can be isolated to the deployment boundary that introduced it.

Complete recipes

Copy the query, then validate the assumptions

Beginnerdatabase_query_events

Find Slow Database Queries by Fingerprint

Rank normalized database operations by slow-query rate, average duration, and worst observed duration without storing raw SQL or parameters.

Which database operations are consistently slow enough to investigate?

See SQL and result
Beginnerdatabase_pool_samples

Measure Database Connection-Pool Saturation

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

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

See SQL and result
Intermediatedatabase_transaction_events

Calculate Database Transaction Rollback Rate

Compare committed and rolled-back transactions by service while preserving error categories, duration, and affected accounts.

Which services roll back an unusual share of database transactions?

See SQL and result
Intermediatedatabase_lock_wait_events

Find Database Lock Waits and Deadlocks

Rank blocked database operation fingerprints by incident count, wait duration, unresolved locks, and detected deadlocks.

Which database operations create the most serious lock contention?

See SQL and result
Beginnerdatabase_replication_samples

Measure Database Replication and CDC Lag

Compare replica and change-data-capture consumers by average lag, worst lag, bytes behind, and stale-sample rate.

Which replicas or CDC consumers are falling behind their source database?

See SQL and result
Beginnerdatabase_migration_events

Track Database Migration Failures by Release

Compare database migration success, failure, rollback, and duration by application release before completing a rollout.

Which releases contain failed or rolled-back database migrations?

See SQL and result
Intermediatedatabase_request_query_events

Detect N+1 Database Query Patterns

Detect database fingerprints repeated many times inside one application request.

Which route and query combinations repeat suspiciously within a request?

See SQL and result

Adapt the event contract before the threshold

Keep the analysis pattern, but validate table names, field types, business definitions, time windows, and minimum-volume rules against your own events. Every published query is also planned and executed against an empty typed table with the pinned engine.