blocking-root-cause-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Blocking Root Cause Analysis

阻塞根因分析

Purpose

目的

This is the final step in the blocking investigation workflow. After:
  1. the
    query-store-volatile-historical-slow-queries-comparison
    skill (Step 1) found suspect queries
  2. the
    wait-category-analysis
    skill confirmed Lock waits as the root cause
  3. the
    check-live-blocking
    skill found no active blocking (intermittent)
  4. the
    create-xe-session
    skill set up passive monitoring
...this skill retrieves the captured XE data and combines it with Query Store waits and live DMV state to build a complete root cause picture. The key output is WHO (which application, host, and login) is causing the blocking.
这是阻塞调查工作流的最后一步。在以下步骤完成后:
  1. query-store-volatile-historical-slow-queries-comparison
    skill(步骤 1)发现可疑查询
  2. wait-category-analysis
    skill 确认 Lock waits 是根因
  3. check-live-blocking
    skill 未发现活动阻塞(间歇性阻塞)
  4. create-xe-session
    skill 已设置被动监控
本 skill 会检索捕获的 XE 数据,并将其与 Query Store 等待信息和实时 DMV 状态结合,从而构建完整的根因图景。核心输出是责任方(哪个应用、主机和登录名)造成了阻塞。

Scope

范围

  • Also analyzes blocking-chain session details that the user supplies. Captured history requires the BlockingInvestigation XE session created earlier with the
    create-xe-session
    skill.
  • For blocking happening right now (which sessions are blocked, the head blocker), use the
    check-live-blocking
    skill.
  • 还会分析用户提供的阻塞链会话详情。要获取历史捕获数据,必须使用之前通过
    create-xe-session
    skill 创建的 BlockingInvestigation XE 会话。
  • 对于当前正在发生的阻塞(哪些会话被阻塞、哪个会话是阻塞源头),请使用
    check-live-blocking
    skill。

Prerequisites

前置条件

  • Must be connected to the database where the XE session was created.
  • The BlockingInvestigation XE session must have been created (via the
    create-xe-session
    skill) and must have captured data (the suspect workload ran while the session was active).
  • 必须连接到创建 XE 会话的数据库。
  • 必须已通过
    create-xe-session
    skill 创建 BlockingInvestigation XE 会话,并且该会话必须已捕获数据(可疑工作负载在会话处于活动状态时运行过)。

Required tools

所需工具

  • A read-only SQL query tool connected to the target server and database. Prefer, in order: the SQL Tools MCP server that ships with the
    microsoft-sql-admin
    plugin (
    mssql_list_database_connections
    ,
    mssql_connect_database
    , then
    mssql_execute_query
    ); any other SQL tool the agent host provides for running T-SQL and reading result sets;
    sqlcmd
    from a terminal. If the SQL Tools MCP server is not connected or lists no connections, follow the
    sql-tools-mcp-setup
    skill, which asks before installing or configuring anything. If no SQL tool can be made available, give the user the T-SQL to run and ask for the results.
  • Least privilege: connect that tool with a diagnostic login that cannot write, for example one that holds only
    VIEW SERVER PERFORMANCE STATE
    (
    VIEW SERVER STATE
    before SQL Server 2022) or, on Azure SQL Database,
    VIEW DATABASE PERFORMANCE STATE
    or
    ##MS_ServerStateReader##
    , plus any other read permission these queries need. A tool is only as read-only as the login it connects with.
  • 一个连接到目标服务器和数据库的只读 SQL 查询工具。按以下顺序优先选择:随
    microsoft-sql-admin
    插件提供的 SQL Tools MCP 服务器(
    mssql_list_database_connections
    、
    mssql_connect_database
    ,然后是
    mssql_execute_query
    );Agent 宿主提供的任何其他可用于运行 T-SQL 和读取结果集的 SQL 工具;从终端使用
    sqlcmd
    。如果 SQL Tools MCP 服务器未连接或未列出任何连接,请遵循
    sql-tools-mcp-setup
    skill,该 skill 会在安装或配置任何内容前先进行询问。如果无法提供任何 SQL 工具,请向用户提供 T-SQL 供其运行,并索取执行结果。
  • 遵循最小权限原则:使用无法执行写操作的诊断登录名连接该工具。例如,该登录名仅持有
    VIEW SERVER PERFORMANCE STATE
    (SQL Server 2022 之前为
    VIEW SERVER STATE
    ),或者在 Azure SQL Database 中持有
    VIEW DATABASE PERFORMANCE STATE
    或
    ##MS_ServerStateReader##
    ,以及这些查询需要的任何其他读取权限。工具的只读程度取决于连接所使用的登录名。

