Hi,
Automating Regular Database tasks is the key priority of DBA.In the below script we can automate Databases,Listerners,HTTP services start and stop.
Step 1: Please make sure that oratab file is correct and complete.
Check for oratab file either in /etc/oratab or in /u01/app/oracle/oratab.
Database entries in the oratab file have the following format:
$ORACLE_SID:$ORACLE_HOME:[Y|N]
Here Y indicates that the database can be started up and shutdown using dbstart/dbshut script.
If in my database there is two database named testdb1 and testdb2 then my oratab file will contain the entry like,
testdb1:/u01/app/oracle/product/10.2.0/db_1:Y
testdb2:/u01/app/oracle/product/10.2.0/db_1:Y
where :/u01/app/oracle/product/10.2.0/db_1 is the $ORACLE_HOME of my database.
Step 2: Create a script to call dbstart and dbshut.
In this example I will create one script that will do both startup and shutdown operation. I will name this script as dbora and will be placed in '/etc/init.d'.
a) Login as 'root'.
b) Change directories to /etc/init.d
$cd /etc/init.d
c) Create an empty file called 'dbora' with 'touch' command and Grant permission with chmod as 750.
# touch dbora
# chmod 750 dbora
d)Edit the dbora file and make the contents of it like below.
dbora:
#!/bin/bash
#
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
#
ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
ORA_OWNER=oracle
case "$1" in
'start')
# Start the TNS Listener
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
# Start the Oracle databases:
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
# Start the Intelligent Agent
if [ -f $ORA_HOME/bin/emctl ];
then
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start agent"
elif [ -f $ORA_HOME/bin/agentctl ]; then
su - $ORA_OWNER -c "$ORA_HOME/bin/agentctl start"
else
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl dbsnmp_start"
fi
# Start Management Server
if [ -f $ORA_HOME/bin/emctl ]; then
su - $ORA_OWNER -c "$ORA_HOME/bin/emctl start dbconsole"
elif [ -f $ORA_HOME/bin/oemctl ]; then
su - $ORA_OWNER -c "$ORA_HOME/bin/oemctl start oms"
fi
# Start HTTP Server
if [ -f $ORA_HOME/Apache/Apache/bin/apachectl]; then
su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl start"
fi
touch /var/lock/subsys/dbora
;;
'stop')
# Stop HTTP Server
if [ -f $ORA_HOME/Apache/Apache/bin/apachectl ]; then
su - $ORA_OWNER -c "$ORA_HOME/Apache/Apache/bin/apachectl stop"
fi
# Stop the TNS Listener
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
# Stop the Oracle databases:
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
rm -f /var/lock/subsys/dbora
;;
esac
# End of script dbora
Step 3:As 'root' user perform the following to create symbolic links:
# ln -s /etc/init.d/dbora /etc/rc3.d/S99oracle
# ln -s /etc/init.d/dbora /etc/rc0.d/K01oracle
Alternatively we can register the Service using
/sbin/chkconfig --add dbora
This action registers the service to the Linux service mechanism.
Step 4: Test the script to make sure it works.
The real test is to reboot unix box and then see whether oracle is started up automatically or not.
However to test the script created in step 2, without rebooting, do the following:
Login as root and then,
# /etc/init.d/dbora start (for startup)
# /etc/init.d/dbora stop (for shutdown)
If we restart,start and stop oracle database is successful then we are almost done.The real Beauty of the above shell script is It will start and stop all the listener,Databases,HTTP Services whenever server is rebooted for start and stop.
Note:The above Shell Script we can modify as per our convenience.Suppose if we want to Start only Databases and Listener Sevices than comment the portion of the shell script for Starting HTTP services.
Hope it helps.
Best regards,
Rafi
Believe that anything you can imagine you can achieve it real. Having the devotion,passion and dedication to learn & Work in Oracle field mail me @ rafidba.alvi@gmail.com."Knowledge grows when it is shared". Best Career related guidance in Oracle DBA,Oracle Apps DBA,Oracle SOA Admin/Developers,ODI Developers,OBI Developers and Oracle Designers. "A Catalyst for Oracle DBA & Apps DBA Interviews,Jobs & Career."
Monday, June 20, 2011
Automate Startup and Shutdown of Oracle Database,Listener and HTTP Serivices on Linux
Labels:
DBA tasks
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment