Disk Space Usage (sp_spaceused)
2015-11-03 15:42
232 查看
1,查看数据库中table,indexed view等的空间使用量,但是返回的结果并不十分精确。
sp_spaceused Displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.
Syntax
Arguments
[ @objname=] 'objname'
Is the qualified or nonqualified name of the table, indexed view, or queue for which space usage information is requested. Quotation marks are required only if a qualified object name is specified. If a fully qualified object name (including a database name) is provided, the database name must be the name of the current database.
If objname is not specified, results are returned for the whole database.
objname is nvarchar(776), with a default of NULL.
[ @updateusage=] 'updateusage'
Indicates DBCC UPDATEUSAGE should be run to update space usage information. When objname is not specified, the statement is run on the whole database; otherwise, the statement is run on objname. Values can be true or false. updateusage is varchar(5), with a default of false.
Remarks
When updateusage is specified, the SQL Server Database Engine scans the data pages in the database and makes any required corrections to the sys.allocation_units and sys.partitions catalog views regarding the storage space used by each table. There are some situations, for example, after an index is dropped, when the space information for the table may not be current. updateusage can take some time to run on large tables or databases. Use updateusage only when you suspect incorrect values are being returned and when the process will not have an adverse effect on other users or processes in the database. If preferred, DBCC UPDATEUSAGE can be run separately.
Note:When you drop or rebuild large indexes, or drop or truncate large tables, the Database Engine defers the actual page deallocations, and their associated locks, until after the transaction commits. Deferred drop operations do not release allocated space immediately. Therefore, the values returned by sp_spaceused immediately after dropping or truncating a large object may not reflect the actual disk space available.
示例1,查看当前DB的空间使用量
database_size:Size of the current database in megabytes. database_size includes both data and log files.
Data File Size
unallocated space :Space in the database that has not been reserved for database objects.
reserved:Total amount of space allocated by objects in the database.
data:Total amount of space used by data.
index_size:Total amount of space used by indexes.
unused :Total amount of space reserved for objects in the database, but not yet used.
database_size will always be larger than the sum of reserved + unallocated space because it includes the size of log files, but reserved and unallocated_space consider only data pages.
在Database的Property中,查看到如下信息
示例2,查看当前DB的Table object 空间使用信息
rows:Number of rows existing in the table.
reserved:Total amount of reserved space for objname.
data:Total amount of space used by data in objname.
index_size:Total amount of space used by indexes in objname.
unused:Total amount of space reserved for objname but not yet used.
2,使用DB report
参考文档:
MSDN: sp_spaceused
http://www.codeproject.com/Articles/163070/Monitoring-Free-Space-on-Microsoft-SQL-Server http://www.databasejournal.com/features/mssql/article.php/3080501/Using-xpfixeddrives-to-Monitor-Free-Space.htm
sp_spaceused Displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.
Syntax
sp_spaceused [[ @objname = ] 'objname' ] [,[ @updateusage = ] 'updateusage' ]
Arguments
[ @objname=] 'objname'
Is the qualified or nonqualified name of the table, indexed view, or queue for which space usage information is requested. Quotation marks are required only if a qualified object name is specified. If a fully qualified object name (including a database name) is provided, the database name must be the name of the current database.
If objname is not specified, results are returned for the whole database.
objname is nvarchar(776), with a default of NULL.
[ @updateusage=] 'updateusage'
Indicates DBCC UPDATEUSAGE should be run to update space usage information. When objname is not specified, the statement is run on the whole database; otherwise, the statement is run on objname. Values can be true or false. updateusage is varchar(5), with a default of false.
Remarks
When updateusage is specified, the SQL Server Database Engine scans the data pages in the database and makes any required corrections to the sys.allocation_units and sys.partitions catalog views regarding the storage space used by each table. There are some situations, for example, after an index is dropped, when the space information for the table may not be current. updateusage can take some time to run on large tables or databases. Use updateusage only when you suspect incorrect values are being returned and when the process will not have an adverse effect on other users or processes in the database. If preferred, DBCC UPDATEUSAGE can be run separately.
Note:When you drop or rebuild large indexes, or drop or truncate large tables, the Database Engine defers the actual page deallocations, and their associated locks, until after the transaction commits. Deferred drop operations do not release allocated space immediately. Therefore, the values returned by sp_spaceused immediately after dropping or truncating a large object may not reflect the actual disk space available.
示例1,查看当前DB的空间使用量
Exec sys.sp_spaceused
database_size:Size of the current database in megabytes. database_size includes both data and log files.
Data File Size
unallocated space :Space in the database that has not been reserved for database objects.
reserved:Total amount of space allocated by objects in the database.
data:Total amount of space used by data.
index_size:Total amount of space used by indexes.
unused :Total amount of space reserved for objects in the database, but not yet used.
database_size will always be larger than the sum of reserved + unallocated space because it includes the size of log files, but reserved and unallocated_space consider only data pages.
在Database的Property中,查看到如下信息
示例2,查看当前DB的Table object 空间使用信息
exec sp_spaceused 'dbo.dt_study'
rows:Number of rows existing in the table.
reserved:Total amount of reserved space for objname.
data:Total amount of space used by data in objname.
index_size:Total amount of space used by indexes in objname.
unused:Total amount of space reserved for objname but not yet used.
2,使用DB report
参考文档:
MSDN: sp_spaceused
http://www.codeproject.com/Articles/163070/Monitoring-Free-Space-on-Microsoft-SQL-Server http://www.databasejournal.com/features/mssql/article.php/3080501/Using-xpfixeddrives-to-Monitor-Free-Space.htm
相关文章推荐
- 有人认为,“中文编程”是解决中国程序员编程效率的秘密武器,请问它是一个“银弹”么?
- python网络编程知识体系
- “双11”倒计时,电商行家如何玩转EDM?
- 从一段.html代码说起谈谈AngularJs中的双向数据绑定
- Android 图片滚动,加入自动播放功能,使用自定义属性实现,霸气十足!
- 大数据测试方法
- vs2008转vs2010碰到的一个坑
- 分布式搜索elasticsearch 索引文档的增删改查(RESTful)
- 二分查找程序算法和快速排序
- 云计算概述
- PHP AJAX JSONP实现跨域请求使用实例
- 信息提示框Toast
- Ant-------默认是build.xml 改为其他的名字
- erlang手记(1)
- Android Studio ABD not responding 问题
- PLSQL 的 for循环的小例子
- FMDB使用详情
- Category和Extension的使用
- Android Studio系列教程六--Gradle多渠道打包
- 分享4种CSS3效果(360度旋转、旋转放大、放大、移动)