Platform Detection

平台检测

Confirm which server and database you are connected to, and detect the engine edition, to determine which XE data retrieval query to use:
sql
SELECT
    @@SERVERNAME                                   AS [Server],
    DB_NAME()                                      AS [Database],
    SUSER_SNAME()                                  AS [Login],
    CAST(SERVERPROPERTY('EngineEdition') AS INT)   AS [Engine Edition],
    SERVERPROPERTY('Edition')                      AS [Edition],
    SERVERPROPERTY('ProductVersion')               AS [Product Version];
  • Azure SQL Database / Fabric SQL DB (Engine Edition 5, 11, or 12) → Use the Azure SQL variant for Query 1
  • SQL Server / Managed Instance (Engine Edition 1-4 or 8) → Use the SQL Server variant for Query 1
Queries 2 and 3 are platform-universal and used on all platforms.
确认当前连接的服务器和数据库,并检测引擎版本,以确定应使用哪条 XE 数据检索查询:
sql
SELECT
    @@SERVERNAME                                   AS [Server],
    DB_NAME()                                      AS [Database],
    SUSER_SNAME()                                  AS [Login],
    CAST(SERVERPROPERTY('EngineEdition') AS INT)   AS [Engine Edition],
    SERVERPROPERTY('Edition')                      AS [Edition],
    SERVERPROPERTY('ProductVersion')               AS [Product Version];
  • Azure SQL Database / Fabric SQL DB(Engine Edition 5、11 或 12)→ 对查询 1 使用 Azure SQL 变体
  • SQL Server / Managed Instance(Engine Edition 1-4 或 8)→ 对查询 1 使用 SQL Server 变体
查询 2 和查询 3 与平台无关,可在所有平台上使用。

Data Collection

数据收集

Execute the appropriate Query 1 variant below, plus Queries 2 and 3, in sequence with the SQL query tool.
使用 SQL 查询工具,按顺序执行下方适当的查询 1 变体以及查询 2 和查询 3。

Query 1 — Azure SQL Variant: Retrieve XE Session Data

查询 1 — Azure SQL 变体:检索 XE 会话数据

Use when connected to Azure SQL Database or Fabric SQL Database:
sql
;WITH XEData AS (
    SELECT
        CAST(xet.target_data AS XML) AS target_data
    FROM sys.dm_xe_database_sessions AS xes
    INNER JOIN sys.dm_xe_database_session_targets AS xet
        ON xes.address = xet.event_session_address
    WHERE xes.name = 'BlockingInvestigation'
      AND xet.target_name = 'ring_buffer'
),
RawEvents AS (
    SELECT
        evt.value('(@name)', 'nvarchar(100)') AS event_name,
        evt.value('(@timestamp)', 'datetime2') AS event_time_utc,
        evt.value('(data[@name="duration"]/value)[1]', 'bigint') AS duration_us,
        evt.value('(data[@name="cpu_time"]/value)[1]', 'bigint') AS cpu_time_us,
        evt.value('(data[@name="logical_reads"]/value)[1]', 'bigint') AS logical_reads,
        evt.value('(data[@name="row_count"]/value)[1]', 'bigint') AS row_count,
        evt.value('(data[@name="statement"]/value)[1]', 'nvarchar(max)') AS sql_statement,
        evt.value('(action[@name="client_app_name"]/value)[1]', 'nvarchar(256)') AS client_app_name,
        evt.value('(action[@name="client_hostname"]/value)[1]', 'nvarchar(256)') AS client_hostname,
        evt.value('(action[@name="server_principal_name"]/value)[1]', 'nvarchar(256)') AS login_name,
        evt.value('(action[@name="session_id"]/value)[1]', 'int') AS session_id
    FROM XEData
    CROSS APPLY target_data.nodes('RingBufferTarget/event') AS t(evt)
)
SELECT
    event_time_utc AS [Event Time (UTC)],
    event_name AS [Event],
    duration_us / 1000 AS [Duration (ms)],
    cpu_time_us / 1000 AS [CPU Time (ms)],
    logical_reads AS [Logical Reads],
    row_count AS [Row Count],
    session_id AS [Session ID],
    client_app_name AS [Application Name],
    client_hostname AS [Host Name],
    login_name AS [Login Name],
    LEFT(sql_statement, 200) AS [SQL Text (truncated)]
