Sunday, 4 May 2014

Get MDF and LDF File Statistics Using fn_virtualfilestats


You can get what is the size of the file as well how many times the reads and writes are done for each file. It also displays the read/write data in bytes with the following script.

SELECT DB_NAME(vfs.DbId) DatabaseName,
       mf.name,
       mf.physical_name,
       vfs.BytesRead,
       vfs.BytesWritten,
       vfs.IoStallMS,
       vfs.IoStallReadMS,
       vfs.IoStallWriteMS,
       vfs.NumberReads,
       vfs.NumberWrites,
       (cast(SIZE AS bigint)*8)/1024 Size_MB
FROM ::fn_virtualfilestats(NULL,NULL) vfs
INNER JOIN sys.master_files mf ON mf.database_id = vfs.DbId
AND mf.FILE_ID = vfs.FileId

No comments:

Post a Comment