DMF sys.dm_os_volume_stats監控物理磁盤

   监控数据库数据文件以及磁盘的空间情况是每个DBA必要的工作。sqlserver 2008 r2 sp1之后的版本提供了一个很实用的DMF sys.dm_os_volume_stats来返回数据文件以及文件所在磁盘的空间情况。相比之前的xp_fixeddrives更加的实用。

SELECT DB_NAME(df.database_id) as dbName,
 physical_name AS DataFile,
 size AS FileSize,
 volume_mount_point AS Drive,
 CAST(total_bytes/1024/1024/1024 AS VARCHAR) + ' GB' AS DriveSize,
 CAST(available_bytes/1024/1024/ 1024 AS VARCHAR) + ' GB'  AS SpaceAvailable
FROM sys.master_files df
CROSS APPLY sys.dm_os_volume_stats(df.database_id, df.file_id) ovs
where DB_NAME(df.database_id)='DEMO'

 

/*
dbName DataFile         FileSize Drive DriveSize SpaceAvailable
------ -------------------------------------  -------- ------- --------- ---------------
DEMO C:\SQL2008R2\MSSQL\DATA\DEMO.mdf   10656       C:\  97 GB  32 GB
DEMO C:\SQL2008R2\MSSQL\DATA\DEMO_log.LDF  264         C:\  97 GB  32 GB

(2 row(s) affected)

*/

 

 

你可能感兴趣的:(DMF sys.dm_os_volume_stats監控物理磁盤)