Google it ....

Tuesday, February 4, 2014

Automatically start oracle database on linux after server reboot

Here I'll show you how to configure system for automatically start oracle database after server reboot.
oracle database 11g --- Oracle Linux 6.3
First of all, you need to make sure that any database instances you want to auto start are set to "Y" in the /etc/oratab file
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.

# 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::
#
# 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:/u0/app/oracle/product/11.2.0/dbhome_1:Y

Oracle 11g includes 2 scripts which can be used to start or shut down Oracle databases on Linux. Both scripts are in $ORACLE_HOME/bin and called dbstart and dbshut. We can add some more actions for example start enterprise manager if we create our scripts. Let's make two scripts db_start.sh and db_stop.sh
vi /u0/app/oracle/db_start.sh
# script to start the Oracle database, listener and dbconsole
. ~/.bash_profile
# start the listener and the database
$ORACLE_HOME/bin/dbstart $ORACLE_HOME
# start the Enterprise Manager db console
$ORACLE_HOME/bin/emctl start dbconsole
exit 0

vi /u0/app/oracle/db_stop.sh
# script to stop the Oracle database, listener and dbconsole
. ~/.bash_profile
# stop the Enterprise Manager db console
$ORACLE_HOME/bin/emctl stop dbconsole
# stop the listener and the database
$ORACLE_HOME/bin/dbshut $ORACLE_HOME
exit 0

inside script we are calling the .bash_profile file of the user "oracle" for export environment variables, we need it for $ORACLE_HOME.
give execute right:
chmod u+x db_start.sh db_stop.sh
With user root, create a file called "oracle" under /etc/init.d
vi /etc/init.d/oracle
ORA_OWNER=oracle
RETVAL=0
 
case "$1" in
    'start')
        # Start the Oracle databases:
        su - $ORA_OWNER -c "/u0/app/oracle/db_start.sh"
        touch /var/lock/subsys/oracle
        ;;
    'stop')
        # Stop the Oracle databases:
        su - $ORA_OWNER -c "/u0/app/oracle/db_stop.sh"
        rm -f /var/lock/subsys/oracle
        ;;
    *)
        echo $"Usage: $0 {start|stop}"
        RETVAL=1
esac
exit $RETVAL

change permission for /etc/init.d/oracle file:
chmod 750 /etc/init.d/oracle
to create service of this script:
chkconfig --add oracle

and now we can start and stop database with:
service oracle stop
service oracle start

Now it's time to test our automatically startup procedure, for this reboot your server and check if your database starts automatically after reboot.

3 comments:

  1. Hi. Good script for starting database. But it would be nice if to have script for starting applications too. )

    ReplyDelete
  2. Hi, i have reading out and i will definitely bookmarrk your site, just wanted to say i liked this article.

    ReplyDelete
  3. I hope this works. I had a few problems following what you typed here. I am a newbie to Linux. I am running Oracle Linux, and every time I reboot the server, I can not restart the Enterprise manager.

    When doing the steps, it would not let me save the files a few times in the terminal window, so I used Gedit to create them. Then I had to log in as root to create the last one. However, I got an error when inputing the last command. chkconfig --add oracle, "service oracle does not support chkconfig"

    Please advise.
    Thanks for all the help.

    Roger

    ReplyDelete