久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

數(shù)據(jù)庫(kù)的硬盤(pán)空間如何使用

共計(jì) 2910 個(gè)字符,預(yù)計(jì)需要花費(fèi) 8 分鐘才能閱讀完成。

這篇文章給大家分享的是有關(guān)數(shù)據(jù)庫(kù)的硬盤(pán)空間如何使用的內(nèi)容。丸趣 TV 小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨丸趣 TV 小編過(guò)來(lái)看看吧。

SQL Server 占用的存儲(chǔ)空間,包含數(shù)據(jù)庫(kù) file 占用的存儲(chǔ)空間,數(shù)據(jù)庫(kù)對(duì)象占用的存儲(chǔ)空間。

一,數(shù)據(jù)庫(kù) file 占用的存儲(chǔ)空間

1,使用 sys.master_files 查看數(shù)據(jù)庫(kù)中各個(gè) file 占用的存儲(chǔ)空間

select db.name as database_name,
 db.is_auto_shrink_on,
 db.recovery_model_desc,
 mf.file_id,
 mf.type_desc,
 mf.name as 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 db 
inner join sys.master_files mf 
 on db.database_id=mf.database_idwhere mf.size*8/1024/1024 1 -- GBorder by size_gb desc

2,使用 sp_spaceused 查看當(dāng)前 DB 的空間使用量

use DB_Studygoexec sys.sp_spaceused

database_size:database_size includes both data and log files.

數(shù)據(jù)文件的空間利用信息:

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.

3,按照 extent 統(tǒng)計(jì) data file 的 disk space usage

從系統(tǒng) page:GAM 和 SGAM 上讀取 Extent allocate 信息,計(jì)算 data file 有多少 extent allocated 或 unallocated。

計(jì)算公式:1Extent=8Pages,1Page=8KB

dbcc showfilestats

4,統(tǒng)計(jì) SQL Server 實(shí)例中所有數(shù)據(jù)庫(kù)的日志文件的 disk space usage

dbcc sqlperf(logspace)  返回的結(jié)果總是準(zhǔn)確的,語(yǔ)句的執(zhí)行不會(huì)對(duì) sql server 增加負(fù)擔(dān)

dbcc sqlperf(logspace)

二,查看數(shù)據(jù)庫(kù)中,各個(gè) table 或 index 所占用的 disk space

1,查看數(shù)據(jù)庫(kù)所有 table 或 index 所占用的 disk space

select 
 t.name, sum(case when ps.index_id 2 then ps.row_count else 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
 then ps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_count else 0 end
 )*8/1024 as data_used_mb, sum(case when ps.index_id =2 
 then ps.in_row_data_page_count+ps.lob_used_page_count+ps.row_overflow_used_page_count else 0 end
 )*8/1024 as index_used_mbfrom sys.dm_db_partition_stats psinner join sys.tables t on ps.object_id=t.object_idgroup by t.object_id, t.nameorder by reserved_gb desc

2,在當(dāng)前 DB 中,查看某一個(gè) 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.

三,使用 Standard Reports 查看 disk space usage

四,查看服務(wù)器各個(gè)邏輯盤(pán)符剩余的 disk space

Exec master.sys.xp_fixeddrives

Appendix:

查看數(shù)據(jù)庫(kù)中 table,indexed 等對(duì)象的 disk 空間使用量,但是返回的結(jié)果并不十分精確。

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  ]

感謝各位的閱讀!關(guān)于“數(shù)據(jù)庫(kù)的硬盤(pán)空間如何使用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

正文完
 
丸趣
版權(quán)聲明:本站原創(chuàng)文章,由 丸趣 2023-07-20發(fā)表,共計(jì)2910字。
轉(zhuǎn)載說(shuō)明:除特殊說(shuō)明外本站除技術(shù)相關(guān)以外文章皆由網(wǎng)絡(luò)搜集發(fā)布,轉(zhuǎn)載請(qǐng)注明出處。
評(píng)論(沒(méi)有評(píng)論)
主站蜘蛛池模板: 中超| 贺兰县| 仙桃市| 泗洪县| 洛南县| 宝鸡市| 涟水县| 清流县| 宝坻区| 长治县| 华坪县| 宜君县| 鄂托克前旗| 嘉黎县| 敦煌市| 郯城县| 昌吉市| 珲春市| 兴海县| 马山县| 全南县| 都江堰市| 彰武县| 九江县| 白河县| 英德市| 东乌| 长泰县| 长乐市| 宁安市| 亚东县| 东城区| 四平市| 左权县| 二连浩特市| 筠连县| 临沭县| 临猗县| 广水市| 南宫市| 扶余县|