- 論壇徽章:
- 0
|
可以使用如下方法查碎片:
select bytes from dba_free_space;
可以采用如下方法查系統(tǒng)中物理上不連續(xù)的碎片:
create table wg_dba_free_space
as select * from dba_free_space where 1=2;
create table wg_free_space as select file_id,block_id,blocks from dba_free_space;
create or replace procedure sp_freespace_wg
/*目的是找出系統(tǒng)中物理上不連續(xù)的碎片個(gè)數(shù);而通過(guò)select count(*) from dba_free_space中得到的數(shù)目減去它計(jì)算出來(lái)的東西,就是可以通過(guò)coalesce命令整理的碎片數(shù)了。*/
is
p_file_id number;
p_block_id number;
p_blocks number;
pre_block_id number;
pre_blocks number;
pre_file_id number;
cursor c1 is
select file_id,block_id,blocks
from wg_dba_free_space
where tablespace_name='TS_BILL1'
order by file_id asc,block_id asc;
begin
p_file_id:=0;
p_block_id:=0;
p_blocks:=0;
pre_block_id:=0;
pre_file_id:=0;
for dba_data_files_rec in c1 LOOP
p_file_id:=dba_data_files_rec.file_id;
p_block_id:=dba_data_files_rec.block_id;
p_blocks:=dba_data_files_rec.blocks;
if (p_file_id=pre_file_id) and (p_block_id=pre_block_id+p_blocks) then
/*update*/
update wg_free_space set
blocks=blocks+p_blocks
where file_id=p_file_id
and block_id=p_block_id;
else
insert into wg_free_space(file_id,block_id,blocks)
values(p_file_id,p_block_id,p_blocks);
end if;
pre_file_id:=p_file_id;
pre_block_id:=p_block_id;
pre_blocks:=p_blocks;
commit;
end loop;
end;
execute sp_freespace_wg; |
|