Monday, January 19, 2009

Automating startup/shutdown of Oracle database on Linux

The following script can be used to automate database startup/shutdown of an Oracle database on Linux platform.

- update the oratab file under /etc or /var/opt/oracle

"SID":"ORACLE_HOME":Y

where Y states that the database to be started up/shutdown

- Create the service script in the following location:

/etc/init.d/
vi dbora

- Modify the following script to match the specific environment and This becomes the content of the "dbora" service script.

===================================================================================

#!/bin/sh
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes

DB_SCRIPTS=" FULL DATABASE SCRIPT LOCATION HERE"
APPS_SCRIPTS=:" FULL APPS SCRIPT LOCATION HERE"
ORADEV_OWNER=DB_USER
APPSDEV_OWNER=APPS_USER
LOG_FILE='touch /var/lock/subsys/dbora'

case "$1" in
'start') # Start the Oracle database,listener and apps
su - $ORADEV_OWNER -c "$DB_SCRIPTS/addbctl.sh start"
su - $ORADEV_OWNER -c "$DB_SCRIPTS/addlnctl.sh start SID"
sleep 100
su - $APPSDEV_OWNER -c "$APPS_SCRIPTS/adstrtal.sh apps/apps"
;;
'stop') # Stop the Oracle database,listener and apps
su - $APPSDEV_OWNER -c "$APPS_SCRIPTS/adstpall.sh apps/apps"
sleep 300
su - $ORADEV_OWNER -c "$DB_SCRIPTS/addlnctl.sh stop SID"
su - $ORADEV_OWNER -c "$DB_SCRIPTS/addbctl.sh stop immediate"
rm /var/lock/subsys/dbora
;;
esac

===================================================================================

Modify the sleep time according to the speed of the server and the time taken by the server to startup and shutdown the instance.

- Set script permissions:

chmod 755 /etc/init.d/dbora

- Register the Service

at the terminal prompt, issue the following command.

chkconfig --add dbora
The chkconfig creates the following symbolic links,

On SuSE SLES7:

* /etc/init.d/rc0.d/K10dbora
* /etc/init.d/rc1.d/K10dbora
* /etc/init.d/rc2.d/K10dbora
* /etc/init.d/rc3.d/S99dbora
* /etc/init.d/rc4.d/K10dbora
* /etc/init.d/rc5.d/S99dbora
* /etc/init.d/rc6.d/K10dbora

On Red Hat Advanced Server:

* /etc/rc.d/rc0.d/K10dbora
* /etc/rc.d/rc1.d/K10dbora
* /etc/rc.d/rc2.d/K10dbora
* /etc/rc.d/rc3.d/S99dbora
* /etc/rc.d/rc4.d/K10dbora
* /etc/rc.d/rc5.d/S99dbora
* /etc/rc.d/rc6.d/K10dbora

The symbolic links are not created in SLES8 and after with the 'chkconfig -add' command. To have the symbolic links created run the following in addition:

/sbin/chkconfig --set dbora 35

- Now the instance will startup automatically when Linux boots up.

3 comments:

RogerS said...

Hi...
I used your rc script as a template. I had to modify it as the database is on another node from the application tier. Anyways, I found that the call to the adstrtal.sh with the correct apps/pwd does not work under bash, Linux redhat 4 update 5 as I get an error > ERROR_MSG="Database connection could not be established. Either the database is down or the APPS credentials supplied are wrong." < in the adstrtal.log. If I execute the su - applmgr -c command with the explicit path, execute of the adstrtal.sh and the apps/pwd...it works from the root user. But not when executed by the rc5.d S99oracleapps scripts?
Strange but true.
Roger Sager

RogerS said...

Hi everyone...
Further news on Automating the startup/shutdown of Oracle DB and Apps...
1. I found that Oracle has bug checked the addbctl.sh for the AutoConfig process as this script is run for "start"...it then calls adstrtdb.sql. However, in the adstrtdb.sql the startup command has a hard coding to use the pfile= option to source the initSID.ora file. Instead, there should be no pfile= option, then the startup would source the spfileSID.ora first, failing that look for the initSID.ora file. So this is something to be aware of, especially, if your spfile and init file are different. There are several work arounds...the simplest is to remove the pfile option from the adstrtdb.sql script unitl Oracle release a fix.
2. The original posting rc script will probably work under a run level reboot condition if the Database and Oracle Apps tiers are on the same node/server. However, in my case they were separate. The 10G DB was on node 1 and the
R12.0.4 Apps was on node 2. For a reboot to run level 5 the "adstrtal.sh apps/apps" would not work because there is a sql password check at the beginning of adstrtal.sh which fails with the ORA-12560: TNS:protocol adapter error. This happens even if the Database and listener on node 1 are up and running. Oracle will not admit that they have a problem yet, but my work around is to not call the adstrtal.sh, but instead call the individual start up scripts in the appropriate order...such as
1- adopmnctl.sh start
2- adalnctl.sh start
3- adapcctl.sh start
4- adoacorectl.sh start
5- adformsctl.sh start
6- adoafmctl.sh start
7- adcmctl.sh start apps/apps
8- jtffmctl.sh start
...then on "stop" call them in the reverse order. This work for me under Redhat 4.5, Oracle 10G, and r12.0.4 Apps.
Good Luck
Roger

tikitodo said...

there are many ways of fix broken pdf links, try this application if you’d like to get better results