溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

自動重建失效index的shell腳本怎么寫

發(fā)布時間:2021-11-04 17:08:57 來源:億速云 閱讀:145 作者:柒染 欄目:建站服務器

自動重建失效index的shell腳本怎么寫,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。

自動重建失效index的shell腳本
腳本每一個小時運行一次,檢測失效索引,一旦發(fā)現(xiàn)立刻重建
腳本全部內(nèi)容如下:
[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 <<eof
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

其中為環(huán)境變量設置腳本為
[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

看完上述內(nèi)容,你們掌握自動重建失效index的shell腳本怎么寫的方法了嗎?如果還想學到更多技能或想了解更多相關內(nèi)容,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI