- 论坛徽章:
- 0
|
我想检查我的ORACLE数据库里citrix用户表空间下有哪些索引是需要重建的,当前的用户和表空间为citrix,我用了analyze index index_name validate structure命令对生成的index_stats表做分析,如果B-Tree高度超过3或叶子行的碎片超过20%,那么确认此索引是需要重建的。
由于视图index_stats中只保存一次analyze的分析结果,因此,做完一次analyze就需要将结果插入到表stats_indexes中,因此我建了一个与index_stats视图结构相同的表stats_indexes作为保存分析结果的中间表,然后分步对dba_indexes中列出的citrix用户的索引做analyze index index_name validate structure,将结果保存到表stats_indexes中,然后分析stats_indexes表中的数据,选出B-Tree高度超过3和叶子行碎片超过20%的索引。
具体步骤如下:
SQL>;analyze index <index_name>; validate structure;
SQL>;insert into stats_indexes select * from index_stats;
SQL>;commit;
SQL>;SELECT name,height,del_lf_rows,lf_rows,
ROUND((del_lf_rows / (lf_rows+0.0000000001))*100) "Frag Percent"
FROM stats_indexes
where height>;=3;
由于citrix表空间下有700多个索引,如果逐步进行分析,将花去我大量的时间,因此,我想用PL/SQL程序按照上面的做法写一个批量分析脚本,我写的程序如下:
declare
begin
truncate table stats_indexes;
for rec in (select count(*) from user_indexes where table_owner='CITRIX' order by tablespace_name,table_name)
loop
execute immediate 'analyze index '||rec.index_name||' validate structure';
insert into stats_indexes select * from index_stats;
commit;
end loop;
end;
/
但我执行此程序的时候报错,请大家帮我看看程序有什么问题。
truncate table stats_indexes;
*
ERROR at line 2:
ORA-06550: line 2, column 10:
PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:
:= . ( @ % ;
The symbol ":= was inserted before "TABLE" to continue. |
|