自动重建失效index的shell脚本

自动重建失效index的shell脚本
脚本每一个小时运行一次,检测失效索引,一旦发现立刻重建
脚本全部内容如下:
[oracle@orac1 pump]$ more /home/oracle/tools/rebuild_index.sh

#Enviroment define.
source /home/oracle/tools/SET_JOB_ENV.sh
export PATH=$PATH

#following is excution part
sqlplus / as sysdba <declare
begin
  for i in (select index_name,owner from dba_indexes where status ='UNUSABLE' and wner='EDW1_USER') loop
    execute immediate 'alter index '||i.owner||'.'||i.index_name||' rebuild online';
  end loop;
  for j in (select index_name,partition_name,index_owner from dba_ind_partitions where status ='UNUSABLE' and index_owner='EDW1_USER') loop
    execute immediate 'alter index '||j.index_owner||'.'||j.index_name|| ' rebuild partition '||j.partition_name||' online';
  end loop;
end;
/
exit
eof

其中为环境变量设置脚本为
[oracle@orac1 pump]$ more /home/oracle/tools/SET_JOB_ENV.sh
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
#oracle env
ORACLE_BASE=/data/oracle
ORACLE_HOME=$ORACLE_BASE/product/10.2/db1
ORA_CRS_HOME=$ORACLE_BASE/product/10.2/crs
export ORACLE_BASE ORACLE_HOME
ORACLE_SID=justin
export ORACLE_SID
ORACLE_TERM=xterm
export ORACLE_TERM
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export CLASSPATH
PATH=$HOME/bin:$ORACLE_HOME/bin:$PATH:$ORA_CRS_HOME/bin
NLS_LANG=AMERICAN_AMERICA.UTF8

添加至crontab
#check the unusable index and rebuild them online if exists
01 */1 * * * sh /home/oracle/tools/rebuild_index.sh

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15480802/viewspace-687451/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15480802/viewspace-687451/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值