sys.dm_os_tasks (Transact-SQL)


THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)noAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns one row for each task that is active in the instance of SQL Server.

System_CAPS_ICON_note.jpg Note

To call this from Azure SQL Data Warehouse or Parallel Data Warehouse, use the name sys.dm_pdw_nodes_os_tasks.

Column nameData typeDescription
task_addressvarbinary(8)Memory address of the object.
task_statenvarchar(60)State of the task. This can be one of the following:

PENDING: Waiting for a worker thread.

RUNNABLE: Runnable, but waiting to receive a quantum.

RUNNING: Currently running on the scheduler.

SUSPENDED: Has a worker, but is waiting for an event.

DONE: Completed.

SPINLOOP: Stuck in a spinlock.
context_switches_countintNumber of scheduler context switches that this task has completed.
pending_io_countintNumber of physical I/Os that are performed by this task.
pending_io_byte_countbigintTotal byte count of I/Os that are performed by this task.
pending_io_byte_averageintAverage byte count of I/Os that are performed by this task.
scheduler_idintID of the parent scheduler. This is a handle to the scheduler information for this task. For more information, see sys.dm_os_schedulers (Transact-SQL).
session_idsmallintID of the session that is associated with the task.
exec_context_idintExecution context ID that is associated with the task.
request_idintID of the request of the task. For more information, see sys.dm_exec_requests (Transact-SQL).
worker_addressvarbinary(8)Memory address of the worker that is running the task.

NULL = Task is either waiting for a worker to be able to run, or the task has just finished running.

For more information, see sys.dm_os_workers (Transact-SQL).
host_addressvarbinary(8)Memory address of the host.

0 = Hosting was not used to create the task. This helps identify the host that was used to create this task.

For more information, see sys.dm_os_hosts (Transact-SQL).
parent_task_addressvarbinary(8)Memory address of the task that is the parent of the object.
pdw_node_idintApplies to: Azure SQL Data Warehouse, Parallel Data Warehouse

The identifier for the node that this distribution is on.

On SQL Server requires VIEW SERVER STATE permission on the server.

On SQL Database Premium Tiers requires the VIEW DATABASE STATE permission in the database. On SQL Database Standard and Basic Tiers requires the SQL Database admin account.

A. Monitoring parallel requests

For requests that are executed in parallel, you will see multiple rows for the same combination of (<session_id>, <request_id>). Use the following query to find the Configure the max degree of parallelism Server Configuration Option for all active requests.

System_CAPS_ICON_note.jpg Note

A request_id is unique within a session.

  FROM sys.dm_os_tasks  
  ORDER BY session_id, request_id;  

B. Associating session IDs with Windows threads

You can use the following query to associate a session ID value with a Windows thread ID. You can then monitor the performance of the thread in the Windows Performance Monitor. The following query does not return information for sessions that are sleeping.

SELECT STasks.session_id, SThreads.os_thread_id  
  FROM sys.dm_os_tasks AS STasks  
  INNER JOIN sys.dm_os_threads AS SThreads  
    ON STasks.worker_address = SThreads.worker_address  
  WHERE STasks.session_id IS NOT NULL  
  ORDER BY STasks.session_id;  

Dynamic Management Views and Functions (Transact-SQL)
SQL Server Operating System Related Dynamic Management Views (Transact-SQL)

Community Additions