Automating Database Startup/Shutdown on Oracle Enterprise Linux

Oracle provides the ORACLE_HOME/bin/dbstart and ORACLE_HOME/bin/dbshut scripts that can be used to start the the databases when the Operating System boots and to stop the databases when shutting down the Operating System.

Both the dbstart and dbshut scripts read the /etc/oratab file to determine which databases to start and stop. All databases started with dbstart will be stopped by dbshut. Starting with Oracle 10gR2, the dbstart and dbshut scripts will start and stop the listener provided the listener has the default name and that the listener is not password protected.

The /etc/oratab needs to be edited to set the startup flag to Y to allow dbstart to start the instance. Entries in the /etc/oratab file have the following format.


ORACLE_SID – Database System Identifier
ORACLE_HOME – Complete path to the Oracle Home
{Y|N|W} – Flags used by dbstart to determine if the instance should be started. Y – Yes, N – No. W is used with ASM to direct dbstart to only start the instance after ASM is started.

For an ORACLE_SID of test with an ORACLE_HOME of /u01/app/oracle/product/11.2.0/dbhome_1 you would use an entry like the following.


With the settings made in the /etc/oratab you should be able to at this time test the start up and shutdown scripts as the Oracle software owner.

The path to the ORACLE_HOME needs to be passed in order for dbstart and dbshut to startup and shutdown the Listener along with the database. If the path is not provided a message will be given that the ORACLE_HOME_LISTENER is not set.

[oracle@odreccat etc]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME
Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log
[oracle@odreccat etc]$ 

Both dbstart and dbshut are scripts located in ORACLE_HOME/bin. A quick look at dbstart and we see that the first argument is used to set ORACLE_HOME_LISTENER.

# First argument is used to bring up Oracle Net Listener
if [ ! $ORACLE_HOME_LISTNER ] ; then
  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
  echo "Usage: $0 ORACLE_HOME"

  # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
  # a different ORACLE_HOME for each entry in the oratab.

  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
    echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1
    $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &
    VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1`
    export VER10LIST
    echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"

You can either provide the complete path of the Oracle Home or the environment variable if set. When the Oracle Home is set the message about the ORACLE_HOME_LISTENER is not present.

[oracle@odreccat etc]$ dbstart $ORACLE_HOME
Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log
[oracle@odreccat etc]$ 

Next a script needs to be prepared to handle the starting and stopping of the service. Oracle provides a script to handle this requirement. The script is commonly called dbora but can be given any name. As the root user create the file /etc/init.d/dbora using the script below.

# chkconfig: 345 99 10
# description: Service to start and stop Oracle Database and Listener
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/

# Source function library.
. /etc/init.d/functions


# See how we were called.


start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora

return $RETVAL

stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora

return $RETVAL

restart() {

case "$1" in
echo $"Usage: $0 {start|stop|restart}"
exit 1

exit $?

The only changes you need to make to this script are to provide values for ORA_OWNER and ORA_HOME that match your system. Change the group of dbora to OSDBA (dba) and set the permissions to 750.

[root@odreccat ~]# chgrp  dba /etc/init.d/dbora 
[root@odreccat ~]# chmod 750 /etc/init.d/dbora 
[root@odreccat ~]# ls -al /etc/init.d/dbora 
-rwxr-x--- 1 root dba 877 Sep  6 12:16 /etc/init.d/dbora
[root@odreccat ~]# 

While still logged in as the root user execute the dbora script with both the start and stop arguments.

[root@odreccat init.d]# ./dbora start
Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log

[root@odreccat init.d]# ./dbora stop
Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log

[root@odreccat init.d]# 

The results should be no different than when executing dbstart or dbshut. Next register the service at run-levels 3,4, and 5 and set it to auto start using chkconfig.

[root@odreccat ~]# chkconfig --level 345 dbora on

With the service registered starting and stopping the oracle services can be done with the service command.

[root@odreccat init.d]# service dbora start
Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log

[root@odreccat init.d]# service dbora stop
Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log

[root@odreccat init.d]# 

The service can also be started using the GUI tool Service Configuration found under System | Administration | Services.

The database and listener are now configured to startup and shutdown along with the server.

6 thoughts on “Automating Database Startup/Shutdown on Oracle Enterprise Linux”

  1. I’ve previous exreniepce in DBA before reading this book. The Architecture & Administration PART was excellent and cover around 95% of the test questions, but the second part Backup & Recovery was full of errors and not useful at all and doesn’t cover more than 25% of the test questions, and only cover the titles of the test!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *