dataiotech Labs
Scripts Library/sqlserver/#55
Script #55
sqlserver
Performanceread-onlyMin Version: 2008

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.

#io-latency#virtual-file-stats#storage
sqlserver · sql
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;
Operational Notes & Remediation Guidance

Sustained read/write latencies exceeding 20ms typically indicate disk storage subsystem saturation.

Production Safety & Execution Standards
  • 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?

Runbook Library (63)
Related Alerts & Metrics
M31SQL Server Disk I/O LatencySQL Server