# Oracle Database - Automating Shutdown and Startup on Linux

## 1 - About

Automating database startup and shutdown guards against incorrect database shutdown.

Since the version 11.2, it's recommended to use Oracle Restart but a single database installation doesn't install it.

Before the version 11.2, to automate database startup and shutdown, the $ORACLE_HOME/bin/dbstart and$ORACLE_HOME/bin/dbshut scripts must be used.

The init command in the operating system documentation for more information about system startup and shutdown procedures.

The scripts refer to the same entries in the oratab file, which are applied on the same set of databases. You cannot, for example, have the dbstart script automatically start sid1, sid2, and sid3, and have the dbshut script shut down only sid1. However, you can specify that the dbshut script shuts down a set of databases while the dbstart script is not used at all. To do this, include a dbshut entry in the system shutdown file, but do not include the dbstart entry from the system startup files.

## 3 - Scripts Steps

• Log in as the root user.

### 3.1 - oratab

You must Edit the file oratab.

• On Solaris: /var/opt/oracle/oratab
• On AIX, HP-UX, and Linux: /etc/oratab

The oratab file contains database entries in the following format:

SID:ORACLE_HOME:{Y|N|W}

If you add new database instances to the system and automate startup for them, then you must edit the entries for those instances in the oratab file.

#### 3.1.1 - For a single Instance

In this example, the values Y and N specify whether you want the scripts to start or shut down the database, respectively. For each database for which you want to automate shutdown and startup, first determine the instance identifier (SID) for that database, which is identified by the SID in the first field. Then, change the last field for each to Y.

#### 3.1.2 - For ASM

You can set dbstart to autostart a single-instance database that uses an Automatic Storage Management installation that is auto-started by Oracle Clusterware. This is the default behavior for an Automatic Storage Management cluster. If you want to do this, then you must change the oratab entry of the database and the Automatic Storage Management installation to use a third field with the value W and N, respectively. These values specify that dbstart auto-starts the database only after the Automatic Storage Management instance is started.

#### 3.1.3 - Example

#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed. # # orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_2:Y ### 3.2 - Dbora file Create a file called dbora, and copy the following lines into this file: • Change the value of the ORACLE_HOME environment variable to an Oracle home directory for the installation. • Change the value of the ORACLE environment variable to the user name of the owner of the database installed in the Oracle home directory (typically, oracle). #! /bin/sh -x # # Change the value of ORACLE_HOME to specify the correct Oracle home # directory for your installation. # For info: On 11.2 ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1 # # Change the value of ORACLE to the login name of the # oracle owner at your site. (typically, oracle). # export ORACLE=oracle # PATH and HOME export JAVA_HOME=/usr/java/latest export ORACLE_HOME_LISTENER=$ORACLE_HOME
export ORACLE_TRACE=Y
export PATH=$JAVA_HOME/bin:$ORACLE_HOME/bin:$PATH echo$PATH

# The accents are important. Don't change them ...
HOST=hostname
PLATFORM=uname

#
if [ ! "$2" = "ORA_DB" ] ; then if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l$ORACLE -n "$0$1 ORA_DB"
exit
else
rsh $HOST -l$ORACLE  $0$1 ORA_DB
if [ "$PLATFORM" = "Linux" ] ; then touch /var/lock/subsys/dbora fi exit fi fi # # Source function library. # This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. . /etc/rc.d/init.d/functions # See how we were called. case "$1" in
start)
su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE -c$ORACLE_HOME/bin/dbstart
;;
stop)
su - $ORACLE -c$ORACLE_HOME/bin/dbshut
su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl stop"
;;
su - $ORACLE -c$ORACLE_HOME/bin/dbshut
su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE -c$ORACLE_HOME/bin/dbstart
;;
status)
$ORACLE_HOME/bin/lsnrctl status ;; *) echo$"Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0 This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER, then you must specify the listener name in the stop and start commands: $ORACLE_HOME/bin/lsnrctl {start|stop} listener_name
chgrp dba dbora
chmod 750 dbora

Create symbolic links to the dbora script in the appropriate run-level script directories as follows.

• AIX
ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
ln -s /etc/dbora /etc/rc.d/rc0.d/K01dbora
• HP-UX
ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
ln -s /sbin/init.d/dbora /sbin/rc0.d/K001dbora
• 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
• Solaris
ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora

## 4 - Documentation / Reference

db/oracle/startstop.txt · Last modified: 2018/09/16 12:42 by gerardnico