Monday, March 3, 2008

Auto Start Oracle

Start and shut of oracle database when machine boot up and shutdown.

create a script name oracle with the below text in /etc/init.d as root.


#chkconfig: 2345 99 1
#description: testing script
#
#!/bin/sh

user=oracle
SU=/bin/su
export ORACLE_HOME=/opt/app/oracle/product/10.2.0/db_1

case "$1" in
start)
touch /var/lock/subsys/oracle
$SU $user $ORACLE_HOME/bin/dbstart
;;
restart)
$SU $user $ORACLE_HOME/bin/dbshut
rm -f /var/lock/subsys/oracle
touch /var/lock/subsys/oracle
$SU $user $ORACLE_HOME/bin/dbstart
;;
stop)
$SU $user $ORACLE_HOME/bin/dbshut
rm -f /var/lock/subsys/oracle
;;
*)
echo "Usage : oracle start restart stop"
;;
esac

#chkconfig: 2345 99 1 tells the start portion will run in runlevels of 2,3,4 and 5 and start value is 1 (S01) and kill value is 99 (K99).

A file in /var/lock/subsys/service_name is needed to run the shutdow part of the script.
/var/lock/subsys/oracle is used for this.

Staying in /etc/init.d type

/sbin/chkconfig --add oracle to add the startup and shutdown scripts to respective runlevels.
/sbin/chkconfig --del oracle to delete the service.
/sbin/chkconfig oracle on/off to disable and enable service start up on boot time.

edit the /etc/oratab file and add Y to end of the line of the instance that needs to startup when machine boots.

ent10:/oraclebase/app/oracle/product/10.2.0/db_1:Y

Current dbstart and dbshut script in $ORACLE_HOME/bin has errors that require you pass the ORACLE_HOME when you call them. To fix this edit
ORACLE_HOME_LISTNER=$1 to ORACLE_HOME_LISTNER=$ORACLE_HOME
on both dbstart and dbshut.

Related Metalink notes

Note:61333.1 - AUTOMATIC STARTUP AND SHUTDOWN OF ORACLE DATABASE INSTANCES
Note:207508.1 - Dbstart does not work if using an spfile only
Note:91815.1 - The Annotated dbstart Script
Note:1019790.6 - AUTOMATIC STARTUP/SHUTDOWN OF ORACLE INSTANCES ON HP-UX UNIX
Note:1019817.6 - AUTOMATIC STARTUP/SHUTDOWN OF ORACLE INSTANCES ON IBM AIX
Note:222813.1 - How to Automate Startup/Shutdown of Oracle Database on Linux