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. It helps you identify which queries are consuming the most resources or generating the most wait activity.

Top SQL


Top SQL Table

The table lists up to 10 queries with the following information per row:

ColumnDescription
AASAverage Active Sessions — average number of active sessions executing this query during the selected period
% of TotalPercentage of total DB time attributed to this query
SQL TextNormalized SQL text (truncated)
Top Wait TypeMost frequent wait event type observed for this query (color-coded)
CPU% / Wait%Breakdown of time spent on CPU vs. waiting
ExecutionsNumber of executions observed during the period
Avg TimeAverage execution time per call

Sorting

The table can be sorted by clicking on any of the following column headers:

Sort ColumnUse Case
AASIdentify queries with the highest average active sessions (default)
Total Time %Identify queries consuming the most total database time
Top Wait TypeGroup queries by their dominant wait event
ExecutionsIdentify the most frequently executed queries
Avg TimeIdentify consistently slow individual executions
Cache HitIdentify queries with poor buffer cache utilization

Use the Search SQL box above the table to filter queries by SQL text. The filter applies to the normalized SQL text displayed in the table.


Query Detail

Click on any row to expand the full detail panel for that query.

FieldDescription
SQL QueryFull normalized SQL text
Query IDInternal PostgreSQL query identifier
Query HashHash of the normalized query text
AASAverage Active Sessions for this query
SamplesNumber of ASH samples capturing this query
ExecutionsNumber of executions observed
Avg Exec TimeAverage execution time per call

Query Detail


Tab 1 — Overview

  • Query Activity Over Time — Activity timeline chart showing the execution pattern of this specific query over the selected period, colored by wait event type
  • Wait Class Distribution — Breakdown of wait event types observed for this query during the period

Tab 2 — Performance

Execution Statistics

MetricDescription
Total Exec TimeCumulative execution time across all observed executions
Avg Exec TimeAverage time per execution
Min Exec TimeFastest execution observed
Max Exec TimeSlowest execution observed
Std DevStandard deviation of execution time — indicates variability
Total RowsTotal rows returned across all executions

I/O Statistics

MetricDescription
Blocks Read (Disk)Blocks read from disk (cache misses)
Blocks Hit (Cache)Blocks served from buffer cache
Cache Hit RatioPercentage of reads served from buffer cache

Query Performance Detail

Interpreting Cache Hit Ratio

A low cache hit ratio for a specific query indicates it is reading many blocks from disk — likely due to a missing index, a large sequential scan or insufficient shared_buffers. Investigate the query execution plan with EXPLAIN (ANALYZE, BUFFERS).


Tab 3 — Active Sessions

A table of sessions currently executing this query, refreshed with the ASH data:

ColumnDescription
PIDPostgreSQL process ID
StateSession state (active, idle, idle in transaction)
Wait EventCurrent wait event (e.g. On CPU, lock name, I/O event)
ClientClient address or local for local connections
Query StartHow long this execution has been running

{screenshot: ash-query-detail-active-sessions} Query Current Executions


Next Steps