2009年1月13日星期二

使用show_space工具

这个工具也是大叔写的,用来查看表或者索引所占的空间还是很方便的,只需要登录到相应的用户下,执行脚本就可以了。用法应该不用我说了,看看脚本内容就知道了。

create or replace procedure show_space(
p_segname in varchar2,
p_owner in varchar2 default user,
p_type in varchar2 default 'TABLE')
as
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;

begin
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 );

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 );

dbms_output.put_line( 'Free Blocks');
dbms_output.put_line( l_free_blks );
dbms_output.put_line( 'Total Blocks');
dbms_output.put_line( l_total_blocks );
dbms_output.put_line( 'Total Bytes');
dbms_output.put_line( l_total_bytes );
dbms_output.put_line( 'Unused Blocks');
dbms_output.put_line( l_unused_blocks );
dbms_output.put_line( 'Unused Bytes');
dbms_output.put_line( l_unused_bytes );
dbms_output.put_line( 'Last Used Ext FileId');
dbms_output.put_line( l_lastusedextfileid );
dbms_output.put_line( 'Last Used Ext BlockId');
dbms_output.put_line( l_lastusedextblockid );
dbms_output.put_line( 'Last Used Block');
dbms_output.put_line( l_last_used_block );
end;
/
grant execute on show_space to public;

没有评论: