Oracle Auto-Startup Script for Linux

This post is to provide a script to auto-start Oracle Instances on Linux upon server restart.

First step would be to configure /etc/oratab file as per your requirement, oratab file is in the following format:

<DB NAME>:<ORACLE HOME>:<Y|N>

The last letter tells oracle if the database need to restarted or not, so we would change the last letter to Y of all the databases that we want to start on instance restart.

Second step would be to create a /etc/init.d/oracle script as follows:-

!/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. path to oracle home (needed only to check if dbstart exists)
ORA_HOME=<Specify absolute Oracle Home path here>
ORA_OWNER=oracle
ORACLE_SID=<SID of the DB you want to start>
PATH=$PATH:/usr/local/bin
if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle database and listener:
# Remove "&" if you don't want startup as a background process.
export ORACLE_SID=$ORACLE_SID
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
# at this point we have $ORACLE_HOME env variable set
su $ORA_OWNER -c "dbstart $ORACLE_HOME" &
touch /var/lock/subsys/oracle
;;
'stop')
# Stop the Oracle database and listener:
export ORACLE_SID=$ORACLE_SID
export ORAENV_ASK=NO
. /usr/local/bin/oraenv
su $ORA_OWNER -c "dbshut $ORACLE_HOME"
rm -f /var/lock/subsys/oracle
;;
esac

Once the script is created (Please make sure that the Oracle Home & Oracle SID is specified) execute following commands:

chmod 750 /etc/init.d/oracle
chkconfig --add oracle
chkconfig --level 2345 oracle on
chkconfig --level 06 oracle of

That’s it all your databases should now start upon the server restart.

NOTE: In case of PDB please ensure that you have saved the PDB state else the PDBs would be started in mounted state and not READ WRITE state.

ALTER PLUGGABLE DATABASE <DB NAME> SAVE STATE;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.