Top SQL
The Top SQL panel displays the top 10 SQL queries observed in ASH samples during the selected time window, ranked by various dimensions. It helps you identify which queries are consuming the most resources or executing most frequently.
{screenshot: ash-top-sql-panel}
Ranking Dimensions
Use the tabs at the top of the panel to switch the ranking criterion:
| Tab | Ranks by | Use Case |
|---|---|---|
| Executions | Number of times the query appeared in ASH samples | Identify most frequently running queries |
| Total Time | Cumulative time across all samples | Identify queries consuming the most total database time |
| Average Time | Average time per sample occurrence | Identify consistently slow individual executions |
| Wait Events | Number of samples with a non-CPU wait | Identify queries blocked on waits most often |
{screenshot: ash-top-sql-tabs}
Table Columns
| Column | Description |
|---|---|
| Rank | Position in the current ranking |
| Query | Truncated SQL text (hover or click to expand) |
| Database | Database where the query was executed |
| User | PostgreSQL user who executed the query |
| Executions | Number of ASH samples capturing this query |
| Total Time (s) | Cumulative time this query appeared in samples |
| Avg Time (s) | Average time per sample occurrence |
| Top Wait Event | Most frequent wait event observed for this query |
Query Text
SQL text is truncated in the table for readability. Click on any row to expand the full query text in a detail panel.
{screenshot: ash-top-sql-query-expand}
Query text is normalized — literal values (numbers, strings) are replaced with placeholders, so queries with the same structure but different parameters are grouped together.
Correlating with the Timeline
Top SQL always reflects the currently selected time window, including any zoom applied on the Activity Timeline.
Typical workflow:
- Spot a spike on the Activity Timeline at 14:32
- Zoom into that interval
- Check Top SQL to see which query was dominant during the spike
- Expand the query text to identify the specific statement