sys.fn_virtualfilestats (Transact-SQL)

sys.fn_virtualfilestats (Transact-SQL)

 

Updated: June 10, 2016

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2008)yesAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Returns I/O statistics for database files, including log files. In SQL Server, this information is also available from the sys.dm_io_virtual_file_stats dynamic management view.

Topic link icon Transact-SQL Syntax Conventions

  
fn_virtualfilestats ( { database_id | NULL } , { file_id | NULL } )  

database_id | NULL
Is the ID of the database. database_id is int, with no default. Specify NULL to return information for all databases in the instance of SQL Server.

file_id | NULL
Is the ID of the file. file_id is int, with no default. Specify NULL to return information for all files in the database.

Column NameData typeDescription
DbIdsmallintDatabase ID.
FileIdsmallintFile ID.
TimeStampintDatabase timestamp at which the data was taken.
NumberReadsbigintNumber of reads issued on the file.
BytesReadbigintNumber of bytes read issued on the file.
IoStallReadMSbigintTotal amount of time, in milliseconds, that users waited for the read I/Os to complete on the file.
NumberWritesbigintNumber of writes made on the file.
BytesWrittenbigintNumber of bytes written made on the file.
IoStallWriteMSbigintTotal amount of time, in milliseconds, that users waited for the write I/Os to complete on the file.
IoStallMSbigintSum of IoStallReadMS and IoStallWriteMS.
FileHandlebigintValue of the file handle.
BytesOnDiskbigintPhysical file size (count of bytes) on disk.

For database files, this is the same value as size in sys.database_files, but is expressed in bytes rather than pages.

For database snapshot sparse files, this is the space the operating system is using for the file.

fn_virtualfilestats is a system table-valued function that gives statistical information, such as the total number of I/Os performed on a file. You can use this function to help keep track of the length of time users have to wait to read or write to a file. The function also helps identify the files that encounter large numbers of I/O activity.

Requires VIEW SERVER STATE permission on the server.

A. Displaying statistical information for a database

The following example displays statistical information for file ID 1 in the database with an ID of 1.

SELECT *  
FROM fn_virtualfilestats(1, 1);  
GO  

B. Displaying statistical information for a named database and file

The following example displays statistical information for the log file in the AdventureWorks2012 sample database. The system function DB_ID is used to specify the database_id parameter.

SELECT *  
FROM fn_virtualfilestats(DB_ID(N'AdventureWorks2012'), 2);  
GO  

C. Displaying statistical information for all databases and files

The following example displays statistical information for all files in all databases in the instance of SQL Server.

SELECT *  
FROM fn_virtualfilestats(NULL,NULL);  
GO  

DB_ID (Transact-SQL)
FILE_IDEX (Transact-SQL)
sys.database_files (Transact-SQL)
sys.master_files (Transact-SQL)

Community Additions

ADD
Show:
© 2016 Microsoft