Monday, November 18, 2013

Automating Oracle Database Startup and Shutdown in Linux

Operating System: Oracle Linux 6.3
Database Version: 11.2.0.1.0

Given here is a bash script to automate the start up and shutdown of an Oracle database. The bash script calls out of the box Oracle DB scripts. Your Oracle database instance and the listener are started/stopped when the bash script is executed.

1. Modify the "/etc/oratab" file to allow the dbstart utility to be brought up on boot time. An example file is given below.

# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/home/oracle/db/app/oracle/product/11.2.0/dbhome_1:Y

2. Given below is a script that executes the dbstart and dbshut utilities. Place this in the "/etc/init.d" directory as the root user. Call this file dbora and set the file permissions to 750.

#!/bin/bash
# chkconfig: 345 98 11
# description: Oracle Database auto start-stop script

ORA_HOME=/home/oracle/db/app/oracle/product/11.2.0/dbhome_1
ORA_OWNER=oracle
LOG_FILE=$ORA_HOME/dbora.log

echo "Execute dbora script" >> $LOG_FILE

if [ ! -f $ORA_HOME/bin/dbstart ]
then
        echo “Oracle Database startup: cannot start” >> $LOG_FILE
        exit
fi

case "$1" in
        'start')
                echo "Start Oracle DB option" >> $LOG_FILE
                su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
                touch /var/lock/subsys/dbora
                ;;
        'stop')
                echo "Stop Oracle DB option" >> $LOG_FILE
                su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
                rm -f /var/lock/subsys/dbora
                ;;
esac


echo "End dbora script" >> $LOG_FILE 

3. Use the chkconfig command to update the configurations for the new system service. The configurations made are based on the header in the dbora file.

#chkconfig --add <filename>
sudo chkconfig --add dbora  

# Check the run levels of dbora script
sudo chkconfig --list


4. Validate the scripts.

#Start DB Instance and listener
sudo /etc/init.d/dbora start

#Stop DB Instance and listener
sudo /etc/init.d/dbora stop

 

No comments:

Post a Comment