Saturday, October 31, 2009

Automating Shutdown and Startup Oracle10g Database

To automate database startup and shutdown by using the dbstart and dbshut scripts:

1. Log in as the root user.

2. Edit the oratab file for your platform.

once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.


To open the file, use one of the following commands:



$ vi /etc/oratab

3. Create a file called dbora in /etc/init.d .
$vi /etc/init.d/dbora

!/bin/bash
# Run level script to start Oracle 10g services on RedHat Enterprise Linux (RHEL4.6)
# -------------------------------------------------------------------------
# Copyright (c) 2009 Tamim Khan
# Comment/suggestion: tamimdba@gmail.com
# -------------------------------------------------------------------------
# chkconfig: 345 91 19
# description: Startup/Shutdown Oracle service
# File Location: /etc/rc.d/init.d/dbora

OUSER="oracle"
OPATH="/u01/app/oracle/product/10.2.0/db_1"

# check Oracle db status
function chkdb_status() {

# set username
SUSER="scott"
# set password
SPASS="tiger"

sqlplus -s /nolog > /dev/null 2>&1 <<EOF
whenever sqlerror exit failure
connect $SUSER/$SPASS
exit success
EOF

if [ $? -ne 0 ]; then
echo "Connection failed : DB is down"
exit 1
else
echo "Connection succeeded : DB is up"
fi
}

case "$1" in
start)
echo  "### Starting Oracle ### "
su - $OUSER -c "$OPATH/bin/lsnrctl start"
su - $OUSER -c "$OPATH/bin/dbstart"
;;
stop)
echo  "### Stopping Oracle ### "
su - $OUSER -c "$OPATH/bin/lsnrctl stop"
su - $OUSER -c "$OPATH/bin/dbshut"
;;
restart)
$0 stop
$1 start
;;
isqlstart)
echo  "### Starting Oracle iSQL Plus ### "
su - $OUSER -c "$OPATH/bin/isqlplusctl start"
echo "### Note: You can access service at url:  http://$(hostname):5560/isqlplus"
;;
isqlstop)
echo  "### Stopping Oracle iSQL Plus ### "
su - $OUSER -c "$OPATH/bin/isqlplusctl stop"
;;
emstart)
echo  "### Starting Oracle Enterprise Manager 10g Database Control ###"
su - $OUSER -c "$OPATH/bin/emctl start dbconsole"
echo "### Note: You can access service at url:  http://$(hostname):1158/em"
;;
emstop)
echo  "### Stopping Oracle Enterprise Manager 10g Database Control ###"
su - $OUSER -c "$OPATH/bin/emctl stop dbconsole"
;;
status)
echo "### Oracle database status ###"
chkdb_status
;;
*)
echo $"Usage: $0 {start|stop|isqlstart|isqlstop|emstart|emstop}"
exit 1
esac
exit 0

The lines to start and stop the listener can be removed under Oracle 10g release 2, as the dbstart command includes an automatic start of the listener.

4. Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:
$ chgrp dba dbora
$ chmod 750 dbora

5. Add dbora in checkcofig:
    $ chkconfig  --add dbora
$ chkconfig  --level 345 dbora on