I have a database which has four data files and a log file. The data files are each around 5 GB, the log is about 1 GB. The database reports the total space reserved as around 21 GB, and of that 18 GB is in use. This information is corroborated by:
- Disk Usage Report
- Database Properties dialog (in Management Studio)
sp_spaceused
sys.database_files
- The data files on disk
However, the Disk Usage Report and sp_spaceused
are both reporting that there is around 61 GB of data file space reserved, leaving around 43 GB as "unused" (i.e. not containing data). This should be impossible as the total space reserved is only 21 GB.
This phantom reserved space certainly isn't on the hard drive, so it must be a case of incorrect data somewhere in SQL Server. Where is it and how do I restore normality?
Best Answer
Looking at the code behind
sp_spaceused
, it references a system table calledsys.allocation_units
which stores statistics about how big each object in the database is. In particular, thetotal_pages
andused_pages
columns relate to the reserved and used disk space reported bysp_spaceused
. The following query can help to pinpoint which objects are reporting the excessive reserved space:Once a table has (or some tables have) been identified, their statistics can be updated by running one of:
The report should now correctly report (or be closer to correctly reporting) the true reserved and used disk space for the database.
More information is available at MS Docs on DBCC UPDATEUSAGE and sp_spaceused.