How to Set up Automatic Startup and Shutdown of an Oracle Database on Linux without Using Oracle-Restart

Posted in: Technical Track

We have all set up automatic startup and shutdown of an Oracle Database on Linux at some point. I, myself, have made some scripts to do it in the past. However, did you know there is an official way/script for this?

You can accomplish this with dbstart and dbshut scripts, which are located in the $ORACLE_HOME/bin directory.
This is documented for 12.1 in Stopping and Starting Oracle Software .

Of course, if you have Oracle Clusterware configured, you can use Oracle Restart and SRVCTL tool, and Clusterware will automatically start and stop the Oracle database instances and listeners, which is much better.
This post refers to the official procedure in case you don’t have Clusterware configured.

Quick Guide:

1) You need your Database Entry in /etc/oratab:
No mysteries with that. Just follow the pattern:

$ORACLE_SID:$ORACLE_HOME:<N|Y>

2) Create file /etc/init.d/dbora:
Edit with your environment configuration:

#! /bin/sh 
# description: Oracle auto start-stop script.
#
# Set ORACLE_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= ORA_OWNER=

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

* You may also want to add listener commands in the script. For that, fit the following in the same syntax as shown above.

$ORACLE_HOME/bin/lsnrctl {start|stop} listener_name

3) Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:

# chgrp dba dbora
# chmod 750 dbora

4) Create symbolic links to the dbora script:

# 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

And that’s it!
Now your database and listener are restarting automatically with the server.

* Bonus!
*.1) Register this as a service:

chkconfig --add dbora

*.2) And now you can stop/start your database as an OS service:

# service dbora start
# service dbora stop

Interesting:
– Oracle 11gR2 documentation states the use of the dbstart and dbshut scripts are deprecated. It’s supposed to be replaced by Oracle Restart.
– The Oracle 12c documentation has no mention of the deprecation of dbstart and dbshut and has reinstated the documentation about them (as I linked above). So, feel free to use dbstart and dbshut in a supported manner for all versions of the database.

Important:
Also, note that this post is focused on Linux RHEL or OL, but you can also find this procedure documented for AIX and Solaris as per official Online Doc: Stopping and Starting Oracle Software.

I hope this helps!

email

Interested in working with Matheus? Schedule a tech call.

About the Author

Lead Database Consultant
Well known in the Oracle community in Latin America and Europe where he participates regularly in technology events, Matheus is actually the youngest Oracle ACE Director in the world. Lead Database Consultant at Pythian, Matheus is a Computer Scientist by PUCRS and has been working as an Oracle DBA for the last 10 years.

No comments

Leave a Reply

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