The Oracle Database software provides the following two scripts to configure automatic Database startup and shutdown with the server:
[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
We need to call these two scripts in the unix startup/shutdown script (rc0.d/rc1.d, etc.)
1. Check the oratab file under/etc/oratab. The file should contain the entries of the database to be set to auto start and close,
The autostart value is Y, as shown below:
$ 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. Save the following file to/etc/init. d/(/etc/init. d/is unique in RedHat linux ).
[Root @ prod init. d] # pwd
/Etc/init. d
[Root @ prod init. d] # ls-l dbora
-Rw-r -- 1 root 1049 Mar 27 :10 dbora
-- Note the setting of ORA_OWNER and ORA_HOME variables.
---------------- 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 ---------------------------------