SQL Server Disk I/O Latency by File
Calculates read/write latency in ms for every data and log file. Used to prove disk-related slowness.
SELECT DB_NAME(vfs.database_id) AS db_name, mf.physical_name, mf.type_desc,
vfs.num_of_reads, vfs.num_of_writes,
CAST(vfs.io_stall_read_ms / NULLIF(vfs.num_of_reads, 0) AS DECIMAL(10,1)) AS avg_read_ms,
CAST(vfs.io_stall_write_ms / NULLIF(vfs.num_of_writes, 0) AS DECIMAL(10,1)) AS avg_write_ms
FROM sys.dm_io_virtual_file_stats(NULL, NULL) vfs
JOIN sys.master_files mf ON mf.database_id = vfs.database_id AND mf.file_id = vfs.file_id
ORDER BY (vfs.io_stall_read_ms + vfs.io_stall_write_ms) DESC;Sustained read/write latencies exceeding 20ms typically indicate disk storage subsystem saturation.
- This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
- Prior to executing on production systems under high load, verify the target database version (Min. Version: 2008).
- Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.
Engineering Triad: Related Runbooks & Incident Response
Which production incidents and emergency drills execute this script as a diagnosis step?
SQL Server Disk I/O Latency: Diagnose Data and Transaction Log Bottlenecks
Measures read/write latency by file using differences between samples and separates query, backup and storage causes.
SQL Server Corruption - Error 823/824/825: DBCC CHECKDB & Page Restore
Emergency corruption triage for Msg 823, 824, 825 I/O errors and suspect_pages: surgical Page Restore with log chains, nonclustered index rebuilds, and REPAIR_ALLOW_DATA_LOSS disaster procedures without taking DB offline.
Other SQLSERVER Diagnostic Scripts
View All (100)SQL Server Running Requests and Blocking Chain
Shows active requests, wait types, blocking sessions and the running statement together. The first diagnostic query to run during a slowdown.
Top CPU-Consuming Queries in SQL Server
Lists the top 20 queries by total and average CPU time from the plan cache. Pinpoints the source of CPU pressure at query level.
SQL Server Missing Index Recommendations (Missing Index DMVs)
Ranks the optimizer's missing index suggestions by estimated benefit. Merge them with existing indexes before applying.
SQL Server Index Fragmentation with Rebuild/Reorganize Advice
Measures fragmentation on large indexes and recommends rebuild or reorganize. Lets you plan maintenance windows without wasted work.