FROM RawEvents
ORDER BY event_time_utc DESC;
连接到 Azure SQL Database 或 Fabric SQL Database 时使用:
sql
;WITH XEData AS (
    SELECT
        CAST(xet.target_data AS XML) AS target_data
    FROM sys.dm_xe_database_sessions AS xes
    INNER JOIN sys.dm_xe_database_session_targets AS xet
        ON xes.address = xet.event_session_address
    WHERE xes.name = 'BlockingInvestigation'
      AND xet.target_name = 'ring_buffer'
),
RawEvents AS (
    SELECT
        evt.value('(@name)', 'nvarchar(100)') AS event_name,
        evt.value('(@timestamp)', 'datetime2') AS event_time_utc,
        evt.value('(data[@name="duration"]/value)[1]', 'bigint') AS duration_us,
        evt.value('(data[@name="cpu_time"]/value)[1]', 'bigint') AS cpu_time_us,
        evt.value('(data[@name="logical_reads"]/value)[1]', 'bigint') AS logical_reads,
        evt.value('(data[@name="row_count"]/value)[1]', 'bigint') AS row_count,
        evt.value('(data[@name="statement"]/value)[1]', 'nvarchar(max)') AS sql_statement,
        evt.value('(action[@name="client_app_name"]/value)[1]', 'nvarchar(256)') AS client_app_name,
        evt.value('(action[@name="client_hostname"]/value)[1]', 'nvarchar(256)') AS client_hostname,
        evt.value('(action[@name="server_principal_name"]/value)[1]', 'nvarchar(256)') AS login_name,
        evt.value('(action[@name="session_id"]/value)[1]', 'int') AS session_id
    FROM XEData
    CROSS APPLY target_data.nodes('RingBufferTarget/event') AS t(evt)
)
SELECT
    event_time_utc AS [Event Time (UTC)],
    event_name AS [Event],
    duration_us / 1000 AS [Duration (ms)],
    cpu_time_us / 1000 AS [CPU Time (ms)],
    logical_reads AS [Logical Reads],
    row_count AS [Row Count],
    session_id AS [Session ID],
    client_app_name AS [Application Name],
    client_hostname AS [Host Name],
    login_name AS [Login Name],
    LEFT(sql_statement, 200) AS [SQL Text (truncated)]
FROM RawEvents
ORDER BY event_time_utc DESC;

Query 1 — SQL Server Variant: Retrieve XE Session Data

查询 1 — SQL Server 变体:检索 XE 会话数据

Use when connected to SQL Server (on-premises) or Azure SQL Managed Instance:
sql
;WITH XEData AS (
    SELECT
        CAST(xet.target_data AS XML) AS target_data
    FROM sys.dm_xe_sessions AS xes
    INNER JOIN sys.dm_xe_session_targets AS xet
        ON xes.address = xet.event_session_address
    WHERE xes.name = 'BlockingInvestigation'
      AND xet.target_name = 'ring_buffer'
),
RawEvents AS (
    SELECT
        evt.value('(@name)', 'nvarchar(100)') AS event_name,
        evt.value('(@timestamp)', 'datetime2') AS event_time_utc,
        evt.value('(data[@name="duration"]/value)[1]', 'bigint') AS duration_us,
        evt.value('(data[@name="cpu_time"]/value)[1]', 'bigint') AS cpu_time_us,
        evt.value('(data[@name="logical_reads"]/value)[1]', 'bigint') AS logical_reads,
        evt.value('(data[@name="row_count"]/value)[1]', 'bigint') AS row_count,
        evt.value('(data[@name="statement"]/value)[1]', 'nvarchar(max)') AS sql_statement,
        evt.value('(action[@name="client_app_name"]/value)[1]', 'nvarchar(256)') AS client_app_name,
        evt.value('(action[@name="client_hostname"]/value)[1]', 'nvarchar(256)') AS client_hostname,
        evt.value('(action[@name="server_principal_name"]/value)[1]', 'nvarchar(256)') AS login_name,
        evt.value('(action[@name="session_id"]/value)[1]', 'int') AS session_id
    FROM XEData
    CROSS APPLY target_data.nodes('RingBufferTarget/event') AS t(evt)
)
SELECT
    event_time_utc AS [Event Time (UTC)],
    event_name AS [Event],
    duration_us / 1000 AS [Duration (ms)],
    cpu_time_us / 1000 AS [CPU Time (ms)],
    logical_reads AS [Logical Reads],
    row_count AS [Row Count],
    session_id AS [Session ID],
    client_app_name AS [Application Name],
    client_hostname AS [Host Name],
    login_name AS [Login Name],
    LEFT(sql_statement, 200) AS [SQL Text (truncated)]
