oracle show_space脚本
2016-05-12 20:33
465 查看
show_space脚本打印数据库段的空间利用率信息:
运行结果如下:
unformattedblocks:为表分配位于高水位线之下的但未用的块数.把未格式化和未用的块加在一起,就是已为表分配但是从未保存的assm对象数据块的总块数.
FS1-FS4:包含数据的格式化块.项名后面的数字区间表示各块的空闲度,0-25表示空闲度为0-25%的块数
Fullblocks:已满的块数,不能再对这些块执行插入.
Totalblocks,bytes:为段分配的总共块数和字节数
Unusedblocks,bytes:表示未用的空间所占的比例.这些块已经分配给所查看的段,但是目前在段的高水位之上
LastUsedExtFileid:包含最后一个区块的文件的文件ID
LastUsedExtBlockId:最后一个区段开始处的块ID,这是最后使用的文件中的块ID
LastUsedBlocks:最后一个区段中最后一个块的偏移量
createorreplaceprocedureshow_space
(p_segnameinvarchar2,
p_ownerinvarchar2defaultuser,
p_typeinvarchar2default'TABLE',
p_partitioninvarchar2defaultNULL)
--thisprocedureusesauthidcurrentusersoitcanqueryDBA_*
--viewsusingprivilegesfromaROLEandsoitcanbeinstalled
--onceperdatabase,insteadofonceperuserthatwantedtouseit
authidcurrent_user
as
l_free_blksnumber;
l_total_blocksnumber;
l_total_bytesnumber;
l_unused_blocksnumber;
l_unused_bytesnumber;
l_LastUsedExtFileIdnumber;
l_LastUsedExtBlockIdnumber;
l_LAST_USED_BLOCKnumber;
l_segment_space_mgmtvarchar2(255);
l_unformatted_blocksnumber;
l_unformatted_bytesnumber;
l_fs1_blocksnumber;l_fs1_bytesnumber;
l_fs2_blocksnumber;l_fs2_bytesnumber;
l_fs3_blocksnumber;l_fs3_bytesnumber;
l_fs4_blocksnumber;l_fs4_bytesnumber;
l_full_blocksnumber;l_full_bytesnumber;
--inlineproceduretoprintoutnumbersnicelyformatted
--withasimplelabel
procedurep(p_labelinvarchar2,p_numinnumber)
is
begin
dbms_output.put_line(rpad(p_label,40,'.')||
to_char(p_num,'999,999,999,999'));
end;
begin
--thisqueryisexecuteddynamicallyinordertoallowthisprocedure
--tobecreatedbyauserwhohasaccesstoDBA_SEGMENTS/TABLESPACES
--viaaroleasiscustomary.
--NOTE:atruntime,theinvokerMUSThaveaccesstothesetwo
--views!
--thisquerydeterminesiftheobjectisaASSMobjectornot
begin
executeimmediate
'selectts.segment_space_management
fromdba_segmentsseg,dba_tablespacests
whereseg.segment_name=:p_segname
and(:p_partitionisnullor
seg.partition_name=:p_partition)
andseg.owner=:p_owner
andseg.segment_type=:p_type
andseg.tablespace_name=ts.tablespace_name'
intol_segment_space_mgmt
usingp_segname,p_partition,p_partition,p_owner,p_type;
exception
whentoo_many_rowsthen
dbms_output.put_line
('Thismustbeapartitionedtable,usep_partition=>');
return;
end;
--iftheobjectisinanASSMtablespace,wemustusethisAPI
--calltogetspaceinformation,elseweusetheFREE_BLOCKS
--APIfortheusermanagedsegments
ifl_segment_space_mgmt='AUTO'
then
dbms_space.space_usage
(p_owner,p_segname,p_type,l_unformatted_blocks,
l_unformatted_bytes,l_fs1_blocks,l_fs1_bytes,
l_fs2_blocks,l_fs2_bytes,l_fs3_blocks,l_fs3_bytes,
l_fs4_blocks,l_fs4_bytes,l_full_blocks,l_full_bytes,p_partition);
p('UnformattedBlocks',l_unformatted_blocks);
p('FS1Blocks(0-25)',l_fs1_blocks);
p('FS2Blocks(25-50)',l_fs2_blocks);
p('FS3Blocks(50-75)',l_fs3_blocks);
p('FS4Blocks(75-100)',l_fs4_blocks);
p('FullBlocks',l_full_blocks);
else
dbms_space.free_blocks(
segment_owner=>p_owner,
segment_name=>p_segname,
segment_type=>p_type,
freelist_group_id=>0,
free_blks=>l_free_blks);
p('FreeBlocks',l_free_blks);
endif;
--andthentheunusedspaceAPIcalltogettherestofthe
--information
dbms_space.unused_space
(segment_owner=>p_owner,
segment_name=>p_segname,
segment_type=>p_type,
partition_name=>p_partition,
total_blocks=>l_total_blocks,
total_bytes=>l_total_bytes,
unused_blocks=>l_unused_blocks,
unused_bytes=>l_unused_bytes,
LAST_USED_EXTENT_FILE_ID=>l_LastUsedExtFileId,
LAST_USED_EXTENT_BLOCK_ID=>l_LastUsedExtBlockId,
LAST_USED_BLOCK=>l_LAST_USED_BLOCK);
p('TotalBlocks',l_total_blocks);
p('TotalBytes',l_total_bytes);
p('TotalMBytes',trunc(l_total_bytes/1024/1024));
p('UnusedBlocks',l_unused_blocks);
p('UnusedBytes',l_unused_bytes);
p('LastUsedExtFileId',l_LastUsedExtFileId);
p('LastUsedExtBlockId',l_LastUsedExtBlockId);
p('LastUsedBlock',l_LAST_USED_BLOCK);
end;
/
运行结果如下:
SQL>setserveroutputon
SQL>execshow_space('TOBJ')
UnformattedBlocks..................... 0
FS1Blocks(0-25)...................... 0
FS2Blocks(25-50)..................... 0
FS3Blocks(50-75)..................... 0
FS4Blocks(75-100)..................... 0
FullBlocks............................ 196
TotalBlocks............................ 256
TotalBytes.............................2,097,152
TotalMBytes............................ 2
UnusedBlocks........................... 48
UnusedBytes............................ 393,216
LastUsedExtFileId.................... 4
LastUsedExtBlockId................... 57,856
LastUsedBlock......................... 80
PL/SQLproceduresuccessfullycompleted.
unformattedblocks:为表分配位于高水位线之下的但未用的块数.把未格式化和未用的块加在一起,就是已为表分配但是从未保存的assm对象数据块的总块数.
FS1-FS4:包含数据的格式化块.项名后面的数字区间表示各块的空闲度,0-25表示空闲度为0-25%的块数
Fullblocks:已满的块数,不能再对这些块执行插入.
Totalblocks,bytes:为段分配的总共块数和字节数
Unusedblocks,bytes:表示未用的空间所占的比例.这些块已经分配给所查看的段,但是目前在段的高水位之上
LastUsedExtFileid:包含最后一个区块的文件的文件ID
LastUsedExtBlockId:最后一个区段开始处的块ID,这是最后使用的文件中的块ID
LastUsedBlocks:最后一个区段中最后一个块的偏移量
相关文章推荐
- mystat脚本获得oracle统计结果
- Oracle数据库搭建及PL/SQL连接(免安装客户端)
- oracle 关联多表的修改
- Oracle向MySQL迁移表结构和数据
- Oracle char、varchar、varchar2、nvarchar、nvarchar2、nchar比较
- oracle常用数据字典
- Oracle IN 突破1000
- oracle、mysql、sql server等;流行数据库的链接驱动配置
- ORACLE取周、月、季、年的开始时间和结束时间
- oracle优化查询
- 关于oracle的监听响应速度过慢
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- oracle中long和date的互换
- 【ORACLE】oracle的一些操作记录
- Oracle VM + centos7.1+openstack kilo 多结点安装教程---neutron的安装(3)
- Oracle VM + centos7.1+openstack kilo 多结点安装教程---neutron的安装(2)
- jdbc查询oracle空字段数据时的表现
- Oracle中Number decimal(numeric )、float 和 real 数据类型的区别
- MySQL与Oracle 差异比较之三函数
- 7.34 Unix卸载oracle