Sunday, 24 November 2013

Find the index need to rebuild in Oracle

Goal:

Following script will help to find out the index candidate for rebuild in Oracle.

select
   p.object_name c1,
   p.operation c2,
   p.options c3,
   count(1) c4
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1,2,3;


select 'ALTER INDEX  ' ||owner||'.'||index_name||'  REBUILD ONLINE;'
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1,2,3;


select 'ALTER INDEX  ' ||object_name||'  REBUILD ONLINE;'
from
   dba_hist_sql_plan p,
   dba_hist_sqlstat s
where
   p.object_owner ='STLBAS'
and
   p.operation like '%INDEX%'
and
   p.sql_id = s.sql_id
group by
   p.object_name,
   p.operation,
   p.options
order by
   1;


select 'ALTER INDEX  ' ||owner||'.'||index_name||'  REBUILD ONLINE;' 
from dba_indexes 
where owner='STLBAS'
and table_name in('STTRNDTL','STFETRAN')

No comments:

Post a Comment