Tuesday, January 25, 2011

Storage performance via TSQL

Storage performance via TSQL

On SQL 2000 looking at I/O statistics is achieved using fn_virtualfilestats

   d.name as DBName
   ,RTRIM(b.name) AS LogicalFileName
   ,CASE WHEN (a.NumberReads = 0) THEN 0 ELSE a.IOStallReadMS / a.NumberReads END AS AvgReadTransfersMS
   ,CASE WHEN (a.NumberWrites = 0) THEN 0 ELSE a.IOStallWriteMS / a.NumberWrites END AS AvgWriteTransfersMS
FROM ::fn_virtualfilestats(-1,-1) a 
INNER JOIN sysaltfiles b ON a.dbid = b.dbid AND a.fileid = b.fileid
INNER JOIN sysdatabases d ON d.dbid = b.dbid
ORDER BY a.NumberWrites DESC
For SQL 2005+, sys.dm_io_virtual_file_stats is a available. This is a dynamic management function that shows how SQL is using the data files.

 DB_NAME(filestats.database_id) AS DBName
 ,files.name AS LogicalFileName
 ,num_of_reads AS NumberReads
 ,num_of_writes AS NumberWrites
 ,num_of_bytes_read AS BytesRead
 ,num_of_bytes_written AS BytesWritten
 ,io_stall_read_ms AS IOStallReadMS
 ,io_stall_write_ms AS IOStallWriteMS
   ,CASE WHEN (num_of_reads = 0) THEN 0 ELSE io_stall_read_ms / num_of_reads END AS AvgReadTransfersMS
   ,CASE WHEN (num_of_writes = 0) THEN 0 ELSE io_stall_write_ms / num_of_writes END AS AvgWriteTransfersMS
FROM sys.dm_io_virtual_file_stats(-1,-1) filestats
INNER JOIN sys.master_files files
  ON filestats.file_id = files.file_id
  AND filestats.database_id = files.database_id
ORDER BY num_of_writes DESC

Further info on here c/o David Pless

If Disk Performance is an issue, consider these aspects

No comments: