THE SQL Server Blog Spot on the Web
Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | Join | Help
in Search

Louis Davidson

sys.dm_io_virtual_file_stats

Excellent dmv that shows, for each file that SQL Server uses for the databases, stats on how frequently the file has been used by the database. This is one of the primary dynamic management views I use almost daily (well, not usually when I am on vacation, but even sometimes then!)  The file can be any file used in the database, including the log or full text files.

Type: Function

Parameters:

  • database_id – key of the database, retrieved from sys.databases
  • file_id - key of a file in a database. Can be retrieved from sys.database_files if you are working in the context of a database, or sys.master_files will give you all files in all databases

Columns:

  • database_id, file_id – same as the parameter descriptions
  • sample_ms – the number of milliseconds that have passed since the values for sys.dm_io_virtual_file_stats were reset the only way to reset the values is to restart the server.
  • num_of_reads – number of individual read operations that were issued to the file. Note that this is physical reads, not logical reads. Logical reads would not be registered.
  • num_of_bytes_read – the number of bytes that were read, as opposed to the number of reads. The size of a read is not a constant value that can be calculated by the number of reads.
  • Io_stall_read_ms – total time user processes waited for IO. Note that this number can be much greater than the sample_ms. If 10 processes are trying to use the file simultaneously, but the disk is only able to server 1, then you might get 9 seconds waiting over a 10 second time period.
  • num_of_writes , num_of_bytes_written, io_stall_write_ms - the same as the read values, except for writes.
  • io_stall – sum of io_stall_write_ms and io_stall_read_ms
  • size_on_disk_bytes – the size of the file in bytes
  • file_handle – the Windows file handle of the file (Books Online)

Example:

For all databases, get vital stats on how busy the file has been, since the last restart:

select db_name(mf.database_id) as databaseName, mf.physical_name, 
       
num_of_reads, num_of_bytes_read, io_stall_read_ms, num_of_writes,
      
num_of_bytes_written, io_stall_write_ms, io_stall,size_on_disk_bytes
from sys.dm_io_virtual_file_stats(null,null) as divfs
        
join sys.master_files as mf
             
on mf.database_id = divfs.database_id
                
and mf.file_id = divfs.file_id


Published Friday, July 27, 2007 9:26 PM by drsql

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Jason Haley said:

July 28, 2007 7:39 PM
 

Linchi Shea said:

Louis;

Are you sure num_of_writes are the physical writes for the data files?

Linchi

July 29, 2007 11:29 PM
 

drsql said:

Linchi, I am 99% sure, based on testing.  On my laptop, I ran the query in the Examples, and then this query (which was not in cache):

select *

from   adventureWorks.sales.individual

Then I reran the example query, and it showed a change in reads.  I then ran the query again, and this time no change in reads.  Next I ran a different query:

select *

from   adventureWorks.sales.customer

And saw the same behavior.  If I am interpreting this wrong, please let me know :)

July 31, 2007 11:20 PM
 

Linchi Shea said:

Louis;

But that's for reads. I was referring to the num_of_writes column.

August 1, 2007 5:11 PM
 

drsql said:

Duh, sorry I didn't read your question well enough.  I assumed that based on the value in the reads column.   This is something I will need to verify (or someone who reads this could :) but I am quite sure of it.  Thanks for pointing this out.

August 1, 2007 11:32 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement