Skip to content

Commit 83171d0

Browse files
committed
Edit pass
1 parent 2405c69 commit 83171d0

File tree

1 file changed

+56
-42
lines changed

1 file changed

+56
-42
lines changed

docs/relational-databases/system-dynamic-management-views/sys-dm-exec-requests-transact-sql.md

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: sys.dm_exec_requests returns information about each request that is
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
66
ms.reviewer: mikeray, randolphwest, derekw
7-
ms.date: 10/04/2023
7+
ms.date: 04/06/2025
88
ms.service: sql
99
ms.subservice: system-objects
1010
ms.topic: "reference"
@@ -23,10 +23,10 @@ monikerRange: "=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-20
2323

2424
[!INCLUDE [sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw.md)]
2525

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).
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).
2727

2828
> [!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`.
3030
3131
| Column name | Data type | Description |
3232
| --- | --- | --- |
@@ -35,15 +35,15 @@ Returns information about each request that is executing in [!INCLUDE [ssNoVersi
3535
| `start_time` | **datetime** | Timestamp when the request arrived. Not nullable. |
3636
| `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. |
3737
| `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. |
3939
| `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. |
4040
| `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. |
4242
| `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. |
4343
| `user_id` | **int** | ID of the user who submitted the request. Not nullable. |
4444
| `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). |
4747
| `wait_time` | **int** | If the request is currently blocked, this column returns the duration in milliseconds, of the current wait. Not nullable. |
4848
| `last_wait_type` | **nvarchar(60)** | If this request has previously been blocked, this column returns the type of the last wait. Not nullable. |
4949
| `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
8383
| `group_id` | **int** | ID of the workload group to which this query belongs. Not nullable. |
8484
| `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. |
8585
| `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. |
8888
| `dop` | **int** | **Applies to**: [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] and later.<br /><br />The degree of parallelism of the query. |
8989
| `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. |
9090
| `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
9797

9898
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.
9999

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).
101101

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

104104
## Permissions
105105

@@ -111,34 +111,49 @@ For [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions, `s
111111

112112
## Examples
113113

114-
### A. Show Active Requests
114+
### A. Find the query text for a running batch
115115

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

118+
```sql
119+
SELECT * FROM sys.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)`.
124+
125+
```sql
126+
SELECT * FROM sys.dm_exec_sql_text(< copied sql_handle >);
127+
GO
118128
```
119-
SELECT
120-
r.session_id,
121-
r.status,
122-
r.command,
123-
r.start_time,
124-
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+
SELECT r.session_id,
136+
r.status,
137+
r.command,
138+
r.start_time,
139+
r.total_elapsed_time / 1000.00 AS elapsed_seconds,
140+
r.cpu_time / 1000.00 AS 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.text AS query_text
148+
FROM sys.dm_exec_requests AS r
149+
INNER JOIN sys.dm_exec_sessions AS s
150+
ON r.session_id = s.session_id
151+
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
137152
WHERE r.session_id <> @@SPID
138153
ORDER BY r.start_time DESC;
139154
```
140155

141-
### B. Find all locks that a running batch is holding
156+
### C. Find all locks that a running batch is holding
142157

143158
The following example queries `sys.dm_exec_requests` to find the interesting batch and copy its `transaction_id` from the output.
144159

@@ -156,28 +171,27 @@ WHERE request_owner_type = N'TRANSACTION'
156171
GO
157172
```
158173

159-
### C. Find all currently blocked requests
174+
### D. Find all currently blocked requests
160175

161176
The following example queries `sys.dm_exec_requests` to find information about blocked requests.
162177

163178
```sql
164179
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
171186
FROM sys.dm_exec_requests
172187
WHERE status = N'suspended';
173188
GO
174189
```
175190

176-
### D. Order existing requests by CPU
191+
### E. Order existing requests by CPU
177192

178193
```sql
179-
SELECT
180-
[req].[session_id],
194+
SELECT [req].[session_id],
181195
[req].[start_time],
182196
[req].[cpu_time] AS [cpu_time_ms],
183197
OBJECT_NAME([ST].[objectid], [ST].[dbid]) AS [ObjectName],

0 commit comments

Comments
 (0)