Oracle DB Auto Restart after Server Maintenance

Oracle DB Auto Restart after Server Maintenance:


To avoid manual work of restarting DBs after server maintenance, below procedure can be used

Below setup worked with OEL 7.9 with Oracle 12.1.0.2 and 19c.

touch /etc/init.d/dbora

chmod 750  /etc/init.d/dbora

place the below content on dbora and change the ORACLE_SID as defined in /etc/oratab


#! /bin/sh  -x

#

# This is my old script for auto-starting Oracle DB on Linux.

# When I'm not using Cloud Databases, I now install the Oracle Database 21c RPM which includes its own script

#

# chkconfig: 2345 80 05

# description: start and stop Oracle Databases


#

# OL7: systemctl enable dbora

#

# Note:

#   Change the awk pattern to match a DB of the ORACLE_HOME to be used

#   Change the autostart entry of /etc/oratab to Y for any DB you want started; this is required by dbstart

ORACLE_HOME=$(awk -F: '/^sbxdevdb:/ {print $2}' /etc/oratab )


[ -z "$ORACLE_HOME" ] && { echo "ORACLE_HOME is not set in dbora"; exit 1; }


#

# Note: Change the value of ORACLE to the login name of the oracle owner

ORACLE=oracle


PATH=${PATH}:$ORACLE_HOME/bin

export ORACLE_HOME PATH


case $1 in

'start')

        echo -n $"Starting Oracle: "

        su $ORACLE -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &

        su $ORACLE -c "$ORACLE_HOME/bin/lsnrctl start LISTENER" &

        ;;

'stop')

        echo -n $"Shutting down Oracle: "

        su $ORACLE -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &

        su $ORACLE -c "$ORACLE_HOME/bin/lsnrctl stop LISTENER" &

        ;;

'restart')

        echo -n $"Shutting down Oracle: "

        su $ORACLE -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &

        su $ORACLE -c "$ORACLE_HOME/bin/lsnrctl stop LISTENER" &

        sleep 5

        echo -n $"Starting Oracle: "

        su $ORACLE -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &

        su $ORACLE -c "$ORACLE_HOME/bin/lsnrctl start LISTENER" &

        ;;

*)

        echo "usage: $0 {start|stop|restart}"

        exit

        ;;

esac

sleep 20


exit


Then

edit /etc/oratab restart flag to Y

As root user


 chkconfig --add dbora

 systemctl enable dbora


test using below

service dbora stop

service dbora start


That's all. Well done!!

No comments: