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

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.

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. Service classes are defined in the WLM configuration.
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:

  • Classified

  • Completed

  • Dequeued

  • Evicted

  • Evicting

  • Initialized

  • Invalid

  • Queued

  • QueuedWaiting

  • Rejected

  • Returning

  • Running

  • TaskAssigned

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

Sample Query

Service classes 1 - 4 are used internally by Amazon Redshift, and service class 5 is reserved for the dedicated superuser queue. The following query displays all currently executing queries in service classes greater than 4, which are the superuser queue and the WLM query queues.

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

This query returns the following sample output:

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