#!/bin/sh

############################################################################################
#
# Nombre script
#	'oraidxrebuild.sh'
#
# Version
#	1.0.0
# 
#  Descripcion
#	Shell script que gestiona la regeneración automática de índices y la aplicación de
#	estadísticas sobre la instancia Oracle del Gestor HP OpenView.
#
# Visita nuestra comunidad web en www.monitorizando.com 
#
############################################################################################

echo "
begin
    for v in (
        select t.index_name from sys.all_indexes t
               where   t.table_name like 'OPC_HIST%'
                    or t.table_name like 'OPC_ACT%'
                    or t.table_name like 'OPC_ANNO%'
    ) loop
        begin
           execute immediate 'alter index ' || v.index_name || ' rebuild online';
        exception
            when others then
                dbms_output.put_line(sqlerrm);
        end;
    end loop; 
    for v in (
        select t.owner, t.table_name from sys.all_tables t where t.owner = 'OPC_OP'
    ) loop
        begin
            dbms_stats.gather_table_stats(OWNNAME => v.owner, TABNAME => v.table_name, ESTIMATE_PERCENT => 25, METHOD_OPT => '
FOR ALL INDEXED COLUMNS SIZE 254', DEGREE => 2,GRANULARITY => 'ALL',CASCADE => TRUE);
        exception
            when others then
                dbms_output.put_line(sqlerrm);
        end;
    end loop;
end;
/
" | /opt/OV/bin/OpC/opcdbpwd -e sqlplus -s

