小程序三方平台开发: 解析小程序开发的未来趋势和机遇
324
2024-01-05
这篇文章给大家分享的是有关数据库的硬盘空间如何使用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
SQL Server占用的存储空间,包含数据库file占用的存储空间,数据库对象占用的存储空间。
一,数据库file占用的存储空间
1,使用 sys.master_files 查看数据库中各个file占用的存储空间
select db.name asdatabase_name, db.is_auto_shrink_on, db.recovery_model_desc, mf.file_id, mf.type_desc, mf.nameas logic_file_name, mf.size*8/1024/1024 as size_gb, mf.physical_name, --mf.max_size, mf.growth,mf.is_percent_growth, mf.state_descfrom sys.databases dbinner join sys.master_files mf ondb.database_id=mf.database_idwhere mf.size*8/1024/1024>1 -- GBorder by size_gb desc2,使用sp_spaceused 查看当前DB的空间使用量
useDB_Studygoexec sys.sp_spaceuseddatabase_size:database_size includes both data and log files.
数据文件的空间利用信息:
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 spacebecause it includes the size of log files, butreserved and unallocated_space consider only data pages.
3, 按照extent统计data file的disk space usage
从系统page:GAM 和 SGAM 上读取Extent allocate 信息,计算data file有多少extent allocated 或 unallocated。
计算公式:1Extent=8Pages,1Page=8KB
dbcc showfilestats4, 统计SQL Server 实例中所有数据库的日志文件的disk space usage
dbcc sqlperf(logspace) 返回的结果总是准确的,语句的执行不会对sql server增加负担
dbcc sqlperf(logspace)二,查看数据库中,各个table 或index 所占用的disk space
1,查看数据库所有table 或index 所占用的disk space
select t.name, sum(case when ps.index_id<2 thenps.row_countelse 0 end) as row_count, sum(ps.reserved_page_count)*8/1024/1024 as reserved_gb, sum(ps.used_page_count)*8/1024 as used_mb, sum( case when ps.index_id<2 thenps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_countelse 0 end )*8/1024 as data_used_mb, sum(case when ps.index_id>=2 thenps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_countelse 0 end )*8/1024 asindex_used_mbfrom sys.dm_db_partition_stats psinnerjoin sys.tables t on ps.object_id=t.object_idgroup byt.object_id, t.nameorderby reserved_gb desc2,在当前DB中,查看某一个Table object 空间使用信息
exec sp_spaceused dbo.dt_studyrows:Number of rows existing in the table.
reserved:Total amount of reserved space for objname.
data:Total amount of space used by data inobjname.
index_size:Total amount of space used by indexes in objname.
unused:Total amount of space reserved forobjname but not yet used.
三,使用Standard Reports 查看disk space usage
四,查看服务器各个逻辑盘符剩余的disk space
Exec master.sys.xp_fixeddrivesAppendix:
查看数据库中table,indexed等对象的disk空间使用量,但是返回的结果并不十分精确。
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 ]感谢各位的阅读!关于“数据库的硬盘空间如何使用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~