何时应该降低高水位(HWM)

一、
何时应该降低高水位(HWM

Table包含两种空闲的block,在HWM之上的空闲block和在HWM之下的空闲Block
释放HWM之上的空闲block
Alter table table_name deallocate unused;

对于HWM之下的空闲block,是我们要重点操作的对象,也就是降低高水位,具体操作如下:
1.
对于不管是LMT下的FLM还是ASSM
都可以使用以下procedure来得到tableblocks使用情况,但是,如果段空间管理是FLM,需要指定参数p_space MANUAL’p_analyzed’N’
Show_space存储过程:
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'
)
as
p_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 )
is
begin
dbms_output.put_line( rpad(p_label,40,'.') ||
p_num );
end;
begin
p_segname := upper(p_segname_1); -- rainy changed
p_owner := upper(p_owner_1);
p_type := p_type_1;

if (p_type_1 = 'i' or p_type_1 = 'I') then --rainy changed
p_type := 'INDEX';
end if;

if (p_type_1 = 't' or p_type_1 = 'T') then --rainy changed
p_type := 'TABLE';
end if;

if (p_type_1 = 'c' or p_type_1 = 'C') then --rainy changed
p_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') then
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( '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' then
dbms_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*PLUS中,要看到这个procedure显示结果,就需要设置set serverout on。统计结果分为两部分,前一部分是可以得到一个segmentHWM的位置,这里,HWM=total_blocks-unused block+1。后一部分统计block free space使用情况,block的空间使用分为free space: 0-25%,25%-50%,50%-75%,70%-100%total5种情况,show_space会对需要统计的表汇总这5种类型的block数量。
例如:ASSM类型,用户caikemy_test表统计情况:
SQL>set serverout on
SQL> exec show_space('my_test','caike');
Total Blocks............................256
Total Bytes.............................2097152
Unused Blocks...........................64
Unused Bytes............................524288
Last Used Ext FileId....................18
Last Used Ext BlockId...................265
Last Used Block.........................64
*************************************************
The segment is analyzed
0% -- 25% free space blocks.............0
0% -- 25% free space bytes..............0
25% -- 50% free space blocks............0
25% -- 50% free space bytes.............0
50% -- 75% free space blocks............1
50% -- 75% free space bytes.............8192
75% -- 100% free space blocks...........25
75% -- 100% free space bytes............204800
Unused Blocks...........................30
Unused Bytes............................245760
Total Blocks............................124
Total bytes.............................1015808

PL/SQL procedure successfully completed.

当前HWM=256-64+1=193,当table HWM下的block的状态大多为free space较高值时,可以考虑合并HWM下的blocks,将空闲的block释放,降低tableHWM,如红色字体部分。

FLM类型,用户caikemy_test2表统计情况:
SQL> exec show_space('my_test2','caike','MANUAL','T','N');
Free Blocks.............................2
Total Blocks............................80
Total Bytes.............................655360
Unused Blocks...........................3
Unused Bytes............................24576
Last Used Ext FileId....................41
Last Used Ext BlockId...................81
Last Used Block.........................5

PL/SQL procedure successfully completed.

当前HWM=80-3+1=78,如果free_blocks较高,说明需要降低高水位。
注意:红色字体部分必须指定。
阅读更多
文章标签: oracle 管理
个人分类: oracle DB
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