FROM RawEvents
ORDER BY event_time_utc DESC;
Key difference: Uses
sys.dm_xe_sessions
and
sys.dm_xe_session_targets
(server-scoped DMVs) instead of
sys.dm_xe_database_sessions
and
sys.dm_xe_database_session_targets
.
连接到 SQL Server(本地部署)或 Azure SQL Managed Instance 时使用:
sql
;WITH XEData AS (
    SELECT
        CAST(xet.target_data AS XML) AS target_data
    FROM sys.dm_xe_sessions AS xes
    INNER JOIN sys.dm_xe_session_targets AS xet
        ON xes.address = xet.event_session_address
    WHERE xes.name = 'BlockingInvestigation'
      AND xet.target_name = 'ring_buffer'
),
RawEvents AS (
    SELECT
        evt.value('(@name)', 'nvarchar(100)') AS event_name,
        evt.value('(@timestamp)', 'datetime2') AS event_time_utc,
        evt.value('(data[@name="duration"]/value)[1]', 'bigint') AS duration_us,
        evt.value('(data[@name="cpu_time"]/value)[1]', 'bigint') AS cpu_time_us,
        evt.value('(data[@name="logical_reads"]/value)[1]', 'bigint') AS logical_reads,
        evt.value('(data[@name="row_count"]/value)[1]', 'bigint') AS row_count,
        evt.value('(data[@name="statement"]/value)[1]', 'nvarchar(max)') AS sql_statement,
        evt.value('(action[@name="client_app_name"]/value)[1]', 'nvarchar(256)') AS client_app_name,
        evt.value('(action[@name="client_hostname"]/value)[1]', 'nvarchar(256)') AS client_hostname,
        evt.value('(action[@name="server_principal_name"]/value)[1]', 'nvarchar(256)') AS login_name,
        evt.value('(action[@name="session_id"]/value)[1]', 'int') AS session_id
    FROM XEData
    CROSS APPLY target_data.nodes('RingBufferTarget/event') AS t(evt)
)
SELECT
    event_time_utc AS [Event Time (UTC)],
    event_name AS [Event],
    duration_us / 1000 AS [Duration (ms)],
    cpu_time_us / 1000 AS [CPU Time (ms)],
    logical_reads AS [Logical Reads],
    row_count AS [Row Count],
    session_id AS [Session ID],
    client_app_name AS [Application Name],
    client_hostname AS [Host Name],
    login_name AS [Login Name],
    LEFT(sql_statement, 200) AS [SQL Text (truncated)]
FROM RawEvents
ORDER BY event_time_utc DESC;
主要区别:SQL Server 变体使用
sys.dm_xe_sessions
和
sys.dm_xe_session_targets
(服务器级 DMV),而不是
sys.dm_xe_database_sessions
和
sys.dm_xe_database_session_targets
(数据库级 DMV)。

Query 2: Query Store Wait Categories (Universal)

查询 2:Query Store 等待类别(通用)

This query works on all platforms with Query Store enabled:
sql
SELECT TOP (20)
    q.query_id AS [Query ID],    q.query_hash AS [Query Hash],
    ws.wait_category_desc AS [Wait Category],
    SUM(ws.total_query_wait_time_ms) AS [Total Wait Time (ms)],
    SUM(ws.avg_query_wait_time_ms * ws.total_query_wait_time_ms)
        / NULLIF(SUM(ws.total_query_wait_time_ms), 0) AS [Weighted Avg Wait (ms)],
    SUM(ws.total_query_wait_time_ms) * 100.0
        / NULLIF(SUM(SUM(ws.total_query_wait_time_ms)) OVER (PARTITION BY q.query_id), 0)
        AS [Wait Category % of Query Total],
    COUNT(DISTINCT p.plan_id) AS [Plan Count]
