Automate oracle startup on linux reboot

In this forum you can share stuff related to Oracle 11g, 10g, 9i.
Post Reply
MasterN
Posts: 12
Joined: Mon Jun 23, 2008 3:32 am
Location: Pakistan

Automate oracle startup on linux reboot

Post by MasterN »

How can we automate database startup shutdown on linux reboot?
amirtai
Posts: 138
Joined: Sat Apr 08, 2006 5:54 pm
Location: Canada
Contact:

Post by amirtai »

Hi there

Please always mention the database version in your question. Here's a solution for Oracle Server - Enterprise Edition - Version: 8.1.7.4 to 10.1.0.3:

The DB 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 - 1: Check the oratab file in /etc/oratab. This should have the entry for the DB we are dealing with, with a value Y, like:
$ORACLE_SID:$ORACLE_HOME:Y

Step - 2: Login to root.
Save the following file in /etc/rc.d/init.d/oracle:

#!/bin/sh
#
# /etc/rc.d/init.d/oracle
# Description: Starts and stops the Oracle database and listeners
# See how we were called.
case "$1" in
start)
echo -n "Starting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Starting Oracle Listeners: "
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
stop)
echo -n "Shutting Down Oracle Listeners: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Shutting Down Oracle Databases as part of system down." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c "lsnrctl stop" >> /var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle
echo -n "Shutting Down Oracle Databases: "
su - oracle -c dbshut >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
;;
restart)
echo -n "Restarting Oracle Databases: "
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Restarting Oracle Databases as part of system up." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
su - oracle -c dbstop >> /var/log/oracle
su - oracle -c dbstart >> /var/log/oracle
echo "Done."
echo -n "Restarting Oracle Listeners: "
su - oracle -c "lsnrctl stop" >> /var/log/oracle
su - oracle -c "lsnrctl start" >> /var/log/oracle
echo "Done."
echo ""
echo "----------------------------------------------------" >> /var/log/oracle
date +"! %T %a %D : Finished." >> /var/log/oracle
echo "----------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;
*)
echo "Usage: oracle {start|stop|restart}"
exit 1
esac

It is worth checking that this file actually correctly stops and starts the databases for your system. Check the log file, /var/log/oracle for error messages.

Once this script is working we need to create start and kill symbolic links in the appropriate runlevel directories /etc/rc.d/rcX.d.

The following commands will ensure that the databases will come up in runlevels 2,3 and 4:

$ ln -s ../init.d/oracle /etc/rc.d/rc2.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc3.d/S99oracle
$ ln -s ../init.d/oracle /etc/rc.d/rc4.d/S99oracle

To stop the databases on reboot or restart we need the following links:

$ ln -s ../init.d/oracle /etc/rc.d/rc0.d/K01oracle # Halting
$ ln -s ../init.d/oracle /etc/rc.d/rc6.d/K01oracle # Rebooting


Please refer to Metalink doc ID: 281912.1 for further info.

Regards
Amir
MasterN
Posts: 12
Joined: Mon Jun 23, 2008 3:32 am
Location: Pakistan

Post by MasterN »

Dear Amir,

My database version is 10g 2.0 and I already perfomed all the steps like you mentioned.

but after all this error occured:

dbora: execvp : no such file or directory exist.
rs: starting dbora: failed.


Here is my script dbora:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
#ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi

case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
;;
esac

After this set the privileges to 750,
chmod 750 /etc/init.d/dbora

After this Associate the dbora service with the appropriate run levels and set it to auto-start using the following command.
chkconfig --level 345 dbora on

Everything is ok. but the error occured. Why?

Thanks for your cooperation,
admin
Posts: 2062
Joined: Fri Mar 31, 2006 12:59 am
Location: Pakistan
Contact:

Post by admin »

Please check File ( /etc/sysconfig/oracle )

which have two line

START_ORACLE_DB="no"
START_ORACLE_DB_LISTENER="no"

replace them with Yes instead of No....
MasterN
Posts: 12
Joined: Mon Jun 23, 2008 3:32 am
Location: Pakistan

Post by MasterN »

no such file exist in the location
/etc/sysconfig/

Thanks,
amirtai
Posts: 138
Joined: Sat Apr 08, 2006 5:54 pm
Location: Canada
Contact:

Post by amirtai »

Hi

I would try running that script manually from shell prompt after setting up ORA env variables without passing any arguments:

. oraenv

$ORACLE_HOME/bin/dbstart

$ORACLE_HOME/bin/dbshut

Let's figure out first, which script is causing error.

Regards

Amir
MasterN
Posts: 12
Joined: Mon Jun 23, 2008 3:32 am
Location: Pakistan

Post by MasterN »

hi,

when i direct run the script

etc/init.d/dbora

then error occured no such file or directory? but root have the 755 permissions on the script dbora.
amirtai
Posts: 138
Joined: Sat Apr 08, 2006 5:54 pm
Location: Canada
Contact:

Post by amirtai »

Hi

Please run that script individually as suggested earlier and let us know the result.

Regards

Amir
MasterN
Posts: 12
Joined: Mon Jun 23, 2008 3:32 am
Location: Pakistan

Post by MasterN »

Dear,

I run the script individually, the error occured

dbora: execvp: no such file or directory
rc: starting dbora: failed.

any help?

Thanks,
amirtai
Posts: 138
Joined: Sat Apr 08, 2006 5:54 pm
Location: Canada
Contact:

Post by amirtai »

Hello

Please paste your "dbora: script here, so we could look into it.

Regards

Amir
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests