Forums | Aggregator | Books | Industry News | Firefox Plugins | Social | Links

Comments

Automating Database Startup and Shutdown on Linux - Use these methods to automatically startup and shutdown your database instances when your system starts and stops.



Merouane Dichou said...

Hi,

should add touch /var/lock/subsys/dbora to start and rm -f /var/lock/subsys/dbora to stop
why ?
because /etc/rc.d/rc script looks at /var/lock/subsys/SVC_NAME to
see if a service is running.
if the file do not exist then the stop (S10dbora) will not be executed and the database will not be shutdown (clean)
tested in redhat 3.0

rob said...

su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME""

contains one extra " on the end

Tim... said...

Many thanks for spotting the typo. I've corrected it now.

Cheers

Tim...

Tomas said...


Excellent to-the-point article on scripting starting/stopping of 10G.

Thanks for the heads-up on the wrong PATH in dbstart.

I prefer the non-RSH method. That way I don't have to worry about another potentially insecure service listening for connections.

Dave said...

Thanks for this - excellent work - the scripts are just what I was looking for.

Mark said...

I might add that when adding the service via checkconfig, it is better to use the

chkconfig --add dbora

this will use the chkconfig line in the dbora script and set up both K and S RC scripts. I believe the line as written will only set up the S scripts, if dbora has never been added...

Ron said...

Thanks for the great article

Andrei said...

Here is dbora that works better for me, it shows process status when using system-config-services.

Onse dbora added to /etc/init.d say

# chkconfig --add dbora

so that dbora will appear in system-config-services applet.

This script will work only and only if ORA_OWNER environment has been properly configured with ORACLE_HOME and /etc/oratab is OK as well

So here is my dbora
--
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

ORA_OWNER=oracle

# Source function library.
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 1
fi

orastatus() {
status ora_pmon_BUBAMARA
RETVAL=$?
status tnslsnr
RETVAL2=$?
if [ $RETVAL -ne 0 ] ; then
return $RETVAL
fi
if [ $RETVAL2 -ne 0 ] ; then
return $RETVAL2
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
# Assumes that ORA_OWNER environment has been
# setup properly as well as /etc/oratab
su - $ORA_OWNER -c "dbstart $ORACLE_HOME"
su - $ORA_OWNER -c "lsnrctl start"
;;
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 "dbshut $ORACLE_HOME"
su - $ORA_OWNER -c "lsnrctl stop"
;;
status)
orastatus
;;
*)
echo $"Usage: $0 {start|stop|status}"
exit 2
esac

MMcGee said...

Very helpful script. You might add that if you have problems with the su - "$ORA_OWNER" commands it might be because the Oracle shell variables are not set for that user or might be . This can be confusing since you think you set them in the dbora script...but those from root are not passed to that user...

dario the boring said...

I sustain Merouane Dichou comments.

This script will work when manually invoked, but will not be invoked by linux.

jade said...

thx!
You helped me a lot with the ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle problem

jeremy said...

Auto-startup failed for me with "permission denied." The root of the problem was that rsh was failing. The solution was to add .rhosts in the oracle user's home folder. .rhosts needs to contain the long server name and then the root user name, eg:
servername.domain.com root

.rhosts must be readable only by the owner:
chmod 700 ~/.rhosts

Then auto-startup should work.

Awesome article -thanks!

Roni Vered said...

Simple, elegant and useful.
Thanks a lot, I use this page every time I install a new database server.

Cherrs,
Roni.

Kurt said...

If you're going to edit dbstart, it is probably better to optionally preserve the previous functionality by changing the line to:

ORACLE_HOME_LISTNER=${1:-$ORACLE_HOME}

Santhosh said...

su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME""

That did not work for me. I have to change it to below to make it work:

su - $ORA_OWNER -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"

Tim... said...

Hi.

The method in the article works fine for me on all RHEL versions and their clones. What Linux distro are you using?

Cheers

Tim...

Dude said...

Using su - $ORA_OWNER is the wrong approach as it resets the shell environment varibles. Simply omit the dash.

