监控数据库数据文件以及磁盘的空间情况是每个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
结果如下:
参考自:http://blog.csdn.net/ldslove/article/details/8156795