DBCC EXTENTINFO命令用于查询某个数据库、或者某个数据对象(主要是数据表)的盘区分配情况,然后计算每个对象理论上

区的数目和实际数目,如果实际数目远大于理论的数目,那这个对象就是碎片过多,管理员应该要考虑重建对象

 

建立下面的存储过程帮助分析:

 

View Code
create table extentinfo 
[file_id] smallint
page_id 
int
pg_alloc 
int
ext_size 
int
obj_id 
int
index_id 
int
partition_number 
int,
partition_id 
bigint,
iam_chain_type 
varchar(50),
pfs_bytes 
varbinary(10) ) 
go 
drop proc import_extentinfo
go
create procedure import_extentinfo 
as dbcc extentinfo('test_shrink'
go 
insert extentinfo  
exec import_extentinfo 
go 

select * from extentinfo 
select [file_id],obj_id, index_id, partition_id, ext_size, 
'actual extent count'=count(*), 'actual page count'=sum(pg_alloc), 
'possible extent count'=ceiling(sum(pg_alloc)*1.0/ext_size), --一个对象的所有盘区页数的各/
'possible extents / actual extents' = (ceiling(sum(pg_alloc)*1.00/ext_size)*100.00/ count(*
from extentinfo 
group by [file_id],obj_id, index_id,partition_id, ext_size 
having count(*)-ceiling(sum(pg_alloc)*1.0/ext_size) > 0 
order by partition_id, obj_id, index_id, [file_id]

 

盘区信息的含义

字段名称

   

file_id

数据库的数据文件编号

page_id

在某个盘区中的第一个页面的页面号

 

pg_alloc

该盘区为数据库分配的页面数量m1m8

ext_size

盘区的大小,以页面为单位

object_id

数据库对象的ID

index_id

表示数据对象的类型

partition_number

分区号

rows

大约的数据行数

hobt_id

存储数据的堆或B树的存储单元ID

 

 

 

posted on 2011-07-25 10:32  cnby  阅读(654)  评论(0编辑  收藏  举报