FROM sys.query_store_query q
INNER JOIN sys.query_store_query_text qt
    ON q.query_text_id = qt.query_text_id
INNER JOIN sys.query_store_plan p
    ON q.query_id = p.query_id
INNER JOIN sys.query_store_wait_stats ws
    ON p.plan_id = ws.plan_id
INNER JOIN sys.query_store_runtime_stats_interval rsi
    ON ws.runtime_stats_interval_id = rsi.runtime_stats_interval_id
WHERE rsi.start_time >= DATEADD(MINUTE, -60, GETUTCDATE())
  AND q.is_internal_query = 0
GROUP BY q.query_id, ws.wait_category_desc
ORDER BY [Total Wait Time (ms)] DESC;
此查询适用于所有已启用 Query Store 的平台:
sql
SELECT TOP (20)
    q.query_id AS [Query ID],    q.query_hash AS [Query Hash],
    ws.wait_category_desc AS [Wait Category],
    SUM(ws.total_query_wait_time_ms) AS [Total Wait Time (ms)],
    SUM(ws.avg_query_wait_time_ms * ws.total_query_wait_time_ms)
        / NULLIF(SUM(ws.total_query_wait_time_ms), 0) AS [Weighted Avg Wait (ms)],
    SUM(ws.total_query_wait_time_ms) * 100.0
        / NULLIF(SUM(SUM(ws.total_query_wait_time_ms)) OVER (PARTITION BY q.query_id), 0)
        AS [Wait Category % of Query Total],
    COUNT(DISTINCT p.plan_id) AS [Plan Count]
FROM sys.query_store_query q
INNER JOIN sys.query_store_query_text qt
    ON q.query_text_id = qt.query_text_id
INNER JOIN sys.query_store_plan p
    ON q.query_id = p.query_id
INNER JOIN sys.query_store_wait_stats ws
    ON p.plan_id = ws.plan_id
INNER JOIN sys.query_store_runtime_stats_interval rsi
    ON ws.runtime_stats_interval_id = rsi.runtime_stats_interval_id
WHERE rsi.start_time >= DATEADD(MINUTE, -60, GETUTCDATE())
  AND q.is_internal_query = 0
GROUP BY q.query_id, ws.wait_category_desc
ORDER BY [Total Wait Time (ms)] DESC;

Query 3: Check for Currently Active Blocking (Universal)

查询 3:检查当前活动阻塞(通用)

This query works on all platforms:
sql
SELECT
    r.session_id AS [Session ID],
    r.blocking_session_id AS [Blocking Session ID],
    DB_NAME(r.database_id) AS [Database],
    s.program_name AS [Application Name],
    s.host_name AS [Host Name],
    s.login_name AS [Login Name],
    r.status AS [Request Status],
    r.command AS [Command],
    r.wait_type AS [Wait Type],
    r.wait_time AS [Wait Time (ms)],
    r.wait_resource AS [Wait Resource],
    r.start_time AS [Request Start Time],
    DATEDIFF(SECOND, r.start_time, GETDATE()) AS [Elapsed Seconds],
    r.open_transaction_count AS [Open Transactions],    r.query_hash AS [Query Hash],
    r.plan_handle AS [Plan Handle]
FROM sys.dm_exec_sessions s
INNER JOIN sys.dm_exec_connections c
    ON s.session_id = c.session_id
INNER JOIN sys.dm_exec_requests r
    ON s.session_id = r.session_id
    AND (
        r.connection_id IS NULL
        OR r.connection_id = c.connection_id
        )
WHERE s.is_user_process = 1
    AND r.blocking_session_id <> 0
OPTION (MAXDOP 1, USE HINT ('FORCE_DEFAULT_CARDINALITY_ESTIMATION','QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_160','ENABLE_QUERY_OPTIMIZER_HOTFIXES'))
此查询适用于所有平台:
sql
SELECT
    r.session_id AS [Session ID],
    r.blocking_session_id AS [Blocking Session ID],
    DB_NAME(r.database_id) AS [Database],
    s.program_name AS [Application Name],
    s.host_name AS [Host Name],
    s.login_name AS [Login Name],
    r.status AS [Request Status],
    r.command AS [Command],
    r.wait_type AS [Wait Type],
    r.wait_time AS [Wait Time (ms)],
    r.wait_resource AS [Wait Resource],
    r.start_time AS [Request Start Time],
    DATEDIFF(SECOND, r.start_time, GETDATE()) AS [Elapsed Seconds],
    r.open_transaction_count AS [Open Transactions],    r.query_hash AS [Query Hash],
    r.plan_handle AS [Plan Handle]
