Oracle Database 軟體提供了以下兩個指令碼來設定資料庫隨伺服器自動啟動和關閉:
[oracle@prod bin]$ pwd
/u01/app/oracle/product/11.2.0/db_1/bin
[oracle@prod bin]$ ls -l dbs*
-rwxr-x--- 1 oracle oinstall 6030 Jan 1 2000 dbshut
-rwxr-x--- 1 oracle oinstall 13797 Jan 1 2000 dbstart
我們需要在 unix 啟動/關閉指令碼( rc0.d / rc1.d 等)中調用這兩個指令碼
1、檢查 /etc/oratab 下的 oratab 檔案,該檔案應該包含要設定自動啟動和關閉的資料庫的條目,
其中 autostart 範圍的值為 Y,如下所示:
$ORACLE_SID:$ORACLE_HOME:Y
[oracle@prod bin]$ more /etc/oratab
prod:/u01/app/oracle/product/11.2.0/db_1:N
[oracle@prod bin]$ vi /etc/oratab
prod:/u01/app/oracle/product/11.2.0/db_1:Y
2、將如下檔案儲存到 /etc/init.d/ 下(/etc/init.d/ 是 RedHat linux 下特有的)。
[root@prod init.d]# pwd
/etc/init.d
[root@prod init.d]# ls -l dbora
-rw-r--r-- 1 root root 1049 Mar 27 20:10 dbora
--注意 ORA_OWNER 和 ORA_HOME 變數的設定
------------------ Start dbora ---------------------------------
#! /bin/bash
#
# description: Oracle auto start-stop script.
#
# chkconfig: 2345 99 10
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid
# Source function library.
. /etc/init.d/functions
RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/11.2.0/db_1"
# See how we were called.
prog="oracle"
start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
------------------ End dbora ---------------------------------