By default, Oracle software installation does not deploy automatic startup and shutdown init scripts on the platform.It’s desirable to have the Oracle database and listener automatically shutdown and startup when the server reboots unexpectedly.
Step 1. Edit the /etc/oratab file, and place a Y at the end of the entry for the databases you want to automatically restart when the system reboots. This might need root privileges to edit the file:
#vi /etc/oratab
DEMO:/opt/oracle/product/12.2.0/db_1:Y
The Y on the end of the string signifies that the database can be tarted and stopped by the $ORACLE_HOME/bin/dbstart and $ORACLE_HOME/bin/dbshut scripts.
Step 2. Create the service script /etc/init.d/dbora. Content of the script is as follows.We need to change the values of variables ORACLE_HOME and ORACLE_OWNER as per our environment. This is a bare bones script for stop and start a database and listener:
# vi /etc/init.d/dbora
#!/bin/sh
ORACLE_HOME=/opt/oracle/product/12.2.0/db_1
ORACLE_OWNER=oracle
case "$1" in
'start') # Start the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start LISTENER"
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
;;
'stop') # Stop the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start LISTENER"
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
;;
esac
# End of script dbora
Step 3. Adding this init script to rc0, rc3 and rc5
We use 3 soft links to add them into different running levels and prioritize the execution orders by naming the file.
# chgrp dba dbora
# chmod 750 dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
#ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
Step 4. For testing the script:
Restart the whole server
# init 6
For manually start/stop DB and listener:
A: To test whether the dbora script is working, as root run the following to stop your database and listener:
# /etc/init.d/dbora stop
B. To test the startup of your database and listener, as root issue the following command:
# /etc/init.d/dbora start
==========================Thank You============
Shell Script to automate Oracle Database and Listener Startup/Shutdown on Linux
Script For Monitoring Alert Log
Requirement:
A shell script to monitor alert log for all the databases on a server once in every 15 min.And in the case of any ORA- error mail to the respective TEAM.
Below script is prepared using the ADRCI utility of oracle 11g and above.
Script: alert_log_ora_errorchecking.sh
#!/bin/sh
##################################################################################
###### ALERT LOG CHECKING VIA ADRCI #######################################################
###### Author - XXXXXX#######################################################
###################################################################################
export ORACLE_BASE=/u01/app
export ORACLE_HOME=/u01/app/oracle/product/11.2.3/dbhome_1
export ORACLE_SID=Demo
export LOG=/home/oracle/DBA_SCRIPTS/alert_demo_err.log
export adrci_home=diag/rdbms/demo/demo
export HOST_NAME=demoserv
echo '######################################################################' > $LOG
echo '####ALERT LOG OUTPUT FOR LAST 15 MINUTES #######################' >> $LOG
echo '###################################################################' >> $LOG
#adrci_homes=( $(adrci exec="show homes" | grep -e rdbms -e asm))####If ASM
echo '####################################################' >> $LOG
echo '#### find below error details for the Database:' $ORACLE_SID '#########' >> $LOG
echo '############Host Name :' $HOST_NAME '###################' >> $LOG
echo '####################################################' >> $LOG
echo '' >> $LOG
echo '' >> $LOG
echo '' >> $LOG
for adrci_home in ${adrci_home[@]}
do
echo $adrci_home' Alert Log' >> $LOG
adrci exec="set home ${adrci_home}; show alert -p \\\"message_text like '%ORA-%' and originating_timestamp > systimestamp-1/96\\\"" -term >> $LOG
done
[[ `grep -c "ORA-" ${LOG}` -gt 0 ]] && mail -s "ORA- error found in alert Log of the server" xyz@thedbaportfolio.com <$LOG
Permission:
chmod 755 alert_log_ora_errorchecking.sh
Crontab entry:
0,15,30,45 * * * * /home/oracle/DBA_SCRIPTS/alert_log_ora_errorchecking.sh > /dev/null
Subscribe to:
Posts (Atom)