在OEL5上設定開機時自動啟動oracle資料庫

當在OEL5上安裝好oracle資料庫時,如果重開機,你會發現資料庫沒有啟動,必須手動下指令!
通常必須先以oracle使用者登入,再下指令開啟以下三個服務:
1. 監聽器
$ lsnrctl start
2. 資料庫
$ sqlplus / as sysdba
SQL> startup
...
SQL> exit
3. EM
$ emctl start dbconsole

Oracle-Base網頁可以查到如何在OEL5上將oracle設成開機即自動啟動資料庫的方法.
步驟如下:
1. 將/etc/oratab檔案中(最後一行,最後一個字)的'N'改為'Y'
2. 建立一個檔案/etc/init.d/dbora, 內容如下:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
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 $ORA_HOME"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
touch /var/lock/subsys/dbora
;;
'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/emctl stop dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
# su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/dbora
;;
esac

3. 修改dbora的權限
$ chmod 750 /etc/init.d/dbora
4. 將dbora連結到合適的runlevel,並能自動啟動
$ chkconfig --add dbora

dbstart這個script除了會啟動資料庫(等同於SQL> startup),也會啟動監聽器!
依樣畫壺蘆,加上emctl那行即可.(在oracle 11.1測試可行!, 但是11.2有問題!)

以下部份是由同事提供的資訊, 感謝!
JOBACLE上提到11gR2有個bug!
所以必須在/etc/profile檔中加入一行:export ORACLE_UNQNAME=db_name
則/etc/profile檔尾看起來像這樣:

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
export ORACLE_UNQNAME=demo1
umask 022
fi

留言

這個網誌中的熱門文章

D-BUS學習筆記

關於藍牙裝置找尋(inquiry, scan)兩三事

Cisco Switch學習筆記: EtherChannel