Today, we will go through four queries that are related to storage. We start out with Query #23<\/strong>, which is Volume Info. This query retrieves information from the sys.master_files<\/a> catalog view and the sys.dm_os_volume_stats<\/a> dynamic management function about any operating system volumes or mount points on your server where you have any SQL Server database files. Query #23 is shown in Figure 1. <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 1: Query #23 Volume Info<\/strong><\/p>\n This query shows you how large each operating system volume or mount point is, and how much space is available. You don\u2019t ever<\/u><\/strong> want to run out of space on a volume where SQL Server database files are located (for obvious reasons), but many people are not aware that being low on space can affect the performance of the volume, with both magnetic storage and with flash storage.<\/p>\n With magnetic storage, being low on disk space means that you may be no longer getting the increased disk performance possible from short-stroking<\/a>. This can affect your disk performance with magnetic drives because the arm that moves the drive heads back and forth to read the data has to move further as an individual disk becomes more and more full, plus the disk platters are moving slower on the inside portion compared to the outside portion of the disk. <\/p>\n The reason why I say that this only \u201cmay\u201d be affecting your disk performance is because with many SANs, whatever space has been allocated for a volume may be spread across all of the available drives in the SAN, so the fact that your volume is low on space may have very little to do with what is happening with the overall SAN.<\/p>\n With flash storage, as the drive gets lower on space, it becomes more difficult for garbage collection and TRIM operations to complete without affecting performance. Generally speaking, your write performance will tend to decrease and become more inconsistent as the drive is closer to being full of data.<\/p>\n <\/p>\n Query #24<\/strong> is Drive Level Latency. This query retrieves information from the sys.master_files<\/a> catalog view and the sys.dm_io_virtual_file_stats<\/a> dynamic management function about I\/O statistics for SQL Server data and log files. Query #24 is shown in Figure 2. <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 2: Query #24 Drive Level Latency<\/strong><\/p>\n This particular query aggregates all of the file activity for your database data and log files up to the volume level. This activity includes your normal workload, plus anything else (such as index maintenance, database backups, log reader activity for things like replication, database mirroring, and AlwaysOn AGs) that touches your database data and log files. <\/p>\n These numbers are cumulative since SQL Server was last started. This means that the latency numbers you see here will usually tend to be a little higher than what you might see in Performance Monitor, and also higher than what shows up at the SAN-level. This query helps you understand your disk performance for SQL Server at the volume level. Once you understand this, then you are ready to drill down to the individual database file level with the next query.<\/p>\n <\/p>\n Query #25<\/strong> is IO Stalls by File. This query retrieves information from the sys.master_files<\/a> catalog view and the sys.dm_io_virtual_file_stats<\/a> dynamic management function about I\/O statistics for SQL Server data and log files. Query #25 is shown in Figure 3. <\/p>\n <\/p>\n 1:<\/span> -- Volume info for all LUNS that have database files on the current instance (Query 23) (Volume Info)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> DISTINCT<\/span> vs.volume_mount_point, vs.file_system_type, <\/pre>\n 3:<\/span> vs.logical_volume_name, CONVERT<\/span>(DECIMAL<\/span>(18,2),vs.total_bytes\/1073741824.0) AS<\/span> [Total Size<\/span> (GB)],<\/pre>\n 4:<\/span> CONVERT<\/span>(DECIMAL<\/span>(18,2),vs.available_bytes\/1073741824.0) AS<\/span> [Available Size<\/span> (GB)], <\/pre>\n 5:<\/span> CAST<\/span>(CAST<\/span>(vs.available_bytes AS<\/span> FLOAT<\/span>)\/ CAST<\/span>(vs.total_bytes AS<\/span> FLOAT<\/span>) AS<\/span> DECIMAL<\/span>(18,2)) * 100 AS<\/span> [Space<\/span> Free<\/span> %] <\/pre>\n 6:<\/span> FROM<\/span> sys.master_files AS<\/span> f WITH<\/span> (NOLOCK)<\/pre>\n 7:<\/span> CROSS<\/span> APPLY sys.dm_os_volume_stats(f.database_id, f.[file_id]) AS<\/span> vs <\/pre>\n 8:<\/span> ORDER<\/span> BY<\/span> vs.volume_mount_point OPTION<\/span> (RECOMPILE);<\/pre>\n 9:<\/span> <\/pre>\n 10:<\/span> -- Shows you the total and free space on the LUNs where you have database files<\/span><\/pre>\n 11:<\/span> -- Being low on<\/span> free<\/span> space<\/span> can negatively affect performance<\/pre>\n 1:<\/span> -- Drive level latency information (Query 24) (Drive Level Latency)<\/span><\/pre>\n 2:<\/span> -- Based on code from Jimmy May<\/span><\/pre>\n 3:<\/span> SELECT<\/span> tab.[Drive], tab.volume_mount_point AS<\/span> [Volume Mount Point], <\/pre>\n 4:<\/span> CASE<\/span> <\/pre>\n 5:<\/span> WHEN<\/span> num_of_reads = 0 THEN<\/span> 0 <\/pre>\n 6:<\/span> ELSE<\/span> (io_stall_read_ms\/num_of_reads) <\/pre>\n 7:<\/span> END<\/span> AS<\/span> [Read<\/span> Latency],<\/pre>\n 8:<\/span> CASE<\/span> <\/pre>\n 9:<\/span> WHEN<\/span> io_stall_write_ms = 0 THEN<\/span> 0 <\/pre>\n 10:<\/span> ELSE<\/span> (io_stall_write_ms\/num_of_writes) <\/pre>\n 11:<\/span> END<\/span> AS<\/span> [Write<\/span> Latency],<\/pre>\n 12:<\/span> CASE<\/span> <\/pre>\n 13:<\/span> WHEN<\/span> (num_of_reads = 0 AND<\/span> num_of_writes = 0) THEN<\/span> 0 <\/pre>\n 14:<\/span> ELSE<\/span> (io_stall\/(num_of_reads + num_of_writes)) <\/pre>\n 15:<\/span> END<\/span> AS<\/span> [Overall Latency],<\/pre>\n 16:<\/span> CASE<\/span> <\/pre>\n 17:<\/span> WHEN<\/span> num_of_reads = 0 THEN<\/span> 0 <\/pre>\n 18:<\/span> ELSE<\/span> (num_of_bytes_read\/num_of_reads) <\/pre>\n 19:<\/span> END<\/span> AS<\/span> [Avg<\/span> Bytes\/Read<\/span>],<\/pre>\n 20:<\/span> CASE<\/span> <\/pre>\n 21:<\/span> WHEN<\/span> io_stall_write_ms = 0 THEN<\/span> 0 <\/pre>\n 22:<\/span> ELSE<\/span> (num_of_bytes_written\/num_of_writes) <\/pre>\n 23:<\/span> END<\/span> AS<\/span> [Avg<\/span> Bytes\/Write<\/span>],<\/pre>\n 24:<\/span> CASE<\/span> <\/pre>\n 25:<\/span> WHEN<\/span> (num_of_reads = 0 AND<\/span> num_of_writes = 0) THEN<\/span> 0 <\/pre>\n 26:<\/span> ELSE<\/span> ((num_of_bytes_read + num_of_bytes_written)\/(num_of_reads + num_of_writes)) <\/pre>\n 27:<\/span> END<\/span> AS<\/span> [Avg<\/span> Bytes\/Transfer]<\/pre>\n 28:<\/span> FROM<\/span> (SELECT<\/span> LEFT<\/span>(UPPER<\/span>(mf.physical_name), 2) AS<\/span> Drive, SUM<\/span>(num_of_reads) AS<\/span> num_of_reads,<\/pre>\n 29:<\/span> SUM<\/span>(io_stall_read_ms) AS<\/span> io_stall_read_ms, SUM<\/span>(num_of_writes) AS<\/span> num_of_writes,<\/pre>\n 30:<\/span> SUM<\/span>(io_stall_write_ms) AS<\/span> io_stall_write_ms, SUM<\/span>(num_of_bytes_read) AS<\/span> num_of_bytes_read,<\/pre>\n 31:<\/span> SUM<\/span>(num_of_bytes_written) AS<\/span> num_of_bytes_written, SUM<\/span>(io_stall) AS<\/span> io_stall, vs.volume_mount_point <\/pre>\n 32:<\/span> FROM<\/span> sys.dm_io_virtual_file_stats(NULL<\/span>, NULL<\/span>) AS<\/span> vfs<\/pre>\n 33:<\/span> INNER<\/span> JOIN<\/span> sys.master_files AS<\/span> mf WITH<\/span> (NOLOCK)<\/pre>\n 34:<\/span> ON<\/span> vfs.database_id = mf.database_id AND<\/span> vfs.file_id = mf.file_id<\/pre>\n 35:<\/span> CROSS<\/span> APPLY sys.dm_os_volume_stats(mf.database_id, mf.[file_id]) AS<\/span> vs <\/pre>\n 36:<\/span> GROUP<\/span> BY<\/span> LEFT<\/span>(UPPER<\/span>(mf.physical_name), 2), vs.volume_mount_point) AS<\/span> tab<\/pre>\n 37:<\/span> ORDER<\/span> BY<\/span> [Overall Latency] OPTION<\/span> (RECOMPILE);<\/pre>\n 38:<\/span> <\/pre>\n 39:<\/span> -- Shows you the drive-level latency for reads and writes, in milliseconds<\/span><\/pre>\n 40:<\/span> -- Latency above 20-25ms is<\/span> usually a problem<\/pre>\n 1:<\/span> -- Calculates average stalls per read, per write, and per total input\/output for each database file (Query 25) (IO Stalls by File)<\/span><\/pre>\n 2:<\/span>