FROM sys.dm_exec_sessions s
INNER JOIN sys.dm_exec_connections c
    ON s.session_id = c.session_id
INNER JOIN sys.dm_exec_requests r
    ON s.session_id = r.session_id
    AND (
        r.connection_id IS NULL
        OR r.connection_id = c.connection_id
        )
WHERE s.is_user_process = 1
    AND r.blocking_session_id <> 0
OPTION (MAXDOP 1, USE HINT ('FORCE_DEFAULT_CARDINALITY_ESTIMATION','QUERY_OPTIMIZER_COMPATIBILITY_LEVEL_160','ENABLE_QUERY_OPTIMIZER_HOTFIXES'))

Report Template

报告模板

Present the combined results in this exact format:
undefined
严格按以下格式呈现组合结果:
undefined

Query Blocking Root Cause Report

Query Blocking Root Cause Report

Database: {{database name}} Date: {{current date in YYYY-MM-DD format}} Data Sources: BlockingInvestigation XE Session + Query Store + DMVs

Database: {{database name}} Date: {{current date in YYYY-MM-DD format}} Data Sources: BlockingInvestigation XE Session + Query Store + DMVs

Prerequisites Check

Prerequisites Check

{{If Query 1 (XE data) returns no rows, display this and STOP:}}
The BlockingInvestigation XE session has not captured any data yet. This could mean:
  1. The XE session has not been created. Use the
    create-xe-session
    skill to set it up.
  2. The suspect query has not executed since the session was started. Wait for the workload to run and try again.
  3. The query text pattern used when creating the session does not match the suspect query.
{{Skip the remaining sections if no XE data.}}

{{If Query 1 (XE data) returns no rows, display this and STOP:}}
The BlockingInvestigation XE session has not captured any data yet. This could mean:
  1. The XE session has not been created. Use the
    create-xe-session
    skill to set it up.
  2. The suspect query has not executed since the session was started. Wait for the workload to run and try again.
  3. The query text pattern used when creating the session does not match the suspect query.
{{Skip the remaining sections if no XE data.}}

XE Captured Executions

XE Captured Executions

{{Display all captured query executions from Query 1:}}
Time (UTC)EventDuration (ms)CPU (ms)Logical ReadsSession IDApplicationHostLoginQuery Hash
{{one row per captured event, truncate SQL to 100 characters}}

{{Display all captured query executions from Query 1:}}
Time (UTC)EventDuration (ms)CPU (ms)Logical ReadsSession IDApplicationHostLoginQuery Hash
{{one row per captured event, truncate SQL to 100 characters}}

Source Identification

Source Identification

{{This is the CRITICAL section. Analyze the XE data to identify the blocking source:}}
{{This is the CRITICAL section. Analyze the XE data to identify the blocking source:}}

Sessions Running the Suspect Query

Sessions Running the Suspect Query

Application NameHost NameLogin# ExecutionsAvg Duration (ms)Max Duration (ms)
{{Group XE data by application, host, login — these are the sessions running the query that gets blocked}}
Application NameHost NameLogin# ExecutionsAvg Duration (ms)Max Duration (ms)
{{Group XE data by application, host, login — these are the sessions running the query that gets blocked}}

Currently Active Blocking (if any)

Currently Active Blocking (if any)

{{If Query 3 returned results, display a summary table.}} {{If no active blocking: "No active blocking detected at the time of this report."}}

{{If Query 3 returned results, display a summary table.}} {{If no active blocking: "No active blocking detected at the time of this report."}}

Query Store Wait Correlation

Query Store Wait Correlation

{{Show the wait categories from Query 2 for the queries that match the XE-captured SQL text:}}
Wait CategoryTotal Wait Time (ms)Interpretation
{{If Lock waits are present: "CONFIRMED — Lock waits detected, confirming blocking as the root cause."}}
{{Note any other significant wait categories that may be contributing.}}

