Automating Oracle Database Startup and Shutdown by Linux Systemd Service

PURPOSE

Oracle recommends to configure the system to automatically start Oracle Database when the system starts, and to automatically shut it down when the system down.

Environment:

  • Operating System:     Oracle Linux 7
  • Oracle Database:        Oracle 18c

Subscribe to get access

Read more of this content when you subscribe today.

Automating 18c Oracle Database Startup and Shutdown on Oracle Linux 7

PURPOSE

Oracle recommends to configure the system to automatically start Oracle Database when Operating System starts, and to automatically shut it down when the Operating System down.

Environment:
Operating System:     Oracle Linux 7
Oracle Database:        Oracle 18c

SOLUTION

  • Check and configure  /etc/oratab appropriately.
    ...
    ..
    .
    OEMREP:/opt/oracle/product/18c/dbhome_1:Y
    ...
    ..
    .
  • Change directory to /etc/init.d, and create a file “dbora” with below contents.
#! /bin/sh
# 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 ORACLE_HOME.

ORA_HOME=<Type your ORACLE_HOME in full path here>
ORA_OWNER=<Type your Oracle account name here>

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
  • Change file “dbaora” with right group name and permission.
# chgrp dba dbora
# chmod 750 dbora
  •  Create symbolic links to the dbora script in the appropriate run-level script directories:
  1. Platform Symbolic Links Commands
    Oracle Solaris
    # ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
    # ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
    Linux
    # 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
    IBM AIX on POWER Systems (64-Bit)
    # ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
    # ln -s /etc/dbora /etc/rc.d/rc0.d/K01dbora

CHECK THE LOGS

  • /var/log/messages
  • $ORACLE_HOME/network/log/listener.log
  • $ORACLE_HOME/rdbms/log/shutdown.log
  • $ORACLE_HOME/rdbms/log/startup.log

Automating 12c Database Startup and Shutdown on Oracle Linux 7

PURPOSE

Oracle recommends to configure the system to automatically start Oracle Database when the system starts, and to automatically shut it down when the system shuts down.

Environment:
Operating System:     Oracle Linux 7
Oracle Database:        Oracle 12.1.0.2

SOLUTION

  • Check and configure  /etc/oratab appropriately
    If you want dbstart to auto-start a single-instance database that uses an ASM server that is auto-started by CRS (this is the default behavior  for an ASM cluster), you must change the database’s ORATAB entry to use  a third field of “W” and the ASM’s ORATAB entry to use a third field of “N”.
  • Change directory to /etc/init.d, and create a file “dbora” with below contents. The Oracle doc has got typo for this script part  “runuser $HOST -l $ORACLE  $0 $1 ORA_DB”, which will cause failure.
$ cat dbora
#! /bin/sh -x
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.
ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
#runuser $HOST -l $ORACLE  $0 $1 ORA_DB
    runuser  -l $ORACLE  $0 $1 ORA_DB
if [ "$PLATFORM" = "Linux" ] ; then
touch /var/lock/subsys/dbora
fi
exit
fi
#
case $1 in
'start')
$ORACLE_HOME/bin/dbstart $ORACLE_HOME &
;;
'stop')
$ORACLE_HOME/bin/dbshut $ORACLE_HOME &
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit
  • Change file “dbaora” with right group name and permission.
# chgrp dba dbora
# chmod 750 dbora
  •  Create symbolic links to the dbora script in the appropriate run-level script directories:
Platform Symbolic Links Commands
Oracle Solaris
# ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
Linux
# 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
IBM AIX on POWER Systems (64-Bit)
# ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
# ln -s /etc/dbora /etc/rc.d/rc0.d/K01dbora

Check the logs

  • /var/log/messages
  • $ORACLE_HOME/listener.log
  • $OACLE_HOME/shutdown.log
  • $ORACLE_HOME/startup.log