Menu
Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

STL_QUERY_METRICS

Contains metrics information, such as the number of rows processed, CPU usage, input/output, and disk use, for queries that have completed running in user-defined query queues (service classes). To view metrics for active queries that are currently running, see the STV_QUERY_METRICS system table.

Query metrics are sampled at one second intervals. As a result, different runs of the same query might return slightly different times. Also, query segments that run in less than one second might not be recorded.

STL_QUERY_METRICS tracks and aggregates metrics at the query, segment, and step level. For information about query segments and steps, see Query Planning And Execution Workflow. Many metrics (such as max_rows, cpu_time, and so on) are summed across node slices. For more information about node slices, see Data Warehouse System Architecture.

To determine the level at which the row reports metrics, examine the segment and step_type columns.

  • If both segment and step_type are -1, then the row reports metrics at the query level.

  • If segment is not -1 and step_type is -1, then the row reports metrics at the segment level.

  • If both segment and step_type are not -1, then the row reports metrics at the step level.

The SVL_QUERY_METRICS view and the SVL_QUERY_METRICS_SUMMARY view aggregate the data in this table and present the information in a more accessible form.

This table is visible to all users. Superusers can see all rows; regular users can see only their own data. For more information, see Visibility of Data in System Tables and Views.

Table Rows

Row Name Data Type Description
userid integer ID of the user that ran the query that generated the entry.
service_class integer ID for the WLM query queue (service class). Query queues are defined in the WLM configuration. Metrics are reported only for user-defined queues.
query integer Query ID. The query column can be used to join other system tables and views.
segment integer Segment number. A query consists of multiple segments, and each segment consists of one or more steps. Query segments can run in parallel. Each segment runs in a single process. If the segment value is -1, metrics segment values are rolled up to the query level.
step_type integer Type of step that executed. For a description of step types, see Step Types.
starttime timestamp Time in UTC that the query started executing, with 6 digits of precision for fractional seconds. For example: 2009-06-12 11:29:19.131358.
slices integer Number of slices for the cluster.
max_rows bigint Maximum number of rows output for a step, aggregated across all slices.
rows bigint Number of rows processed by a step.
max_cpu_time bigint Maximum CPU time used, in microseconds. At the segment level, the maximum CPU time used by the segment across all slices. At the query level, the maximum CPU time used by any query segment.
cpu_time bigint CPU time used, in microseconds. At the segment level, the total CPU time for the segment across all slices. At the query level, the sum of CPU time for the query across all slices and segments.
max_blocks_read bigint Maximum number of 1 MB blocks read by the segment, aggregated across all slices. At the segment level, the maximum number of 1 MB blocks read for the segment across all slices. At the query level, the maximum number of 1 MB blocks read by any query segment.
blocks_read bigint Number of 1 MB blocks read by the query or segment.
max_run_time bigint The maximum elapsed time for a segment, in microseconds. At the segment level, the maximum run time for the segment across all slices. At the query level, the maximum run time for any query segment.
run_time bigint

Total run time, summed across slices. Run time doesn't include wait time.

At the segment level, the run time for the segment, summed across all slices. At the query level, the run time for the query summed across all slices and segments. Because this value is a sum, run time is not related to query execution time.

max_blocks_to_disk bigint The maximum amount of disk space used to write intermediate results, in MB blocks. At the segment level, the maximum amount of disk space used by the segment across all slices. At the query level, the maximum amount of disk space used by any query segment.
blocks_to_disk bigint The amount of disk space used by a query or segment to write intermediate results, in MB blocks.
step integer Query step that executed.
max_query_scan_size bigint The maximum size of data scanned by a query, in MB. At the segment level, the maximum size of data scanned by the segment across all slices. At the query level, the maximum size of data scanned by any query segment.
query_scan_size bigint The size of data scanned by a query, in MB.

Sample Query

To find queries with high CPU time (more the 1,000 seconds), run the following query.

Copy
Select query, cpu_time / 1000000 as cpu_seconds from stl_query_metrics where segment = -1 and cpu_time > 1000000000 order by cpu_time; query | cpu_seconds ------+------------ 25775 | 9540

To find active queries with a nested loop join that returned more than one million rows, run the following query.

Copy
select query, rows from stl_query_metrics where step = 15 and rows > 1000000 order by rows; query | rows ------+----------- 25775 | 2621562702

To find active queries that have run for more than 60 seconds and have used less than 10 seconds of CPU time, run the following query.

Copy
select query, run_time/1000000 as run_time_seconds from stl_query_metrics where segment = -1 and run_time > 60000000 and cpu_time < 10000000; query | run_time_seconds ------+----------------- 25775 | 114

On this page: