Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My technology blog on SQL Server, TSQL, XML, FILESTREAM and other areas of SQL Server.
Browse by Tags · View All
XML 112
TSQL 69
XQuery 69
XQuery Functions 67
XQuery Training 65
XQuery in TSQL 64
XQuery Tutorial 63
SQL Server XQuery 63
XQuery-Labs 57
BRH 38

Archive · View All
September 2008 32
August 2008 30
July 2008 21
August 2009 19
June 2009 19
May 2010 18
January 2009 15
January 2010 14
October 2008 14
June 2008 13

SQL Server DMF sys.dm_os_volume_stats to retrieve information about physical disk drives

Jul 9 2012 12:52PM by Jacob Sebastian   

Monitoring the size of data files and available disk space on each of the drives (where the data files are placed), is one of the key activities of every database administrator. Depending upon the environment and requirements, people rely on different methods/tools to get this information.

xp_fixeddrives

This (undocumented?) extended stored procedure returns information about the free space available in each of the fixed drives on the server. However, using this type of stored procedures always a pain because they deny the freedom of using the output in a query. If you are writing a piece of TSQL code that utilizes the output of the procedure (such as sending a notification email when the available disk space falls below a threshold value) you will need to capture the output into a table and then write your actual query that uses the information produced by the stored procedure.

In addition, the only piece of information xp_fixeddrives gives us is the free space. One may want to find out the total disk size and many other related pieces of information, which unfortunately, is not available easily.

The following example retrieves information about available free space using xp_fixeddrives

DECLARE @t TABLE (
	Name NVARCHAR(50),
	FreeSpace INT 
)

INSERT INTO @t
EXEC xp_fixeddrives

SELECT
	df.physical_name AS DataFile,
	t.name AS Drive,
	CAST(t.FreeSpace/1024 AS VARCHAR) + ' GB' AS FreeSpace
FROM @t t
INNER JOIN sys.database_files df ON 
	t.name = LEFT(physical_name,1)
	
/*
DataFile          Drive FreeSpace
----------------- ----- ----------
C:\DATA\br3.mdf   C     200 GB
D:\DATA\br3_2.LDF D     123 GB
E:\DATA\br3_1.ndf E     145 GB
*/	

Enter sys.dm_os_volume_stats!

SQL Server 2008 R2 SP1 introduces a really cool Dynamic Management Function that exposes several attributes of the physical disk drives. Some of the interesting pieces of information returned by this function are:

  1. Mount point at which the volume is rooted.
  2. Logical volume name
  3. Type of file system volume, such as NTFS
  4. Total size in bytes of the volume
  5. Available free space on the volume
  6. Whether volume supports operating system compression or not
  7. Whether the volume supports alternate streams or not
  8. Whether the volume supports sparse files or not
  9. Whether the volume is currently marked as read only or not
  10. Whether the volume is currently compressed or not

The query we saw earlier can be easily re-written using this new function as follows.

SELECT 
	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.database_files df
CROSS APPLY sys.dm_os_volume_stats(db_id(), df.file_id) ovs

/*
DataFile          FileSize Drive DriveSize SpaceAvailable
----------------- -------- --------------  --------------
C:\DATA\br3.mdf   1166296  C:\   248 GB    200 GB
D:\DATA\br3_2.LDF 254144   D:\   248 GB    123 GB
E:\DATA\br3_1.ndf 128      E:\   248 GB    145 GB
*/

Reference: http://msdn.microsoft.com/en-us/library/hh223223(v=sql.105).aspx

Tags: 


Jacob Sebastian
1 · 100% · 32002
15
 
0
Lifesaver
 
 
 
0
Incorrect



Submit

3  Comments  

  • Nice, thanks for sharing this!!

    commented on Jul 10 2012 12:27AM
    Sudeep Raj
    12 · 13% · 4286
  • Jacob, It is nice to see someone posting relavent and useful information. I am a big fan of your blogs. Keep up the good work.

    commented on Aug 20 2012 9:59AM
    woodymax
    867 · 0% · 33
  • @woodymax, I am glad to know that you liked this post. Thank you.

    commented on Aug 20 2012 10:32AM
    Jacob Sebastian
    1 · 100% · 32002

Your Comment


Sign Up or Login to post a comment.

"SQL Server DMF sys.dm_os_volume_stats to retrieve information about physical disk drives" rated 5 out of 5 by 15 readers
SQL Server DMF sys.dm_os_volume_stats to retrieve information about physical disk drives , 5.0 out of 5 based on 15 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]