Skip to main content

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:

TabRanks byUse Case
ExecutionsNumber of times the query appeared in ASH samplesIdentify most frequently running queries
Total TimeCumulative time across all samplesIdentify queries consuming the most total database time
Average TimeAverage time per sample occurrenceIdentify consistently slow individual executions
Wait EventsNumber of samples with a non-CPU waitIdentify queries blocked on waits most often

{screenshot: ash-top-sql-tabs}


Table Columns

ColumnDescription
RankPosition in the current ranking
QueryTruncated SQL text (hover or click to expand)
DatabaseDatabase where the query was executed
UserPostgreSQL user who executed the query
ExecutionsNumber 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 EventMost 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:

  1. Spot a spike on the Activity Timeline at 14:32
  2. Zoom into that interval
  3. Check Top SQL to see which query was dominant during the spike
  4. Expand the query text to identify the specific statement

Next Steps