1. 查找 I/O 闩锁等待统计信息
select wait_type, waiting_tasks_count, wait_time_ms, signal_wait_time_ms, wait_time_ms / waiting_tasks_count
from sys.dm_os_wait_stats
where wait_type like 'PAGEIOLATCH%' and waiting_tasks_count > 0
order by wait_type
如果 waiting_task_counts 和 wait_time_ms 与正常情况相比有显著变化,则可以确定存在 I/O 问题。
2. 查找当前挂起的 I/O 请求
select database_id, file_id, io_stall, io_pending_ms_ticks, scheduler_address
from sys.dm_io_virtual_file_stats(NULL, NULL)t1, sys.dm_io_pending_io_requests as t2
where t1.file_handle = t2.io_handle
在正常情况下,该查询通常不返回任何内容。如果此查询返回一些行,则需要进一步调查。
3. 平均IO最多的5个SQL
select top 5 (total_logical_reads/execution_count) as avg_logical_reads,(total_logical_writes/execution_count) as avg_logical_writes,
(total_physical_reads/execution_count) as avg_physical_reads, Execution_count, statement_start_offset, p.query_plan, q.text
from sys.dm_exec_query_stats cross apply sys.dm_exec_query_plan(plan_handle) p cross apply sys.dm_exec_sql_text(plan_handle) as q
order by (total_logical_reads + total_logical_writes)/execution_count Desc