Sql server 提供了一些standard reports,可以查看Disk Usage,Index Usage 和 Top transactions
查看 Database的Disk Space Usage Report,截图如下
sanpshot中,Data Files Space usage分为4部分:Index , Data,Unallocated 和 Unused。
Unallocated space的存在是预留存储空间,在DB运行时,如果有 object 需要空间,那么Sql Server直接将这部分space分配给object,而不用向OS申请额外的disk space。向OS申请额外的disk space会导致data file的grow,由于申请额外的disk space需要耗费一定的时间对space进行初始化,可能会导致transaction timeout,导致transaction失败而rollback。所以,良好的DB Design都会预留足够的disk space,即保持一定量的Unallocated space。
如果Unallocated Space 过大,会导致Disk space exhaust,这时就需要shrink file,以free space。命令dbcc shrinkfile 释放的空间就是Unallocated space,释放之后,这部分空间返回给OS。
Unallocated is extents that are not in use. In essence, these extents are maked with bit 1 in GAM page. Any type of grow will produce unallocated extents.
Unused are pages on allocated extents, but thise pages are not yet used by any objects. As soon as an extent is allocated (either as uniform or shared extent), we have 8 reserved pages on that extent. Some pages are used, and some are unused.
图片来源于:SQL Server – Understanding ‘sp_spaceused’ Results for Database Size Information
推荐文档:Difference between unallocated and unused space
Unallocated space could be returned to the OS when you shrink a file, but the unused space is space that has already been allocated to an object, but just doesn’t yet have any data stored in it.
Unallocated space is the sum of the space used by extents that are not yet allocated to any database objects. So basically it’s the size of the database file(s) minus the sum of the space used by all extents that are assigned to objects be they data,index,GAM,IAM,SGAM,PFS,BCM or DCM pages.
Unused space is the sum of free space available on pages in the data file(s) that have been allocated to an object or objects. Thus running sp_spaceused on a table for instance, the sum of the data and index page space plus the unused space will give you the total space (reserved column in the resultset).
As rows are inserted,updated and deleted in a table then in almost all circumstances there will be some free space on each page. As deletes and updates occur, plus inserts into a table with a clustered index where inserts may not be in clustered index order, then there may well be readjustment of space on the pages e.g. page splits, ghost records etc. Some of this space may be reused but some of it may not, thus as there is transactional activity in your database , the unused space will tend to increase along with the data and index space. This is where defragmenting your indexes can come into play in terms of compacting this unused space and making your data pages and indexes more efficent. You can determine the average freespace on a page for an object using dbcc showcontig.
It is not uncommon to have some 30-50% of the database size as unallocated.
…at database level :
USE AdventureWorks2008R2 GO EXEC sp_spaceused GO
Results
First Recordset:
Second Recordset:
…at table level:
USE AdventureWorks2008R2 GO EXEC sp_spaceused N‘Person.Person‘ GO
Results
Disk Space Usage : unallocated, unused and reserved
原文:http://www.cnblogs.com/ljhdo/p/5128259.html