SQL Server reported that our tempdb is out of space. So I had a quick google search and found this on technet
https://technet.microsoft.com/en-us/library/ms176029(v=sql.105).aspx
Determining the Amount of Free Space in tempdb
The following query returns the total number of free pages and total free space in megabytes (MB) available in all files in tempdb.
SELECT SUM(unallocated_extent_page_count) AS [free pages],
(SUM(unallocated_extent_page_count)*1.0/128) AS [free space in MB]
FROM sys.dm_db_file_space_usage;
This is the result of the query:
free pages free space in MB
-------------------- ---------------------------------------
1272 9.937500
The strange thing is that when i go and check it in the ui of the ssms the size and the free space is perfectly fine
So here are my questions:
- Why are they reporting two different sizes. Is this due that the script actually counts the page file size rather than "hole size"?
- Why is the script dividing the sum by 128?
Any answer is greatly appreciated.

sys.dm_db_file_space_usagegives page count, to get MB you have to multiply by 8 and then divide by 1024. This can be simplified to divide by 128, since 1024/8 = 128.