Grafana Cloud

Understand wait events

Wait events show where your queries spend time waiting for resources instead of actively executing. Understanding wait events helps you identify resource contention, lock conflicts, and I/O bottlenecks that cause performance problems.

What are wait events

When a query executes, it alternates between:

  • Active execution: CPU is processing the query
  • Waiting: Query is blocked, waiting for a resource

Wait events capture what the query is waiting for. High wait times indicate that queries are spending significant time blocked rather than executing.

Why wait events matter

Wait events reveal performance problems that other metrics miss:

ProblemWhat metrics showWhat wait events reveal
Lock contentionHigh query durationQueries waiting for row/table locks
Disk I/O bottleneckSlow queriesQueries waiting for disk reads
Connection pool exhaustionTimeoutsQueries waiting for connections
Shared buffer contentionMemory pressureQueries waiting for buffer access

Access wait events

To view wait events in Database Observability:

  1. Navigate to Database Observability in Grafana Cloud.
  2. In the Queries Overview, note the Wait Events Duration chart showing cumulative wait time.
  3. Click a query to open its details.
  4. Select the Wait Events tab for detailed analysis.

Overview dashboard wait events

The Queries Overview shows a bar chart of cumulative wait event duration by category. This gives you a quick view of where queries spend the most time waiting.

The overview chart groups individual wait event types into high-level categories for easier visualization:

PostgreSQL categories:

CategoryIncluded wait event types
IO WaitIO
Lock WaitLock, LWLock, Activity, Extension, InjectionPoint, IPC, Timeout, BufferPin. This broad category covers heavyweight locks, lightweight locks, and other synchronization or blocking waits.
Network WaitClient

MySQL categories:

CategoryIncluded wait event patterns
IO Waitwait/io/file/*, wait/io/table/*
Lock Waitwait/lock/*, wait/synch/*, wait/io/lock/*
Network Waitwait/io/socket/*

Wait Events tab

The Wait Events tab shows a time series chart of wait events for a specific query. Use the dropdown to switch between four views:

  • Cumulative duration of wait events (by group): Stacked bars showing total wait time for each category (IO Wait, Lock Wait, Network Wait) over time. This is the default view.
  • Cumulative duration of wait events (breakdown): Stacked bars broken down by individual wait event name (for example, Lock:relation, IO:DataFileRead), giving a more granular picture.
  • Number of wait events: Count of wait events by category over time.
  • Wait events duration (by group): Average duration per event by category over time.

Use wait events for diagnosis

This workflow shows how to use wait events to narrow down the source of latency.

Workflow: Diagnose slow queries

  1. Identify affected queries: In the Queries Overview, find queries with high wait event duration.
  2. View wait events tab: Click the query and open the Wait Events tab.
  3. Compare views: Use the dropdown to switch between cumulative duration, event count, and average duration to understand the wait pattern.
  4. Drill into duration of wait events (breakdown): Switch to the breakdown view to see which specific wait events contribute the most time.
  5. Take action: Apply fixes based on the dominant wait event type (refer to the tips below).

The following table lists common scenarios you may encounter:

ScenarioWait patternAction
Database backup runningHigh I/O waitsSchedule backups during low-traffic periods
Large transactionLock waits increasingBreak into smaller transactions
Peak trafficMultiple wait types elevatedScale resources or optimize queries
New deploymentLock waits on specific tablesCheck for schema changes, new queries

Tips for addressing wait events

Use these tips to address the most common wait event patterns.

Lock contention

  • Review transaction isolation levels
  • Consider optimistic locking patterns
  • Break long transactions into smaller units
  • Check for deadlock patterns

I/O contention

  • Add indexes to reduce table scans
  • Increase memory/buffer pools
  • Review disk performance
  • Consider read replicas for read-heavy workloads

Buffer contention

  • Tune shared buffer settings
  • Review concurrent access patterns
  • Consider connection pooling adjustments