You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns information about each request that is executing in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. For more information about requests, see the [Thread and Task Architecture Guide](../thread-and-task-architecture-guide.md).
26
+
Returns information about each request that is executing in [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)]. For more information about requests, see the [Thread and task architecture guide](../thread-and-task-architecture-guide.md).
27
27
28
28
> [!NOTE]
29
-
> To call this from dedicated SQL pool in [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)] or [!INCLUDE [ssPDW](../../includes/sspdw-md.md)], see [sys.dm_pdw_exec_requests (Transact-SQL)](sys-dm-pdw-exec-requests-transact-sql.md). For serverless SQL pool or [!INCLUDE [fabric](../../includes/fabric.md)] use `sys.dm_exec_requests`.
29
+
> To call this from dedicated SQL pool in [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)] or [!INCLUDE [ssPDW](../../includes/sspdw-md.md)], see [sys.dm_pdw_exec_requests](sys-dm-pdw-exec-requests-transact-sql.md). For serverless SQL pool or [!INCLUDE [fabric](../../includes/fabric.md)], use `sys.dm_exec_requests`.
30
30
31
31
| Column name | Data type | Description |
32
32
| --- | --- | --- |
@@ -35,15 +35,15 @@ Returns information about each request that is executing in [!INCLUDE [ssNoVersi
35
35
|`start_time`|**datetime**| Timestamp when the request arrived. Not nullable. |
36
36
|`status`|**nvarchar(30)**| Status of the request. Can be one of the following values:<br /><br />background<br />rollback<br />running<br />runnable<br />sleeping<br />suspended<br /><br />Not nullable. |
37
37
|`command`|**nvarchar(32)**| Identifies the current type of command that is being processed. Common command types include the following values:<br /><br />SELECT<br />INSERT<br />UPDATE<br />DELETE<br />BACKUP LOG<br />BACKUP DATABASE<br />DBCC<br />FOR<br /><br />The text of the request can be retrieved by using `sys.dm_exec_sql_text` with the corresponding `sql_handle` for the request. Internal system processes set the command based on the type of task they perform. Tasks can include the following values:<br /><br />LOCK MONITOR<br />CHECKPOINTLAZY<br />WRITER<br /><br />Not nullable. |
38
-
|`sql_handle`|**varbinary(64)**|Is a token that uniquely identifies the batch or stored procedure that the query is part of. Nullable. |
38
+
|`sql_handle`|**varbinary(64)**|A token that uniquely identifies the batch or stored procedure that the query is part of. Nullable. |
39
39
|`statement_start_offset`|**int**| Indicates, in bytes, beginning with 0, the starting position of the currently executing statement for the currently executing batch or persisted object. Can be used together with the `sql_handle`, the `statement_end_offset`, and the `sys.dm_exec_sql_text` dynamic management function to retrieve the currently executing statement for the request. Nullable. |
40
40
|`statement_end_offset`|**int**| Indicates, in bytes, starting with 0, the ending position of the currently executing statement for the currently executing batch or persisted object. Can be used together with the `sql_handle`, the `statement_start_offset`, and the `sys.dm_exec_sql_text` dynamic management function to retrieve the currently executing statement for the request. Nullable. |
41
-
|`plan_handle`|**varbinary(64)**|Is a token that uniquely identifies a query execution plan for a batch that is currently executing. Nullable. |
41
+
|`plan_handle`|**varbinary(64)**|A token that uniquely identifies a query execution plan for a batch that is currently executing. Nullable. |
42
42
|`database_id`|**smallint**| ID of the database the request is executing against. Not nullable.<br /><br />In [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], the values are unique within a single database or an elastic pool, but not within a logical server. |
43
43
|`user_id`|**int**| ID of the user who submitted the request. Not nullable. |
44
44
|`connection_id`|**uniqueidentifier**| ID of the connection on which the request arrived. Nullable. |
45
-
| `blocking_session_id` | **smallint** | ID of the session that is blocking the request. If this column is `NULL` or `0`, the request isn't blocked, or the session information of the blocking session isn't available (or can't be identified). For more information, see [Understand and resolve SQL Server blocking problems](/troubleshoot/sql/performance/understand-resolve-blocking).<br /><br />-2 = The blocking resource is owned by an orphaned distributed transaction.<br /><br />-3 = The blocking resource is owned by a deferred recovery transaction.<br /><br />-4 = `session_id` of the blocking latch owner couldn't be determined at this time because of internal latch state transitions.<br /><br />`-5` = `session_id` of the blocking latch owner couldn't be determined because it isn't tracked for this latch type (for example, for an SH latch).<br /><br />By itself, `blocking_session_id` `-5` doesn't indicate a performance problem. `-5` is an indication that the session is waiting on an asynchronous action to complete. Before `-5` was introduced, the same session would have shown `blocking_session_id` `0`, even though it was still in a wait state.<br /><br />Depending on workload, observing `blocking_session_id = -5` may be a common occurrence. |
46
-
|`wait_type`|**nvarchar(60)**| If the request is currently blocked, this column returns the type of wait. Nullable.<br /><br />For information about types of waits, see [sys.dm_os_wait_stats (Transact-SQL)](sys-dm-os-wait-stats-transact-sql.md). |
45
+
| `blocking_session_id` | **smallint** | ID of the session that is blocking the request. If this column is `NULL` or `0`, the request isn't blocked, or the session information of the blocking session isn't available (or can't be identified). For more information, see [Understand and resolve SQL Server blocking problems](/troubleshoot/sql/performance/understand-resolve-blocking).<br /><br />-2 = The blocking resource is owned by an orphaned distributed transaction.<br /><br />-3 = The blocking resource is owned by a deferred recovery transaction.<br /><br />-4 = `session_id` of the blocking latch owner couldn't be determined at this time because of internal latch state transitions.<br /><br />`-5` = `session_id` of the blocking latch owner couldn't be determined because it isn't tracked for this latch type (for example, for an SH latch).<br /><br />By itself, `blocking_session_id` `-5` doesn't indicate a performance problem. `-5` is an indication that the session is waiting on an asynchronous action to complete. Before `-5` was introduced, the same session would have shown `blocking_session_id` `0`, even though it was still in a wait state.<br /><br />Depending on workload, observing `blocking_session_id = -5` might be a common occurrence. |
46
+
|`wait_type`|**nvarchar(60)**| If the request is currently blocked, this column returns the type of wait. Nullable.<br /><br />For information about types of waits, see [sys.dm_os_wait_stats](sys-dm-os-wait-stats-transact-sql.md). |
47
47
|`wait_time`|**int**| If the request is currently blocked, this column returns the duration in milliseconds, of the current wait. Not nullable. |
48
48
|`last_wait_type`|**nvarchar(60)**| If this request has previously been blocked, this column returns the type of the last wait. Not nullable. |
49
49
|`wait_resource`|**nvarchar(256)**| If the request is currently blocked, this column returns the resource for which the request is currently waiting. Not nullable. |
@@ -83,8 +83,8 @@ Returns information about each request that is executing in [!INCLUDE [ssNoVersi
83
83
|`group_id`|**int**| ID of the workload group to which this query belongs. Not nullable. |
84
84
|`query_hash`|**binary(8)**| Binary hash value calculated on the query and used to identify queries with similar logic. You can use the query hash to determine the aggregate resource usage for queries that differ only by literal values. |
85
85
|`query_plan_hash`|**binary(8)**| Binary hash value calculated on the query execution plan and used to identify similar query execution plans. You can use query plan hash to find the cumulative cost of queries with similar execution plans. |
86
-
|`statement_sql_handle`|**varbinary(64)**|**Applies to**: [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] and later.<br /><br />`sql_handle` of the individual query.<br /><br />This column is NULL if Query Store isn't enabled for the database. |
87
-
|`statement_context_id`|**bigint**|**Applies to**: [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] and later.<br /><br />The optional foreign key to `sys.query_context_settings`.<br /><br />This column is NULL if Query Store isn't enabled for the database. |
86
+
|`statement_sql_handle`|**varbinary(64)**|**Applies to**: [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] and later.<br /><br />`sql_handle` of the individual query.<br /><br />This column is `NULL` if Query Store isn't enabled for the database. |
87
+
|`statement_context_id`|**bigint**|**Applies to**: [!INCLUDE [ssSQL14](../../includes/sssql14-md.md)] and later.<br /><br />The optional foreign key to `sys.query_context_settings`.<br /><br />This column is `NULL` if Query Store isn't enabled for the database. |
88
88
|`dop`|**int**|**Applies to**: [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] and later.<br /><br />The degree of parallelism of the query. |
89
89
|`parallel_worker_count`|**int**|**Applies to**: [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] and later.<br /><br />The number of reserved parallel workers if this is a parallel query. |
90
90
|`external_script_request_id`|**uniqueidentifier**|**Applies to**: [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] and later.<br /><br />The external script request ID associated with the current request. |
@@ -97,9 +97,9 @@ Returns information about each request that is executing in [!INCLUDE [ssNoVersi
97
97
98
98
To execute code that is outside [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] (for example, extended stored procedures and distributed queries), a thread has to execute outside the control of the non-preemptive scheduler. To do this, a worker switches to preemptive mode. Time values returned by this dynamic management view don't include time spent in preemptive mode.
99
99
100
-
When executing parallel requests in [row mode](../query-processing-architecture-guide.md#row-mode-execution), [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] assigns a worker thread to coordinate the worker threads responsible for completing tasks assigned to them. In this DMV, only the coordinator thread is visible for the request. The columns `reads`, `writes`, `logical_reads`, and `row_count` are **not updated** for the coordinator thread. The columns `wait_type`, `wait_time`, `last_wait_type`, `wait_resource`, and `granted_query_memory` are **only updated** for the coordinator thread. For more information, see the [Thread and Task Architecture Guide](../thread-and-task-architecture-guide.md).
100
+
When executing parallel requests in [row mode](../query-processing-architecture-guide.md#row-mode-execution), [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] assigns a worker thread to coordinate the worker threads responsible for completing tasks assigned to them. In this DMV, only the coordinator thread is visible for the request. The columns `reads`, `writes`, `logical_reads`, and `row_count` are **not updated** for the coordinator thread. The columns `wait_type`, `wait_time`, `last_wait_type`, `wait_resource`, and `granted_query_memory` are **only updated** for the coordinator thread. For more information, see the [Thread and task architecture guide](../thread-and-task-architecture-guide.md).
101
101
102
-
The `wait_resource` column contains similar information to `resource_description` in [sys.dm_tran_locks (Transact-SQL)](sys-dm-tran-locks-transact-sql.md) but is formatted differently.
102
+
The `wait_resource` column contains similar information to `resource_description` in [sys.dm_tran_locks](sys-dm-tran-locks-transact-sql.md) but is formatted differently.
103
103
104
104
## Permissions
105
105
@@ -111,34 +111,49 @@ For [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions, `s
111
111
112
112
## Examples
113
113
114
-
### A. Show Active Requests
114
+
### A. Find the query text for a running batch
115
115
116
-
This following example shows all currently running queries in your SQL Data Warehouse, excluding your own session (@@SPID). It uses CROSS APPLY with `sys.dm_exec_sql_text` to retrieve the full query text for each request, and joins with `sys.dm_exec_sessions` to include user and host info. The session_id <> @@SPID filter ensures you don’t see your own query in the results.
116
+
The following example queries `sys.dm_exec_requests` to find the interesting query and copy its `sql_handle` from the output.
117
117
118
+
```sql
119
+
SELECT*FROMsys.dm_exec_requests;
120
+
GO
121
+
```
122
+
123
+
Then, to obtain the statement text, use the copied `sql_handle` with system function `sys.dm_exec_sql_text(sql_handle)`.
r.total_elapsed_time / 1000.00 AS elapsed_seconds,
125
-
r.cpu_time / 1000.00 AS cpu_seconds,
126
-
r.reads,
127
-
r.writes,
128
-
r.logical_reads,
129
-
r.row_count,
130
-
s.login_name,
131
-
s.host_name,
132
-
t.text AS query_text
133
-
FROM sys.dm_exec_requests r
134
-
JOIN sys.dm_exec_sessions s
135
-
ON r.session_id = s.session_id
136
-
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) t
129
+
130
+
### B. Show active requests
131
+
132
+
This following example shows all currently running queries in your SQL Server data warehouse, excluding your own session (`@@SPID`). It uses `CROSS APPLY` with `sys.dm_exec_sql_text` to retrieve the full query text for each request, and joins with `sys.dm_exec_sessions` to include user any host info. The `session_id <> @@SPID` filter ensures that you don't see your own query in the results.
133
+
134
+
```sql
135
+
SELECTr.session_id,
136
+
r.status,
137
+
r.command,
138
+
r.start_time,
139
+
r.total_elapsed_time/1000.00AS elapsed_seconds,
140
+
r.cpu_time/1000.00AS cpu_seconds,
141
+
r.reads,
142
+
r.writes,
143
+
r.logical_reads,
144
+
r.row_count,
145
+
s.login_name,
146
+
s.host_name,
147
+
t.textAS query_text
148
+
FROMsys.dm_exec_requestsAS r
149
+
INNER JOINsys.dm_exec_sessionsAS s
150
+
ONr.session_id=s.session_id
151
+
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
137
152
WHEREr.session_id<> @@SPID
138
153
ORDER BYr.start_timeDESC;
139
154
```
140
155
141
-
### B. Find all locks that a running batch is holding
156
+
### C. Find all locks that a running batch is holding
142
157
143
158
The following example queries `sys.dm_exec_requests` to find the interesting batch and copy its `transaction_id` from the output.
144
159
@@ -156,28 +171,27 @@ WHERE request_owner_type = N'TRANSACTION'
156
171
GO
157
172
```
158
173
159
-
### C. Find all currently blocked requests
174
+
### D. Find all currently blocked requests
160
175
161
176
The following example queries `sys.dm_exec_requests` to find information about blocked requests.
162
177
163
178
```sql
164
179
SELECT session_id,
165
-
status,
166
-
blocking_session_id,
167
-
wait_type,
168
-
wait_time,
169
-
wait_resource,
170
-
transaction_id
180
+
status,
181
+
blocking_session_id,
182
+
wait_type,
183
+
wait_time,
184
+
wait_resource,
185
+
transaction_id
171
186
FROMsys.dm_exec_requests
172
187
WHERE status = N'suspended';
173
188
GO
174
189
```
175
190
176
-
### D. Order existing requests by CPU
191
+
### E. Order existing requests by CPU
177
192
178
193
```sql
179
-
SELECT
180
-
[req].[session_id],
194
+
SELECT [req].[session_id],
181
195
[req].[start_time],
182
196
[req].[cpu_time] AS [cpu_time_ms],
183
197
OBJECT_NAME([ST].[objectid], [ST].[dbid]) AS [ObjectName],
0 commit comments