Home » SQL Server query to get storage info

SQL Server query to get storage info

by Vlad Drumea
0 comments

This post contains a short SQL Server query to get storage info for the disks hosting your instance’s database files without having to RDP into its host VM.

The query

Since it relies on the dm_os_volume_stats DMV, you’ll need VIEW SERVER STATE permission on SQL Server 2019 or VIEW SERVER PERFORMANCE STATE on 2022.

Output example

The column names are self-explanatory so there’s no need for me to go over them.

SSMS result set |Disk | DiskSize(GB) | DiskFreeSpace(GB) | DiskFreePercent| |E:\ | 875.61 | 215.75 | 24.64%| |F:\ | 838.35 | 467.66 | 55.78%| |C:\ | 837.62 | 479.78 | 57.28%| SQL Server query storage disk

Note that this will only return information about disks that have database files “living” on them.
If you want to get the free space for all the drives on the host you can just run:

Conclusion

This is a pretty simple query to get SQL Server storage info.
If you’ve found this useful you might also like this script to get database size info

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.