開機後自動啟用Oracle DB


編輯 /etc/oratab

將  testdb:/opt/oracle/112:N 改成 testdb:/opt/oracle/112:Y或者新增  *:/opt/oracle/112:Y

其格式為 : <$ORACLE_HOME> : , *表示所有的Instance,Y表示啟用自動開啟資料庫功能

新增 Shell Script ,加入下列 Command 並且將此檔置於 /etc/init.d/(此為範例,檔名為 ora11):

#!/bin/sh
ORA_HOME=/opt/oracle/112
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login
        # will not prompt the user for any values
        su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut immediate"
        su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
        ;;
esac

接者將此 Script 加入啟動選項

# chkconfig --add ora11

修改開機預設啟動 runlevel

# chkconfig --list ora11

# chkconfig --level 35 ora11 on

Oracle DB的listener.log清理