Look in:

Web oracle-core-dba.blogspot.com

Tuesday, July 31, 2007

Oracle DB Auto Start / Shutdown

How to Configure a Linux x86 Server for Oracle DB Auto Start / Shutdown

Applies to: Oracle Server - Enterprise Edition - Version: From 8.1.7.4 to 10.1.0.3 on Linux x86(32 Bit)

The Database server software provides the two scripts to configure automatic DB startup/shutdown with the server machine.
They are

$ORACLE_HOME/bin/dbstart
$ORACLE_HOME/bin/dbshut

We need to call these scripts from the unix start/shutdown scripts (rc0.d / rc1.d etc.)

Step - A:

Check the oratab file in /etc/oratab or /var/opt/oracle/oratab
This should have the entry for the DB we are dealing with, with a value Y, like:
$ORACLE_SID:$ORACLE_HOME:Y

Step - B:

Login to root. Create a new file with name like dbora and
Save the following file in /etc/init.d/
Please note that /etc/init.d is RedHat specific.
Change the permissions accordingly

#chmod 755 /etc/init.d/dbora

-rwxr-xr-x 1 root root 1412 Aug 27 19:14 dbora

Mention the correct ORA_OWNER and ORA_HOME in the dbora

------------------ Edit dbora ---------------------------------

#! /bin/bash
#
# oracle Start/Stop the Databases...
#
# chkconfig: 2345 99 10
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid

# Source function library.
. /etc/init.d/functions

RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/10.1.0/db_1"

# See how we were called.

prog="oracle"

start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dbora

return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut"
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

exit $?


------------------ Save and exit(wq) dbora ---------------------------------


Step - C: Login as root run the following:

# cd /sbin
# chkconfig --add dbora

This will create a system service viz. dbora
# chkconfig --list

This also creates the following files:

/etc/rc2.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc3.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc4.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )
/etc/rc5.d/S99dbora ( calls $ORACLE_HOME/bin/dbstart )

/etc/rc0.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )
/etc/rc1.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )
/etc/rc6.d/K10dbora ( calls $ORACLE_HOME/bin/dbshut )


chkconfig refers the " # chkconfig: 2345 99 10 " from dbora.
This signifies that the service has start run level set to 2, 3, 4 and 5.Stop run level set to 0, 1 and 6. And the start priority should be 99 and stop priority be 10.


If the version is Red Hat 3 ES or more than the dbora file needs two lines of comments.
Each service which should be manageable by chkconfig needs two or more commented lines
added to its init.d script. The second line contains a description for the service,
and may be extended across multiple lines with backslash continuation.

For example,
# chkconfig: 2345 99 10
# description: Saves and restores system entropy pool for higher quality random number generation



Step - D: Reboot the Linux box and check

In some cases for 9.2.0 we also had to copy the init file for SID "test" from /u01/app/oracle/admin/test/pfile to $ORACLE_HOME/dbs to get dbstart and dbshut working:
cp /u01/app/oracle/admin/test/pfile/inittest.ora.642002224936 $ORACLE_HOME/dbs/inittest.ora
But first make sure if your init file already exists in $ORACLE_HOME/dbs!
Note: An article from Metalink customized for my environment. May help you.

No comments: