In many environments, it’s desirable to have the Oracle database and listener automatically shutdown and startup when the server reboots. If you have that requirement, then follow the next several steps to automate your database and listener shutdown and startup:
Steps to configure auto startup/shutdown
1. Edit the /etc/oratab file, and place a Y at the end of the entry for the databases you want to automatically restart when the system reboots. You might need root privileges to edit the file:
# vi /etc/oratab [SID]:[ORACLE_HOME]:Y
The Y on the end of the string signifies that the database can be started and stopped by the ORACLE_HOME/bin/dbstart and ORACLE_HOME/bin/dbshut scripts.
2. Create the service script /etc/init.d/dbora. Content of the script is as follows. Make sure you change the values of variables ORA_HOME and ORA_OWNER to match your environment. This is a bare bones script of what you minimally would need to stop and start a database and listener:
# vi /etc/init.d/dbora #!/bin/bash # chkconfig: 35 99 10 # description: Starts and stops Oracle processes ORA_HOME=/oracle/app/oracle/product/11.2.0/db_1 ORA_OWNER=oracle case "$1" in 'start') su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" su - $ORA_OWNER -c $ORA_HOME/bin/dbstart ;; 'stop') su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" su - $ORA_OWNER -c $ORA_HOME/bin/dbshut ;; esac # End of script dbora
Understanding the script
The lines:
# chkconfig: 35 99 10 # description: Starts and stops Oracle database
are mandatory and not just comments since they describe the characteristics of the service where:
- 35 means that the service will be started in init levels 3 and 5 and will be stopped in other levels.
- 99 means that the service will be started at the near end of the init level processing
- 10 means that the service will be stopped at the near beginning of the init level processing
Rest of the script is pretty easy to understand. The first case starts the listener/DB whereas the 2nd case stops it. Follow the steps below to make script executable and enable to run automatically when system boots up.
Make script executable and Enable to run on boot
1. Change the group of the dbora file to match the group assigned to the operating system owner of the Oracle software (usually oinstall or dba):
# chgrp dba /etc/init.d/dbora
2. Set the script permissions to 755.
# chmod 750 /etc/init.d/dbora
3. Run the following chkconfig command:
# chkconfig --add dbora
This action registers the service to the Linux service mechanism. This also creates the appropriate symbolic links to files beneath the /etc/rc.d directory. Use the –list option to display whether a service is on or off for each runlevel:
# chkconfig --list | grep dbora dbora 0:off 1:off 2:off 3:on 4:off 5:on 6:off
This output indicates the dbora service is on for runlevels 3 and 5. If you need to delete a service, use the –del option of chkconfig.
Testing the script
1. To test whether the dbora script is working, as root run the following to stop your database and listener:
# /etc/init.d/dbora stop
2. To test the startup of your database and listener, as root issue the following command:
# /etc/init.d/dbora start
Final Thoughts
Automating the shutdown and startup of your Oracle database will vary depending on whether you’re using tools like cluster software or ASM. The solution in this section demonstrates the typical steps to implement the shutdown and startup of your database in the scenarios where you don’t have other software that manages this task.