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

STL_WLM_QUERY

Contains a record of each attempted execution of a query in a service class handled by WLM.

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 Columns

Column Name Data Type Description
userid integer ID of the user who generated the entry.
xid integer Transaction ID of the query or subquery.
task integer ID used to track a query through the workload manager. Can be associated with multiple query IDs. If a query is restarted, the query is assigned a new query ID but not a new task ID.
query integer Query ID. If a query is restarted, the query is assigned a new query ID but not a new task ID.
service_class integer ID for the service class. Service classes are defined in the WLM configuration file.
slot_count integer Number of WLM query slots.
service_class_start_time timestamp Time that the query was assigned to the service class.
queue_start_time timestamp Time that the query entered the queue for the service class.
queue_end_time timestamp Time when the query left the queue for the service class.
total_queue_time bigint Total number of microseconds that the query spent in the queue.
exec_start_time timestamp Time that the query began executing in the service class.
exec_end_time timestamp Time that the query completed execution in the service class.
total_exec_time bigint Number of microseconds that the query spent executing.
service_class_end_time timestamp Time that the query left the service class.
final_state character(16) Reserved for system use.

Sample Queries

View Average Query Time in Queues and Executing

Service classes 1 - 4 are used internally by Amazon Redshift, and service class 5 is reserved for the dedicated superuser queue. The following queries display the current configuration for service classes greater than 4, which include the superuser and WLM query queues.

The following query returns the average time (in microseconds) that each query spent in query queues and executing for each service class.

Copy
select service_class as svc_class, count(*), avg(datediff(microseconds, queue_start_time, queue_end_time)) as avg_queue_time, avg(datediff(microseconds, exec_start_time, exec_end_time )) as avg_exec_time from stl_wlm_query where service_class > 4 group by service_class order by service_class;

This query returns the following sample output:

Copy
svc_class | count | avg_queue_time | avg_exec_time -----------+-------+----------------+--------------- 5 | 20103 | 0 | 80415 5 | 3421 | 34015 | 234015 6 | 42 | 0 | 944266 7 | 196 | 6439 | 1364399 (4 rows)

View Maximum Query Time in Queues and Executing

The following query returns the maximum amount of time (in microseconds) that a query spent in any query queue and executing for each service class.

Copy
select service_class as svc_class, count(*), max(datediff(microseconds, queue_start_time, queue_end_time)) as max_queue_time, max(datediff(microseconds, exec_start_time, exec_end_time )) as max_exec_time from stl_wlm_query where svc_class > 5 group by service_class order by service_class;
Copy
svc_class | count | max_queue_time | max_exec_time -----------+-------+----------------+--------------- 6 | 42 | 0 | 3775896 7 | 197 | 37947 | 16379473 (4 rows)