SQL Extended Events Session untuk deteksi kebuntuan

12

Apakah ada cara untuk meningkatkan ukuran <inputbuf>elemen dalam deadlock XML yang ditangkap oleh sesi deadlock extended events?

Kami ingin melihat kueri lengkap untuk membantu menentukan masalah dalam kode Aplikasi.

Tampaknya terbatas pada 1024 karakter +/-. Bisakah itu ditingkatkan?

Lihat di bawah untuk contoh XML. Anda dapat melihat bahwa teks kueri dalam <inputbuf>elemen terpotong di tengah daftar pilih:

<deadlock>
 <victim-list>
  <victimProcess id="processc9c0829848" />
 </victim-list>
 <process-list>
  <process id="processc9c0829848" taskpriority="0" logused="0" waitresource="PAGE: 5:1:40600276 " waittime="696" ownerId="255115931225" transactionname="SELECT" lasttranstarted="2019-04-24T09:29:25.950" XDES="0xc8dfa8da40" lockMode="S" schedulerid="13" kpid="8480" status="suspended" spid="245" sbid="2" ecid="0" priority="0" trancount="0" lastbatchstarted="2019-04-24T09:29:25.950" lastbatchcompleted="2019-04-24T09:29:25.950" lastattention="1900-01-01T00:00:00.950" clientapp="EntityFramework" hostname="MSR-PRD-BDB02" hostpid="43440" loginname="IUSR_BuildDB" isolationlevel="read committed (2)" xactid="255115931225" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
   <executionStack>
    <frame procname="adhoc" line="1" stmtstart="66" stmtend="7378" sqlhandle="0x02000000638e8b1acc45f82c476cd42914e32866e87c4fd60000000000000000000000000000000000000000">
unknown    </frame>
    <frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
unknown    </frame>
   </executionStack>
   <inputbuf>
(@p__linq__0 int,@p__linq__1 int)SELECT 
[Project1].[CachedBuildStateId] AS [CachedBuildStateId], 
[Project1].[BuildVersionId1] AS [BuildVersionID], 
[Project1].[ProjectID] AS [ProjectID], 
[Project1].[VersionName] AS [VersionName], 
[Project1].[PlatformID] AS [PlatformID], 
[Project1].[VersionPath] AS [VersionPath], 
[Project1].[RegionID] AS [RegionID], 
[Project1].[TestStatusID] AS [TestStatusID], 
[Project1].[TestResult] AS [TestResult], 
[Project1].[TestReportPath] AS [TestReportPath], 
[Project1].[TypeID] AS [TypeID], 
[Project1].[Size] AS [Size], 
[Project1].[VersionDate] AS [VersionDate], 
[Project1].[Approved] AS [Approved], 
[Project1].[Archived] AS [Archived], 
[Project1].[CLData] AS [CLData], 
[Project1].[CLCode] AS [CLCode], 
[Project1].[CLSound] AS [CLSound], 
[Project1].[XDKSDKVersion] AS [XDKSDKVersion], 
[Project1].[Comments] AS [Comments], 
[Project1].[DateAdded] AS [DateAdded], 
[Project1].[DateModified] AS [DateModified], 
[Project1].[CacheLocally] AS [CacheLocally],   </inputbuf>
  </process>
  <process id="processc9bf5cf468" taskpriority="0" logused="436" waitresource="PAGE: 5:1:3752363 " waittime="724" ownerId="255115931408" transactionname="user_transaction" lasttranstarted="2019-04-24T09:29:25.973" XDES="0xcf6b186408" lockMode="IX" schedulerid="25" kpid="11228" status="suspended" spid="209" sbid="2" ecid="0" priority="0" trancount="2" lastbatchstarted="2019-04-24T09:29:25.973" lastbatchcompleted="2019-04-24T09:29:25.970" lastattention="1900-01-01T00:00:00.970" clientapp="EntityFramework" hostname="MSR-PRD-BDB04" hostpid="6248" loginname="IUSR_BuildDB" isolationlevel="read committed (2)" xactid="255115931408" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056">
   <executionStack>
    <frame procname="adhoc" line="1" stmtstart="78" stmtend="408" sqlhandle="0x020000009438fe362ae846385f4e36448d4eac52a5f052e10000000000000000000000000000000000000000">
