---
title: "Examine query samples | Database Observability documentation"
description: "Review actual query executions with their parameters, timing, and context."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# Examine query samples

Query samples capture actual query executions from your database, including the specific execution time, duration, and associated wait events. Use samples to understand real-world query behavior and identify patterns that aggregated metrics might miss.

## What query samples capture

Unlike aggregated metrics that show averages and totals, query samples capture individual query executions. Both MySQL and PostgreSQL samples include the timestamp, duration, database/schema, CPU time, wait events, and full query text (shown when [redaction is disabled](#view-full-query-text)). Beyond these shared fields, each engine provides additional details.

### MySQL samples

MySQL samples include resource and row-level metrics from `Performance Schema`:

Expand table

| Field                 | Description                             |
|-----------------------|-----------------------------------------|
| Rows examined         | Number of rows scanned during execution |
| Rows sent             | Number of rows returned to the client   |
| Rows affected         | Number of rows modified                 |
| Errors                | Error count                             |
| Max controlled memory | Controlled memory used by the query     |
| Max total memory      | Total memory used by the query          |

### PostgreSQL samples

PostgreSQL samples include connection and process context from `pg_stat_activity`:

Expand table

| Field                | Description                                   |
|----------------------|-----------------------------------------------|
| Transaction time     | Duration of the enclosing transaction         |
| User                 | Which database user ran the query             |
| Backend type         | Type of backend process                       |
| Client               | Client address                                |
| Process ID           | Backend process ID                            |
| State                | Query state when sampled (active, idle, etc.) |
| Leader PID           | Leader process ID for parallel queries        |
| Transaction ID (Xid) | Transaction identifier                        |
| Xmin horizon         | Xmin snapshot value                           |

## Why query samples matter

Aggregated metrics can hide important patterns:

- **Bimodal distributions**: A query might usually take 10ms but occasionally take 10 seconds
- **Parameter-specific issues**: Certain parameter values might cause slow execution
- **Time-based patterns**: Performance might degrade during specific time windows
- **Correlation with events**: You can match slow queries with application events

## Access query samples

To view samples for a query:

1. Navigate to **Database Observability** in Grafana Cloud.
2. In **Queries Overview**, click a query to open its details.
3. Select the **Query Samples** tab.
4. View the time series chart and sample list.

### Time series visualization

The Query Samples tab shows a chart of sample executions over time:

- **X-axis**: Time
- **Y-axis**: Query duration
- **Points**: Individual query executions

Hover over a point to see a tooltip with sample details. The fields shown vary by database engine — refer to the [table above](#what-query-samples-capture) for the full list. Click a sample to select it and view the full query text (when redaction is disabled).

## View full query text

By default, Database Observability redacts query parameters for security:

**Redacted:**

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT * FROM users WHERE email = ?
```

**Full text (when redaction disabled):**

SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```sql
SELECT * FROM users WHERE email = 'user@example.com'
```

To enable full query text including parameters:

1. **For MySQL**, configure Alloy:

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
database_observability.mysql "default" {
  query_samples {
    disable_query_redaction = true
  }
}
```

2. **For PostgreSQL**, configure Alloy:

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
database_observability.postgres "default" {
  query_samples {
    disable_query_redaction = true
  }
}
```

> Warning
> 
> Disabling redaction exposes actual query parameters in logs. Only enable this in environments where parameter values don’t contain sensitive data, or ensure appropriate access controls are in place.

## Configure sample collection

You can adjust how query samples are collected, including collection intervals, query redaction settings, and which users to exclude. For all configuration options, refer to [Tune Alloy collection](/docs/grafana-cloud/monitor-applications/database-observability/configure/tune-alloy-collection/#query_samples).

## Related documentation

- [Understand wait events](/docs/grafana-cloud/monitor-applications/database-observability/investigate/understand-wait-events/): Interpret wait event data
- [Analyze explain plans](/docs/grafana-cloud/monitor-applications/database-observability/investigate/analyze-explain-plans/): Understand query execution
- [Tune Alloy collection](/docs/grafana-cloud/monitor-applications/database-observability/configure/tune-alloy-collection/): Configure sample collection
- [Find application queries](/docs/grafana-cloud/monitor-applications/database-observability/monitor/find-application-queries/): Correlate with traces
- [Troubleshoot](/docs/grafana-cloud/monitor-applications/database-observability/troubleshoot/): Resolve setup and configuration issues
