日期:2014-05-17 浏览次数:20520 次
-- Various SQL Server IO Statistics
;WITH?
?IOT AS??? -- Total sums of all properties.
???(SELECT SUM(IOS.num_of_reads) AS Reads
??????????,SUM(IOS.num_of_bytes_read) BytesRead
??????????,SUM(IOS.io_stall_read_ms) AS IoStallReadMs
??????????,SUM(IOS.num_of_writes) AS Writes
??????????,SUM(IOS.num_of_bytes_written) AS BytesWritten
??????????,SUM(IOS.io_stall_write_ms) AS IoStallWritesMs
??????????,SUM(IOS.io_stall) AS IoStall
??????????,SUM(IOS.size_on_disk_bytes) SizeOnDisk
????FROM sys.dm_io_virtual_file_stats(default, default) AS IOS)
,IOF AS???
???(SELECT DBS.name AS DatabaseName
??????????,MF.name AS [FileName]
??????????,MF.type_desc AS FileType
??????????,SUBSTRING(MF.physical_name, 1, 3) AS Drive
??????????,CASE WHEN DBS.name IN ('master', 'model', 'msdb', 'tempdb')
????????????????THEN 1 ELSE 0 END AS IsSystemDB
??????????,IOS.*
????FROM sys.dm_io_virtual_file_stats(default, default) AS IOS
?????????INNER JOIN sys.databases AS DBS
?????????????ON IOS.database_id = DBS.database_id
?????????INNER JOIN sys.master_files AS MF
?????????????ON IOS.database_id = MF.database_id
????????????????AND IOS.file_id = MF.file_id)
/*
-- Detailed for each file
SELECT IOF.DatabaseName
??????,IOF.FileName
??????,IOF.FileType
??????,CONVERT(numeric(5,2), 100.0 * IOF.num_of_reads / IOT.Reads) AS [Reads%]