{{Show the wait categories from Query 2 for the queries that match the XE-captured SQL text:}}
Wait CategoryTotal Wait Time (ms)Interpretation
{{If Lock waits are present: "CONFIRMED — Lock waits detected, confirming blocking as the root cause."}}
{{Note any other significant wait categories that may be contributing.}}

Root Cause Assessment

Root Cause Assessment

{{Provide a clear 2-3 sentence assessment:}}
  1. Source: Identify the application(s) and host(s) running the suspect query based on XE data.
  2. Confirmation: State whether blocking was confirmed via Lock waits in Query Store.
  3. Pattern: If the XE captured both high-duration and low-duration executions of the same query, the blocking is intermittent. If ALL executions are high-duration, blocking may be persistent.
  4. Blocker Identity: Note that the XE session captures the VICTIM's identity (the session running the suspect query). The BLOCKER is the other session holding the lock. If active blocking is detected (Query 3), the blocker's identity is known. If not, the blocker has already released the locks.

{{Provide a clear 2-3 sentence assessment:}}
  1. Source: Identify the application(s) and host(s) running the suspect query based on XE data.
  2. Confirmation: State whether blocking was confirmed via Lock waits in Query Store.
  3. Pattern: If the XE captured both high-duration and low-duration executions of the same query, the blocking is intermittent. If ALL executions are high-duration, blocking may be persistent.
  4. Blocker Identity: Note that the XE session captures the VICTIM's identity (the session running the suspect query). The BLOCKER is the other session holding the lock. If active blocking is detected (Query 3), the blocker's identity is known. If not, the blocker has already released the locks.

Recommendations

Recommendations

{{Based on the root cause, provide 3-5 specific, actionable recommendations:}}
  1. Investigate the blocking application: "The application '{{app name}}' on host '{{host}}' running as login '{{login}}' is the source. Review its transaction management — look for long-running transactions, missing COMMIT/ROLLBACK, or excessive lock scope."
  2. Reduce lock duration: "If the blocking query performs large data modifications, consider breaking it into smaller batches (e.g., process 1,000 rows per transaction instead of the entire dataset)."
  3. Add retry logic: "Add retry logic with exponential backoff in the affected application for transient blocking. This improves resilience without changing the database."
  4. Improve indexing: "Review indexes on the contended tables. More selective indexes reduce the number of rows locked per operation, reducing lock conflicts."
  5. Schedule off-peak: "If the blocking comes from a batch job or maintenance operation, consider scheduling it during off-peak hours when contention is lower."
  6. Consider isolation level changes: "If the workload supports it, enabling READ COMMITTED SNAPSHOT (RCSI) allows readers to proceed without being blocked by writers."
  7. Live monitoring: "To see the blocking in real-time next time it occurs, use the
    check-live-blocking
    skill when users report slowness."
undefined
{{Based on the root cause, provide 3-5 specific, actionable recommendations:}}
  1. Investigate the blocking application: "The application '{{app name}}' on host '{{host}}' running as login '{{login}}' is the source. Review its transaction management — look for long-running transactions, missing COMMIT/ROLLBACK, or excessive lock scope."
  2. Reduce lock duration: "If the blocking query performs large data modifications, consider breaking it into smaller batches (e.g., process 1,000 rows per transaction instead of the entire dataset)."
  3. Add retry logic: "Add retry logic with exponential backoff in the affected application for transient blocking. This improves resilience without changing the database."
  4. Improve indexing: "Review indexes on the contended tables. More selective indexes reduce the number of rows locked per operation, reducing lock conflicts."
  5. Schedule off-peak: "If the blocking comes from a batch job or maintenance operation, consider scheduling it during off-peak hours when contention is lower."
  6. Consider isolation level changes: "If the workload supports it, enabling READ COMMITTED SNAPSHOT (RCSI) allows readers to proceed without being blocked by writers."
  7. Live monitoring: "To see the blocking in real-time next time it occurs, use the
    check-live-blocking
    skill when users report slowness."
undefined

Correlating incident captures

关联事件捕获结果

Use the shared incident evidence rules: execution-weighted averages, per-query time windows, positive-session blocking graphs, sleeping heads and distinct downstream counts. Keep diagnostic candidates separate from authorized actions.
使用共享事件证据规则:按执行次数加权的平均值、按查询划分的时间窗口、仅包含正向会话的阻塞图、休眠的头阻塞会话以及不同的下游会话数量。将诊断候选项与已授权操作明确区分。