sys.dm_os_waiting_tasks (języka Transact-SQL)

Dotyczy: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)

Zwraca informacje o kolejce oczekiwania zadań, które oczekują na jakiś zasób. Aby uzyskać więcej informacji o zadaniach, zobacz Przewodnik po wątkach i architekturze zadań.

Uwaga

Aby wywołać to z usługi Azure Synapse Analytics lub Analytics Platform System (PDW), użyj nazwy sys.dm_pdw_nodes_os_waiting_tasks. Ta składnia nie jest obsługiwana przez bezserwerową pulę SQL w usłudze Azure Synapse Analytics.This syntax is not supported by serverless SQL pool in Azure Synapse Analytics.

Nazwa kolumny Typ danych Opis
waiting_task_address Odmiana(8) Adres zadania oczekującego.
session_id Smallint Identyfikator sesji skojarzonej z zadaniem.
exec_context_id Int Identyfikator kontekstu wykonania skojarzonego z zadaniem.
wait_duration_ms bigint Całkowity czas oczekiwania dla tego typu oczekiwania, w milisekundach. Ten czas obejmuje signal_wait_time.
wait_type Nvarchar(60) Nazwa typu oczekiwania.
resource_address Odmiana(8) Adres zasobu, na który oczekuje zadanie.
blocking_task_address Odmiana(8) Zadanie, w którym obecnie znajduje się ten zasób
blocking_session_id Smallint Identyfikator sesji, która blokuje żądanie. Jeśli ta kolumna ma wartość NULL, żądanie nie jest blokowane lub informacje o sesji blokującej są niedostępne (lub nie można ich zidentyfikować).

-2 = Właścicielem zasobu blokującego jest oddzielona transakcja rozproszona.

-3 = Zasób blokujący jest własnością transakcji odzyskiwania odroczonego.

-4 = Nie można określić identyfikatora sesji właściciela zatrzasku blokującego z powodu wewnętrznych przejść stanu zatrzasku.
blocking_exec_context_id Int Identyfikator kontekstu wykonywania zadania blokującego.
resource_description Nvarchar(3072) Opis zużywanego zasobu. Aby uzyskać więcej informacji, zobacz poniższą listę.
pdw_node_id Int Dotyczy: Azure Synapse Analytics, Analytics Platform System (PDW)

Identyfikator węzła, na którym znajduje się ta dystrybucja.

resource_description kolumna

Kolumna resource_description zawiera następujące możliwe wartości.

Właściciel zasobu puli wątków:

  • threadpool id=scheduler<hex-address>

Właściciel zasobu zapytania równoległego:

  • exchangeEvent id={Port|Pipe}<hex-address> WaitType=<exchange-wait-type> nodeId=<exchange-node-id>

Typ oczekiwania na wymianę:

  • e_waitNone

  • e_waitPipeNewRow

  • e_waitPipeGetRow

  • e_waitSynchronizeConsumerOpen

  • e_waitPortOpen

  • e_waitPortClose

  • e_waitRange

Zablokuj właściciela zasobu:

  • <type-specific-description> id=lock<lock-hex-address> mode=<mode> associatedObjectId=<associated-obj-id>

    <type-specific-description> can be:

    • For DATABASE: databaselock subresource=<databaselock-subresource> dbid=<db-id>

    • For FILE: filelock fileid=<file-id> subresource=<filelock-subresource> dbid=<db-id>

    • For OBJECT: objectlock lockPartition=<lock-partition-id> objid=<obj-id> subresource=<objectlock-subresource> dbid=<db-id>

    • For PAGE: pagelock fileid=<file-id> pageid=<page-id> dbid=<db-id> subresource=<pagelock-subresource>

    • For Key: keylock hobtid=<hobt-id> dbid=<db-id>

    • For EXTENT: extentlock fileid=<file-id> pageid=<page-id> dbid=<db-id>

    • For RID: ridlock fileid=<file-id> pageid=<page-id> dbid=<db-id>

    • For APPLICATION: applicationlock hash=<hash> databasePrincipalId=<role-id> dbid=<db-id>

    • For METADATA: metadatalock subresource=<metadata-subresource> classid=<metadatalock-description> dbid=<db-id>

    • For HOBT: hobtlock hobtid=<hobt-id> subresource=<hobt-subresource> dbid=<db-id>

    • For ALLOCATION_UNIT: allocunitlock hobtid=<hobt-id> subresource=<alloc-unit-subresource> dbid=<db-id>

    <mode> can be:

    Sch-S, Sch-M, S, U, X, IS, IU, IX, SIU, SIX, UIX, BU, RangeS-S, RangeS-U, RangeI-N, RangeI-S, RangeI-U, RangeI-X, RangeX-, RangeX-U, RangeX-X

External resource owner:

  • External ExternalResource=<wait-type>

Generic resource owner:

  • TransactionMutex TransactionInfo Workspace=<workspace-id>

  • Mutex

  • CLRTaskJoin

  • CLRMonitorEvent

  • CLRRWLockEvent

  • resourceWait

Latch resource owner:

  • <db-id>:<file-id>:<page-in-file>

  • <GUID>

  • <latch-class> (<latch-address>)

Permissions

On SQL Server and SQL Managed Instance, requires permission.VIEW SERVER STATE

On SQL Database Basic, S0, and S1 service objectives, and for databases in elastic pools, the server admin account, the Azure Active Directory admin account, or membership in the server role is required. On all other SQL Database service objectives, either the permission on the database, or membership in the server role is required.##MS_ServerStateReader##VIEW DATABASE STATE##MS_ServerStateReader##

Permissions for SQL Server 2022 and later

Requires VIEW SERVER PERFORMANCE STATE permission on the server.

Example

A. Identify tasks from blocked sessions.

SQL
SELECT * FROM sys.dm_os_waiting_tasks 
WHERE blocking_session_id IS NOT NULL; 

B. View waiting tasks per connection

SQL
SELECT st.text AS [SQL Text], c.connection_id, w.session_id, 
  w.wait_duration_ms, w.wait_type, w.resource_address, 
  w.blocking_session_id, w.resource_description, c.client_net_address, c.connect_time
FROM sys.dm_os_waiting_tasks AS w
INNER JOIN sys.dm_exec_connections AS c ON w.session_id = c.session_id 
CROSS APPLY (SELECT * FROM sys.dm_exec_sql_text(c.most_recent_sql_handle)) AS st 
              WHERE w.session_id > 50 AND w.wait_duration_ms > 0
ORDER BY c.connection_id, w.session_id
GO

C. View waiting tasks for all user processes with additional information

SQL
SELECT 'Waiting_tasks' AS [Information], owt.session_id,
	owt.wait_duration_ms, owt.wait_type, owt.blocking_session_id,
	owt.resource_description, es.program_name, est.text,
	est.dbid, eqp.query_plan, er.database_id, es.cpu_time,
	es.memory_usage*8 AS memory_usage_KB
FROM sys.dm_os_waiting_tasks owt
INNER JOIN sys.dm_exec_sessions es ON owt.session_id = es.session_id
INNER JOIN sys.dm_exec_requests er ON es.session_id = er.session_id
OUTER APPLY sys.dm_exec_sql_text (er.sql_handle) est
OUTER APPLY sys.dm_exec_query_plan (er.plan_handle) eqp
WHERE es.is_user_process = 1
ORDER BY owt.session_id;
GO

See also

SQL Server Operating System Related Dynamic Management Views (Transact-SQL)
Thread and Task Architecture Guide