Tuesday 12 March 2013

Automating Database Startup and Shutdown on Linux


To automatically start the database and listener

with root user

1) Edit the /etc/oratab file as

[root@server1 ~]# gedit /etc/oratab

e.g your database name is orcl then
in this file there will be a line as

orcl:/oracle/product/10.2.0/db_1:N--------only change this 'N' to 'Y'

2) Create dbora file under /etc/init.d/  using following script .

---------------dbora start--------------------



#!/bin/sh

# The script in dbora starts and shuts down the Oracle database automatically.
# Description: This script calls the dbstart script to start oracle and dbshut to stop oracle.

ORA_HOME=/app/oracle/product/11.2/db_home
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ];
then
        echo "Sorry!!! The $ORA_HOME/bin/dbstart is missing"
        echo "Cannot start Oracle"
        exit
fi

case "$1" in
'start') # Starts the Oracle database and listeners
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
# su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl start"
                ;;
'stop') # Stops the Oracle databases and listeners
 # su - $ORA_OWNER -c "$ORA_HOME/bin/isqlplusctl stop"
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl stop dbconsole"
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
;;
esac


---------------dbora end--------------------------------


3)[root@server1 ~]# chmod 755 /etc/init.d/dbora

4) run these commands one by one

   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc0.d/K10dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc1.d/K10dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc2.d/K10dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc4.d/K10dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc5.d/S99dbora
   [root@server1 ~]# ln -s /etc/init.d/dbora /etc/rc6.d/K10dbora

5) [root@server1 ~]# reboot

No comments:

Post a Comment