2019年11月27日 星期三

使用 SQL Server Profiler 檢視和分析追蹤

使用 SQL Server Profiler 檢視和分析追蹤

測量單位

  • Duration: SQL Server Profiler 顯示 Duration column in milliseconds(10-3 of a second) by default. Trace儲存到檔案或資料表時 in microseconds(10-6 of a second)
  • CPU: in milliseconds(10-3 of a second)


使用
1.啟動SQL Server Profiler

2.新增一個追蹤New Trace

3.登入欲追蹤的SQL Server

4.追蹤屬性設定視窗
    有兩個頁籤,預設顯示一般設定(General)頁籤

5.預設的追蹤事件
切換到事件選取(Events Selection)頁籤,可自訂事件(勾選需要的事件)

6.使用追蹤範本
   也可在一般設定(General)頁籤,依據不同追蹤目的可選擇不同的範本,不同的範本有定義不同的追蹤事件Events,選取後Event Selection頁籤的事件就會依據所選的範本而變動

7.若要自訂追蹤事件
    在事件選取(Events Selection)頁籤,可勾選Show all events顯示所有事件,才會顯示所有事件

    部分不常用追蹤欄位預設是隱藏的,可勾選Show all columns,才會顯示所有可用欄位

    展開前方的加號(+),就可以勾選該類別的各別事件與特定的欄位

    若需要過濾事件,可以點選Column filters,再去設定特定欄位的過濾條件
    例如預設已設定不會收集到SQL Server Profiler本身所執行的SQL Query。


8.設定追蹤儲存至實體檔案
   若需要在追蹤時就儲存實體檔案,則可在一般設定(General)頁籤
   (1)勾選Save to file,並指定檔案位置與檔名
   (2)建議設定追蹤檔大小上限,在set maximum file size輸入350
   (3)預設啟用檔案換用Enable file rollover,建議保留不動
   (4)預設不啟用伺服器處理追蹤資料,建議保留不動。
       若啟用時,因為當SQL Server負載大極度忙碌時,也不會略過追蹤,可能會造成性能的影響
     "Server processes trace data" tells the service running the trace to process the trace data and not the client application. With this option selected no trace data will ever be skipped even if the server is extremely busy, but note that your server performance may be affected if this happens


9.設定追蹤儲存至資料表
    不建議啟用,此動作可在收集完成後再手動進行匯入資料表。
    若勾選了,則要選擇連線到目的地SQL Servre與資料表。


10.設定自動停止追蹤
    若有需要自動停止追蹤,則勾選Enable trace stop time,然後指定一個停止日期與時間之後,當追蹤開始收集,就會自動在指定的時間自動停止。

Check the "Enable trace stop time" checkbox and give the time at which you want to stop track, SQL Server will automatically stop trace on that time.

11.開始收集追蹤
     按下 Run 就會開始執行收集


12.開始收集時的畫面如下
    可透過上方的工具列,按下暫停可暫停追蹤,但下停止可以停止追蹤。


13.另存追蹤
   按下File>Save As>Trace File... 可將目前顯是的追蹤內容,儲存到實體檔案
   按下File>Save As>Trace Table... 可將目前顯是的追蹤內容,儲存到資料表


分析案例
如果是SSIS Package資料流data flow的OLE DB Source - SQL Command with Parameter,則錄不到傳入的參數值,RPC:: Completed只會出現@P1, @P2
既使有選擇Stored Procedure與TSQL所有Event,仍然找不到傳入的參數值



沒有留言:

SQL Server Database Mirroring 資料庫鏡像

SQL Server Database Mirroring 資料庫鏡像