FWIW: https://forums.oracle.com/forums/thread.jspa?threadID=2503302

Tim... said...

Hi.

On the contrary, using "su - ORA_OWNER" is the correct approach because I *want to* reset the shell variables. If I didn't, a bunch of environment variables would not be set correctly.

Cheers

Tim...

Dude said...

I do not recommend to rely on the Oracle account login profile, which can introduce additional problems. There are only 2 environment variables required:

ORACLE_HOME (no need to export)
export ORACLE_UNQNAME=orcl (11g Listener)

which are normally set in the init script anyway. Su - erases these variables. Other variables are set by the dbstart utility script and read from /etc/oratab.

Tim... said...

Hi.

I concede, it is more prone to error using the "su -" if people don't perform the correct profile setup, or do something like put a dodgy login.sql in the home directory. :)

I will revise the article to prevent people making mistakes like this.

Cheers

Tim...

Praveen said...

Hi,

Set all scripts as given. Everything is working fine. For Auto stop/start database when server reboots/shutdown/startup.

I have set below command:

chkconfig --level 036 dbora on

Since dbora script contains both startup and stop database commands and there is no condition is given to check database status to decide it has to be startup or shutdown. How system decides it?

Tim... said...

Hi.

At server startup the script is called with "start", so it will attempt to start the databases.

On shutdown, the script is called with "stop", so it will attempt to shutdown the databases.

This is just the way Linux works with services. Nothing to do with Oracle.

Cheers

Tim...

Praveen said...

Thanks Tim for your prompt reply.

I got your answer, but one more confusion,I
checked startup_shutdown.log and db alert log, I found db startup logs every time but there is no shutdown logs for database...why??

Tim... said...

Hi.

The first time the system stops it probably won't run because the "/var/lock/subsys/dbora" file will be missing. The service only attempts to start if the "/var/lock/subsys/dbora" file is missing, and will only stop if the "/var/lock/subsys/dbora" is present.

When you first set it up, the file will not be present unless you touch it.

Cheers

Tim...

Praveen said...

Thanks Tim.

Okay, I rebooted the system 3-4 times and every time getting db startup logs but not for shutdown.

Is there any way we can get it for both the operations?

Rgrds
Praveen

Tim... said...

Hi.

I've just checked "su" and 11gR2+ methods. Both work as expected. "su" method writes to $ORACLE_HOME/[startup.log|shutdown.log]. 11gR2+ method writes both events to the log specified in the dbora file.

Sounds like you've made a mistake. Open a thread in the forum and post your scripts. I'll check through them.

Cheers

Tim...

Sudhansu said...

Great precise article, thanks!

Small addition for "11gR2+" section.
To enable auto-start for oracle we also need to run "chkconfig dbora on" in addition to "chkconfig --add dbora".

Tim... said...

Hi.

Not so. When the service script begins with this,

#!/bin/sh
# chkconfig: 345 99 10

The "--add" function uses the "345" to decide which run levels the services should be on for. So "--add" turns it on for you.

Cheers

Tim...

Julio said...

Hi,

after i ran (with root) service dbora start y get:

env: /etc/init.d/dbora: No such file or directory

help?

Tim... said...

Hi.

Please stop asking questions in the comments. Ask the same question in the forum on this site and post your current configuration files in that forum post.

Cheers

Tim...

Rouge said...

Hi,
thanks for the article.
regarding the 11g2+ option.

Could nog get the statup.sh/shutdown.sh to work unless I put in the same setting as I put in the ".bash_profile" like stated in the manual
"Oracle Database 11g Release 2 (11.2) Installation On Oracle Linux 6"

link:
http://www.oracle-base.com/articles/11g/oracle-db-11gr2-installation-on-oracle-linux-6.php

Tim... said...

Hi.

I pick everything of significance up from the "/etc/oratab", so I just need the path to the "/usr/local/bin" directory really.

Cheers

Tim...
Prepared Statement Error: Table './oraclebasecms/cms_page_comment_uuids' is marked as crashed and should be repaired