Monday, May 4, 2020

Oracle database start automatic after unix/linux system reboot

The "su" Command

The following method for automating database startup and shutdown of Oracle instances on Linux works equally well for Oracle 9i, 10g, 11G and 12c. It can be used on any RHEL-style distribution, including Oracle Linux, up to an including RHEL7. I still use this method for Oracle 12c on OL6. It will work for RHEL7/OL7, if any one wish then use the systemd services.

Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.

TSH1:/u01/app/oracle/product/12.2.0.1/db_1:Y

Create a file called "/etc/init.d/dbora" as the root user, containing the following code. Adjust the paths to match your system.

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.

#ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
#ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
#ORA_HOME=/u01/app/oracle/product/11.2.0.4/db_1
#ORA_HOME=/u01/app/oracle/product/12.1.0.2/db_1
ORA_HOME=/u01/app/oracle/product/12.2.0/db_1
ORA_OWNER=oracle
export ORACLE_UNQNAME=abcdb

if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
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
        # Remove "&" if you don't want startup as a background process.
        su $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" &
        touch /var/lock/subsys/dbora
        ;;
    '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 "$ORA_HOME/bin/dbshut $ORA_HOME"
        rm -f /var/lock/subsys/dbora
        ;;
esac

Use the chmod command to set the privileges to 750.

chmod 750 /etc/init.d/dbora

Associate the "dbora" service with the appropriate run levels and set it to auto-start using the following command.

chkconfig --add dbora


The relevant instances should now startup/shutdown automatically at system startup/shutdown.

You can start and stop the database using the service, which is what will happen on a reboot.

# service dbora start
# service dbora stop

No comments:

Post a Comment