unknown    </frame>
    <frame procname="unknown" line="1" sqlhandle="0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000">
unknown    </frame>
   </executionStack>
   <inputbuf>
(@0 int,@1 datetime,@2 datetime,@3 int)update [dbo].[CachedBuildState]
set [CachingStatusId] = @0, [StartTimeUtc] = @1, [LastUpdateTimeUtc] = @2, [MessageDetails] = null
where ([CachedBuildStateId] = @3)
   </inputbuf>
  </process>
 </process-list>
 <resource-list>
  <pagelock fileid="1" pageid="40600276" dbid="5" subresource="FULL" objectname="BuildDB.dbo.CachedBuildState" id="lockcda4d62280" mode="IX" associatedObjectId="72057594075283456">
   <owner-list>
    <owner id="processc9bf5cf468" mode="IX" />
   </owner-list>
   <waiter-list>
    <waiter id="processc9c0829848" mode="S" requestType="wait" />
   </waiter-list>
  </pagelock>
  <pagelock fileid="1" pageid="3752363" dbid="5" subresource="FULL" objectname="BuildDB.dbo.CachedBuildState" id="lockd70db08700" mode="S" associatedObjectId="72057594075283456">
   <owner-list>
    <owner id="processc9c0829848" mode="S" />
   </owner-list>
   <waiter-list>
    <waiter id="processc9bf5cf468" mode="IX" requestType="wait" />
   </waiter-list>
  </pagelock>
 </resource-list>
</deadlock>
Snewfie
sumber

Jawaban:

2

Anda memiliki sqlhandleuntuk setiap frame sehingga Anda bisa mendapatkan kueri lengkap menggunakan sys.dm_exec_sql_textfungsi:

SELECT text
FROM sys.dm_exec_sql_text(sql_handle)

sys.dm_exec_sql_text

Misalnya, mendapatkan teks dari beberapa pernyataan dari sys.dm_exec_query_stats(stmtstart, stmtend, sqlhandle, bukannya statement_start_offset, statement_end_offset, sql_handle dalam laporan XML)

SELECT TOP (100)
    CASE   
        WHEN s.[statement_start_offset] > 0 THEN  
            --The start of the active command is not at the beginning of the full command text 
            CASE s.[statement_end_offset]  
               WHEN -1 THEN  
                  --The end of the full command is also the end of the active statement 
                  SUBSTRING(t.TEXT, (s.[statement_start_offset]/2) + 1, 2147483647) 
               ELSE   
                  --The end of the active statement is not at the end of the full command 
                  SUBSTRING(t.TEXT, (s.[statement_start_offset]/2) + 1, (s.[statement_end_offset] - s.[statement_start_offset])/2+1)   
            END  
        ELSE  
            --1st part of full command is running 
            CASE s.[statement_end_offset]  
               WHEN -1 THEN  
                  --The end of the full command is also the end of the active statement 
                  RTRIM(LTRIM(t.[text]))  
               ELSE  
                  --The end of the active statement is not at the end of the full command 
                  LEFT(t.TEXT, (s.[statement_end_offset]/2) +1)  
            END  
        END AS [executing statement]
FROM sys.dm_exec_query_stats s 
    CROSS APPLY sys.dm_exec_sql_text(s.[sql_handle]) t

UPD

Berkat komentar wajar @ JohnEisbrener, saya harus memperhatikan bahwa informasi dari DMVs akan aktual sampai cache kueri dibersihkan. Jadi, jika Anda berharap untuk menggunakan informasi itu setelah pembersihan cache (misalnya setelah server Anda restart), Anda harus menyimpan data itu dalam beberapa tabel permanen segera setelah peristiwa itu terjadi.

Denis Rubashkin
sumber
Ya saya sudah melakukan itu tetapi berharap bahwa pengaturan tiga waa yang dapat meningkatkannya dalam definisi sesi acara diperpanjang. Akan mencoba untuk melihat apakah saya dapat menghancurkan laporan kebuntuan dan meletakkan segala sesuatu di meja untuk tujuan historis untuk devleopeprs untuk melihat kembali. Sayangnya mereka menggunakan kerangka entitas untuk aplikasi ini. Akan memposting solusi saya setelah selesai
Snewfie