Automating Database Startup and Shutdown on Linux
When using RAC or ASM under Oracle 10g Release 2 or above, the Oracle Clusterware automatically starts and stops the Oracle database instances, so the following procedures are not necessary. For all other cases, you can use the methods described below.The "su" Command
The following represents the Oracle recommended method for automating database startup and shutdown of Oracle 9i instances.Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.
Next, create a file called "/etc/init.d/dbora" as the root user, containing the following.TSH1:/u01/app/oracle/product/9.2.0:Y
#!/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/9.2.0
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
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/dbshut
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
rm -f /var/lock/subsys/dbora
;;
esac
Use the chmod command to set the privileges to 750.Associate the dbora service with the appropriate run levels and set it to auto-start using the following command.chmod 750 /etc/init.d/dbora
The relevant instances should now startup/shutdown automatically at system startup/shutdown.chkconfig --add dbora
This method can still be used under Oracle 10g and 11g, provided the "ORA_HOME" variable is amended to use the correct path and this is added to the end of the
dbstart and dbshut lines. The lines to start and stop the listener can be removed under Oracle 10g release 2, as the dbstart command includes an automatic start of the listener.
#!/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/10.2.0/db_1
#ORA_HOME=/u01/app/oracle/product/11.1.0/db_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/dbstart $ORA_HOME"
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/dbshut $ORA_HOME"
rm -f /var/lock/subsys/dbora
;;
esac
The "rsh" Command
With Oracle 10g, Oracle switched from recommending the "su" command to the "rsh" command. In Oracle 10g release 2, thedbstart command includes an automatic start of the listener, so there are some differences between the two versions, but the following represents the preferred method for Oracle 10g.Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.
Next, create a file called "/etc/init.d/dbora" as the root user, containing the following.TSH1:/u01/app/oracle/product/9.2.0:Y
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.
ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE $0 $1 ORA_DB
exit
fi
fi
#
case $1 in
'start')
$ORACLE_HOME/bin/dbstart $ORACLE_HOME
touch /var/lock/subsys/dbora
;;
'stop')
$ORACLE_HOME/bin/dbshut $ORACLE_HOME
rm -f /var/lock/subsys/dbora
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
Use the chmod command to set the privileges to 750.Associate the dbora service with the appropriate run levels and set it to auto-start using the following command.chmod 750 /etc/init.d/dbora
The relevant instances should now startup/shutdown automatically at system startup/shutdown.chkconfig --add dbora
This method relies on the presence of an RSH server, which requires additional packages and configuration.
This can be quite problematic when attempting to use this method under FC5 and FC6, where rsh is deprecated. As a result, I prefer to use the "su" command method.# Install the rhs and rsh-server packages from the OS CD/DVD. rpm -Uvh --force rsh-* # Enable rsh and rlogin. chkconfig rsh on chkconfig rlogin on service xinetd reload
This method can also be used for 11g databases that are not using ASM or RAC.
Known Issues
When using Oracle 10g Release 2, callingdbstart might result in the following error message:This is due to a hard coded path in theFailed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr
dbstart script. To correct this, edit the "$ORACLE_HOME/bin/dbstart"
script and replace the following line (approximately line 78):With this:ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle
TheORACLE_HOME_LISTNER=$ORACLE_HOME
dbstart script shold now start the listener as expected.For more information see:
- Automating Shutdown and Startup (10.2)
- Automating Startup and Shutdown (10.1)
- Automating Database Startup and Shutdown (9.2)
Back to the Top.
