Troubleshooting Deadlocks and Blocking Chains

Troubleshooting Deadlocks and Blocking Chains

131
Created On 11/10/26 11:03 AM - Last Modified 11/10/26 15:56 PM


Symptom


During normal operations, it is possible for TPP to execute a sequence of SQL queries which create a deadlock scenario. Typically, one transaction is automatically chosen as the deadlock victim, and operations proceed as normal. Other SQL processing issues include long-running queries and blocking chains and may require intervention like resetting an object in the Web Console so that processing can resume as normal.

In extreme cases of blocking chains, an environment may become completely unresponsive if it cannot self-resolve the blocking chain. In this situation, the quickest resolution would be to stop/start all TPP services and IIS (stop vplatform, then stop log server, restart IIS, start vplatform, start log server) on each server in the environment.

If your environment has performance issues related to deadlocks or blocking queries, and restarting the Venafi-related services as a workaround is not sufficient, you can use one of the following SQL queries to collect critical data regarding the block(s). Providing these results to Customer Support can be very useful in tracking down root cause, etc.

 

  1. Deadlock query, which pulls a deadlock graph and can be exported from SSMS:

DECLARE @xelfilepath NVARCHAR(260)

SELECT @xelfilepath = dosdlc.path

FROM sys.dm_os_server_diagnostics_log_configurations AS dosdlc;

SELECT @xelfilepath = @xelfilepath + N'system_health_*.xel'

 DROP TABLE IF EXISTS  #TempTable

 SELECT CONVERT(XML, event_data) AS EventData

        INTO #TempTable FROM sys.fn_xe_file_target_read_file(@xelfilepath, NULL, NULL, NULL)

         WHERE object_name = 'xml_deadlock_report'

SELECT EventData.value('(event/@timestamp)[1]', 'datetime2(7)') AS UtcTime,

            CONVERT(DATETIME, SWITCHOFFSET(CONVERT(DATETIMEOFFSET,

      EventData.value('(event/@timestamp)[1]', 'VARCHAR(50)')), DATENAME(TzOffset, SYSDATETIMEOFFSET()))) AS LocalTime,

            EventData.query('event/data/value/deadlock') AS XmlDeadlockReport

     FROM #TempTable

     ORDER BY UtcTime DESC;

    1. Click on the xml column to open that in a new window.  You can save it as .xdl file and open that file in SSMS to see visual representation of the deadlock.  Some of these deadlocking conditions are automatically handled and retried in later versions.
  1. Blocking queries:
    1. Check blocking queries with:

SELECT

    session_id,

    start_time,

    [status],

    command,

    blocking_session_id,

    wait_type,

    wait_time,

    open_transaction_count,

    transaction_id,

    total_elapsed_time,

    Definition = CAST(text AS VARCHAR(MAX))

FROM

    SYS.DM_EXEC_REQUESTS

    CROSS APPLY sys.dm_exec_sql_text(sql_handle)

WHERE blocking_session_id != 0

 

    1. Check the query from blocking session id with:

declare

    @spid int

,   @stmt_start int

,   @stmt_end int

,   @sql_handle binary(20)

set @spid = 297

select  top 1

    @sql_handle = sql_handle

,   @stmt_start = case stmt_start when 0 then 0 else stmt_start / 2 end

,   @stmt_end = case stmt_end when -1 then -1 else stmt_end / 2 end

from    sys.sysprocesses

where   spid = @spid

order by ecid

SELECT

    SUBSTRING(  text,

            COALESCE(NULLIF(@stmt_start, 0), 1),

            CASE @stmt_end

                WHEN -1

                    THEN DATALENGTH(text)

                ELSE

                    (@stmt_end - @stmt_start)

                END

        )

FROM ::fn_get_sql(@sql_handle)

 

    1. Check expensive CPU queries / sessions and use query from item 'b.' above to check what those sessions are doing:

SELECT TOP 10 s.session_id,

           r.status,

           r.cpu_time,

           r.logical_reads,

           r.reads,

           r.writes,

           r.total_elapsed_time / (1000 * 60) 'Elaps M',

           SUBSTRING(st.TEXT, (r.statement_start_offset / 2) + 1,

           ((CASE r.statement_end_offset

                WHEN -1 THEN DATALENGTH(st.TEXT)

                ELSE r.statement_end_offset

            END - r.statement_start_offset) / 2) + 1) AS statement_text,

           COALESCE(QUOTENAME(DB_NAME(st.dbid)) + N'.' + QUOTENAME(OBJECT_SCHEMA_NAME(st.objectid, st.dbid))

           + N'.' + QUOTENAME(OBJECT_NAME(st.objectid, st.dbid)), '') AS command_text,

           r.command,

           s.login_name,

           s.host_name,

           s.program_name,

           s.last_request_end_time,

           s.login_time,

           r.open_transaction_count

FROM sys.dm_exec_sessions AS s

JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id CROSS APPLY sys.Dm_exec_sql_text(r.sql_handle) AS st

WHERE r.session_id != @@SPID

ORDER BY r.cpu_time DESC

 

For more information, see Microsoft’s documentation.

https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-deadlocks-guide?view=sql-server-ver17

 



Environment


TPP/TLSPDC TLSPDC

Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/KCSArticleDetail?id=kA1hj00000010XWCAY&lang=en_US&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FKCSArticleDetail