延續 先前文章:[SQL Server] sp_whoisactive: find out long running queries (找出費時、耗資源的查詢)
補充 常用的範例
-- EX01_sp_WhoIsActive:增加顯示 執行計畫、交易資訊、封鎖資訊等 USE master GO EXEC sp_WhoIsActive @get_plans=1, @get_transaction_info=1, @find_block_leaders=1 GO -- EX02_sp_WhoIsActive:增加顯示 執行計畫、交易資訊、封鎖資訊、系統資訊等 USE master GO EXEC sp_WhoIsActive @get_plans=1, @get_transaction_info=1, @find_block_leaders=1, @get_task_info=2 GO -- EX03_sp_WhoIsActive:增加顯示 執行計畫、交易資訊、封鎖資訊、系統資訊、 -- 取得更多關聯的 ad hoc 查詢或 執行預存程序的呼叫程序、 -- 取得此工作階段(Session)上的更多參考資訊 USE master GO EXEC sp_WhoIsActive @get_plans=1, @get_transaction_info=1, @find_block_leaders=1, @get_task_info=2, @get_outer_command = 1, @get_additional_info = 2 GO
sp_whoisactive 參數說明 2
目前已有24個以上的參數,善用 @help = 1 來查詢使用方式。
參數 | 說明 |
@get_outer_command = 1 | 嘗試取得更多關聯的 ad hoc 查詢或 執行預存程序的呼叫程序 Get the associated outer ad hoc query or stored procedure call, if available |
@sort_order ='[blocked_session_count] ASC' |
排序
Column(s) by which to sort output, optionally with sort directions.
Valid column choices:
session_id, physical_io, reads, physical_reads, writes, tempdb_allocations, tempdb_current, CPU, context_switches, used_memory, physical_io_delta,
reads_delta, physical_reads_delta, writes_delta, tempdb_allocations_delta, tempdb_current_delta, CPU_delta, context_switches_delta, used_memory_delta,
tasks, tran_start_time, open_tran_count, blocking_session_id, blocked_session_count, percent_complete, host_name, login_name, database_name, start_time, login_time
Note that column names in the list must be bracket-delimited.
Commas and/or white space are not required.
|
@get_additional_info = 1 |
取得此工作階段(Session)上的更多參考資訊。
Get additional non-performance-related information about the session or request text_size, language, date_format, date_first, quoted_identifier, arithabort, ansi_null_dflt_on, ansi_defaults, ansi_warnings, ansi_padding, ansi_nulls, concat_null_yields_null, transaction_isolation_level, lock_timeout, deadlock_priority, row_count, command_type.
If a SQL Agent job is running, an subnode called agent_info will be populated with some or all of the following: job_id, job_name, step_id, step_name, msdb_query_error (in the event of an error)
If @get_task_info is set to 2 and a lock wait is detected, a subnode called block_info will be populated with some or all of the following: lock_type, database_name, object_id, file_id, hobt_id, applock_hash, metadata_resource, metadata_class_id, object_name, schema_name.
|
@help = 1 | 顯示出可用的參數與說明 |
sp_whoisactive 使用範例
-- 010_使用help_線上說明
-- 011_get_outer_command=1_ 取得此工作階段(Session)上的更多參考資訊
-- 012_get_outer_command=1_ 取得此工作階段(Session)上的更多參考資訊_2
-- 013_增加顯示:封鎖鏈結、封鎖計數,但沒有排序
-- 014_顯示:封鎖鏈結、封鎖計數,並依據 blocked_session_count 排序
-- 015_取得此工作階段(Session)上的更多參考資訊
-- 016_取得此工作階段(Session)上的更多參考資訊_xml_交易隔離層級
-- 021_顯示 執行計畫、交易資訊、封鎖資訊、系統資訊、取得更多關聯的 ad hoc 查詢或 執行預存程序的呼叫程序、取得此工作階段(Session)上的更多參考資訊
-- 022_延續 021_顯示 執行計畫...
-- 023_延續 021_顯示 執行計畫...
-- 024_延續 021_顯示 執行計畫...
-- 025_延續 021_顯示 執行計畫...
sp_whoisactive 使用範例程式碼(2)
-- EX01-sp_WhoIsActive:線上說明 USE master GO EXEC sp_WhoIsActive @help = 1 GO -- EX02-sp_WhoIsActive: @get_outer_command= 1 , -- 嘗試取得更多關聯的 ad hoc 查詢或 執行預存程序的呼叫程序 USE master GO EXEC sp_WhoIsActive @get_outer_command = 1 GO
-- EX03-sp_WhoIsActive:增加顯示:封鎖鏈結、封鎖計數, -- 並依據 blocked_session_count 排序 USE master GO EXEC sp_WhoIsActive @find_block_leaders = 1 , @sort_order ='[blocked_session_count] ASC' GO -- EX04-sp_WhoIsActive:取得此工作階段(Session)上的更多參考資訊 USE master GO EXEC sp_WhoIsActive @get_additional_info = 1 GO
-- EX05-sp_WhoIsActive: -- 增加顯示 執行計畫、交易資訊、封鎖資訊、系統資訊、 -- 取得更多關聯的 ad hoc 查詢或 執行預存程序的呼叫程序、取得此工作階段(Session)上的更多參考資訊 USE master GO EXEC sp_WhoIsActive @get_plans=1, @get_transaction_info=1, @find_block_leaders=1, @get_task_info=2, @get_outer_command = 1, @get_additional_info = 2 GO
參考資料
[SQL Server] sp_whoisactive: find out long running queries (找出費時、耗資源的查詢)
http://sharedderrick.blogspot.tw/2017/07/sql-server-spwhoisactive-find-out-long.html
sp_whoisactive
http://whoisactive.com/
Looking for sp_whoisactive?
http://sqlblog.com/blogs/adam_machanic/archive/2017/07/26/looking-for-sp-whoisactive.aspx
sp_whoisactive Documentation
http://whoisactive.com/docs/
沒有留言:
張貼留言