Friday 30 September 2016

Get the free size of server

With the help of below sql script we will get the free space of the server.
SELECT DISTINCT d.logical_volume_name AS LogicalName
,d.volume_mount_point AS DriveName
,CONVERT(NUMERIC(32,2),d.available_bytes *1.00/(1048576.0 *1024 ))
AS FreeSpaceInGB
,CONVERT(NUMERIC(32,2),d.Total_Bytes *1.00/(1048576.0 *1024 ))
AS TotalSizeInGB
FROM sys.master_files f
CROSS APPLY sys.dm_os_volume_stats(f.database_id, f.FILE_ID) d
ORDER BY FreeSpaceInGB

See the below
  
We can verify
  

In my system I stored some database on the G drive and some of the database on c drives. So it returns the free spaces on C and G drives. In Prod environment there are dedicated server for the database and configured log and temp databases on different drives. With the help of this sql we will get the free size of the drives.

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts