Automate database Startup and Shutdown

Oracle

To automate the database startup and shutdown perform the below steps

  1. Add the below entry /etc/oratab file

bharatdb:/u01/app/oracle/product/11.2.0/db_2:Y

  1. Prepare the script /etc/init.d/dbora as root user

vi 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/db_2; export ORA_HOME;
ORA_OWNER=oracle; export ORA_OWNER;
#export ORACLE_UNQNAME=DB11G
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
echo -n “Starting Oracle Databases: ” > /var/log/oracle
echo “——————————————-” >> /var/log/oracle
date +”! %T %a %D : Starting Oracle Databases as
part of system up.” >> /var/log/oracle
echo “——————————————-” >> /var/log/oracle
su $ORA_OWNER -c “$ORA_HOME/bin/dbstart $ORA_HOME”
echo “Done.” >> /var/log/oracle
echo “” >> /var/log/oracle
echo “——————————————-” >> /var/log/oracle
date +”! %T %a %D : Finished.” >> /var/log/oracle
echo “——————————————-” >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
echo -n “Shutting Down Oracle Listeners: ” >> /var/log/oracle
echo “——————————————–” >> /var/log/oracle
date +”! %T %a %D : Shutting Down Oracle Databases as part
of system down.” >> /var/log/oracle
echo “——————————————–” >> /var/log/oracle
su $ORA_OWNER -c “$ORA_HOME/bin/dbshut $ORA_HOME”
echo “Done.” >> /var/log/oracle
echo “”
echo “——————————————–” >> /var/log/oracle
date +”! %T %a %D : Finished.” >> /var/log/oracle
echo “——————————————–” >> /var/log/oracle
rm -f /var/lock/subsys/oracle
;;
esac

  1. Grant the necessary privileges

chmod 750 /etc/init.d/dbora

  1. Make this script run automatically with the below command

chkconfig –add dbora
Now the databases will startup/shutdown accordingly during server reboot