STV_WLM_QUERY_STATE - Amazon Redshift

STV_WLM_QUERY_STATE

Records the current state of queries being tracked by WLM.

STV_WLM_QUERY_STATE 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.

Some or all of the data in this table can also be found in the SYS monitoring view SYS_QUERY_HISTORY. The data in the SYS monitoring view is formatted to be easier to use and understand. We recommend that you use the SYS monitoring view for your queries.

Table columns

Column name Data type Description
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. For a list of service class IDs, see WLM service class IDs.
slot_count integer Number of WLM query slots.
wlm_start_time timestamp Time that the query entered the system table queue or short query queue.
state character(16) Current state of the query or subquery.

Possible values are the following:

  • Classified – Query has been assigned to a service class.

  • Completed – Query is finished running. The query either ran successfully or was canceled. For the final state, check the results of STL_QUERY.

  • Dequeued – Internal use only.

  • Evicted – Query has been evicted from the service class for restart.

  • Evicting – Query is being evicted from the service class for restart.

  • Initialized – Internal use only.

  • Invalid – Internal use only.

  • Queued – Query was sent to the query queue because no slots were available to run it.

  • QueuedWaiting – Query is waiting in the query queue.

  • Rejected – Internal use only.

  • Returning – Query is returning results to the client.

  • Running – Query is running.

  • TaskAssigned – Internal use only.

queue_time bigint Number of microseconds that the query has spent in the queue.
exec_time bigint Number of microseconds that the query has been running.
query_priority char(20) The priority of the query. Possible values are n/a, lowest, low, normal, high, and highest, where n/a means that query priority isn't supported.

Sample query

The following query displays all currently executing queries in service classes greater than 4. For a list of service class IDs, see WLM service class IDs.

select xid, query, trim(state) as state, queue_time, exec_time from stv_wlm_query_state where service_class > 4;

This query returns the following sample output:

xid | query | state | queue_time | exec_time -------+-------+---------+------------+----------- 100813 | 25942 | Running | 0 | 1369029 100074 | 25775 | Running | 0 | 2221589242