博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SHOW_SPACE
阅读量:7237 次
发布时间:2019-06-29

本文共 6395 字,大约阅读时间需要 21 分钟。

      这是Oracle大神TOM写的一个好工具SHOW_SPACE;它实际上就是一个存储过程,这个存储过程可以很高效的分析空间使用情况,有了此工具,就不用再通过写SQL语句来看每条记录或表占用表空间的大小了,使用起来非常方便。

一、创建存储过程

create or replace procedure show_space( p_segname_1 in varchar2,p_owner_1 in varchar2 default user,p_type_1 in varchar2 default 'TABLE',p_space in varchar2 default 'AUTO',p_analyzed in varchar2 default 'Y')asp_segname varchar2(100);p_type varchar2(10);p_owner varchar2(30); l_unformatted_blocks number;l_unformatted_bytes number;l_fs1_blocks number;l_fs1_bytes number;l_fs2_blocks number;l_fs2_bytes number;l_fs3_blocks number;l_fs3_bytes number;l_fs4_blocks number;l_fs4_bytes number;l_full_blocks number;l_full_bytes number; l_free_blks number;l_total_blocks number;l_total_bytes number;l_unused_blocks number;l_unused_bytes number;l_LastUsedExtFileId number;l_LastUsedExtBlockId number;l_LAST_USED_BLOCK number; procedure p( p_label in varchar2, p_num in number )isbegindbms_output.put_line( rpad(p_label,40,'.') ||p_num );end;beginp_segname := upper(p_segname_1); -- rainy changedp_owner := upper(p_owner_1);p_type := p_type_1; if (p_type_1 = 'i' or p_type_1 = 'I') then --rainy changedp_type := 'INDEX';end if; if (p_type_1 = 't' or p_type_1 = 'T') then --rainy changedp_type := 'TABLE';end if; if (p_type_1 = 'c' or p_type_1 = 'C') then --rainy changedp_type := 'CLUSTER';end if;  dbms_space.unused_space( segment_owner => p_owner,segment_name => p_segname,segment_type => p_type,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 ); if p_space = 'MANUAL' or (p_space <> 'auto' and p_space <> 'AUTO') thendbms_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( 'Free Blocks', l_free_blks );end if; p( 'Total Blocks', l_total_blocks );p( 'Total Bytes', l_total_bytes );p( 'Unused Blocks', l_unused_blocks );p( 'Unused Bytes', l_unused_bytes );p( 'Last Used Ext FileId', l_LastUsedExtFileId );p( 'Last Used Ext BlockId', l_LastUsedExtBlockId );p( 'Last Used Block', l_LAST_USED_BLOCK );  /*IF the segment is analyzed */if p_analyzed = 'Y' thendbms_space.space_usage(segment_owner => p_owner ,segment_name => p_segname ,segment_type => p_type ,unformatted_blocks => l_unformatted_blocks ,unformatted_bytes => l_unformatted_bytes,fs1_blocks => l_fs1_blocks,fs1_bytes => l_fs1_bytes ,fs2_blocks => l_fs2_blocks,fs2_bytes => l_fs2_bytes,fs3_blocks => l_fs3_blocks ,fs3_bytes => l_fs3_bytes,fs4_blocks => l_fs4_blocks,fs4_bytes => l_fs4_bytes,full_blocks => l_full_blocks,full_bytes => l_full_bytes);dbms_output.put_line(rpad(' ',50,'*'));dbms_output.put_line('The segment is analyzed');p( '0% -- 25% free space blocks', l_fs1_blocks);p( '0% -- 25% free space bytes', l_fs1_bytes);p( '25% -- 50% free space blocks', l_fs2_blocks);p( '25% -- 50% free space bytes', l_fs2_bytes);p( '50% -- 75% free space blocks', l_fs3_blocks);p( '50% -- 75% free space bytes', l_fs3_bytes);p( '75% -- 100% free space blocks', l_fs4_blocks);p( '75% -- 100% free space bytes', l_fs4_bytes);p( 'Unused Blocks', l_unformatted_blocks );p( 'Unused Bytes', l_unformatted_bytes );p( 'Total Blocks', l_full_blocks);p( 'Total bytes', l_full_bytes); end if; end;/

二、存储过程使用方法:

SQL> create table test01 as select * from all_objects;Table created.SQL> set serveroutput on;SQL> exec show_space('TEST01');Total Blocks............................1280Total Bytes.............................10485760Unused Blocks...........................38Unused Bytes............................311296Last Used Ext FileId....................5Last Used Ext BlockId...................610304Last Used Block.........................90*************************************************The segment is analyzed0% -- 25% free space blocks.............00% -- 25% free space bytes..............025% -- 50% free space blocks............025% -- 50% free space bytes.............050% -- 75% free space blocks............050% -- 75% free space bytes.............075% -- 100% free space blocks...........075% -- 100% free space bytes............0Unused Blocks...........................0Unused Bytes............................0Total Blocks............................1214Total bytes.............................9945088PL/SQL procedure successfully completed.SQL> delete from TEST01;85054 rows deleted.SQL> exec show_space('TEST01');Total Blocks............................1280Total Bytes.............................10485760Unused Blocks...........................38Unused Bytes............................311296Last Used Ext FileId....................5Last Used Ext BlockId...................610304Last Used Block.........................90*************************************************The segment is analyzed0% -- 25% free space blocks.............00% -- 25% free space bytes..............025% -- 50% free space blocks............025% -- 50% free space bytes.............050% -- 75% free space blocks............050% -- 75% free space bytes.............075% -- 100% free space blocks...........121475% -- 100% free space bytes............9945088Unused Blocks...........................0Unused Bytes............................0Total Blocks............................0Total bytes.............................0PL/SQL procedure successfully completed.SQL> alter table TEST01 move;Table altered.SQL> exec show_space('TEST01');Total Blocks............................8Total Bytes.............................65536Unused Blocks...........................5Unused Bytes............................40960Last Used Ext FileId....................5Last Used Ext BlockId...................609168Last Used Block.........................3*************************************************The segment is analyzed0% -- 25% free space blocks.............00% -- 25% free space bytes..............025% -- 50% free space blocks............025% -- 50% free space bytes.............050% -- 75% free space blocks............050% -- 75% free space bytes.............075% -- 100% free space blocks...........075% -- 100% free space bytes............0Unused Blocks...........................0Unused Bytes............................0Total Blocks............................0Total bytes.............................0PL/SQL procedure successfully completed.SQL>

转载地址:http://sdwbm.baihongyu.com/

你可能感兴趣的文章
字典树
查看>>
单例模式的七种写法
查看>>
extjs_08_界面布局
查看>>
卷积神经网络(CNN)代码实现(MNIST)解析
查看>>
git 在命令行与图形状态下使用详情
查看>>
爱上MVC~Web.Config的Debug和Release版本介绍
查看>>
linux操作系统中oracle数据库的密码过期问题解决
查看>>
Spring中Bean的五个作用域
查看>>
hadoop之 distcp(分布式拷贝)
查看>>
Java后端程序员1年工作经验总结
查看>>
使用Vundle管理配置Vim的插件
查看>>
JDBC连接池&DBUtils使用
查看>>
可以通过shadowserver来查看开放的mdns(用以反射放大攻击)——中国的在 https://mdns.shadowserver.org/workstation/index.html...
查看>>
IOS系统控件高度
查看>>
Flink - ResultPartition
查看>>
2017.10.09 穆瑞课KUKA机器人培训视频的感想
查看>>
Jsoup
查看>>
python中的中文编码问题
查看>>
安卓播放音频
查看>>
in linux system of ftp command
查看>>