萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 資料庫 >> Oracle 教學

Linux 上 Oracle 9i/10g/11g 自動啟動關閉腳本配置

適用範圍

非 RAC/ASM 環境(RAC 由 Clusterware 管理)。適用 Oracle 9iR2+。

標準作法(su 命令版)

  1. 編輯 /etc/oratab,將實例重啟旗標設為 Y:
    ORCL:/u01/app/oracle/product/11.2.0:Y
    
  2. 建立 /etc/init.d/dbora(需 root 權限):
    #!/bin/sh
    # chkconfig: 345 99 10
    # description: Oracle auto start-stop script
    ORA_HOME=/u01/app/oracle/product/11.2.0
    ORA_OWNER=oracle
    
    if [ ! -f $ORA_HOME/bin/dbstart ]; then
      echo "Oracle startup: cannot start"
      exit
    fi
    
    case "$1" in
      'start')
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
        ;;
      'stop')
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
        ;;
    esac
    
  3. 加入開機自動執行:
    chmod +x /etc/init.d/dbora
    chkconfig --add dbora
    chkconfig dbora on
    

關鍵點

  • dbstart/dbshut 讀取 /etc/oratab 中旗標為 Y 的實例
  • 監聽器先啟動、後關閉
  • su - oracle 確保環境變數正確載入
  • RAC/ASM 環境請勿使用此腳本,交由 Clusterware 管理
copyright © 萬盛學電腦網 all rights reserved