AUTOMATING STARTING AND STOPPING THE DATABASE AND LISTENER ON LINUX




It is sometime desirable by most DBAs to have the oracle database and listener automatically shutdown and startup when the server reboots. The following steps shows you how to automate your database and listener shutdown and startup.

Please note that this demonstration is linux centric (I am working on OEL 6.8), so if you are working with a different Unix platform, refer to the Oracle Database Admin’s Guide.

1. Edit the /etc/oratab file, and place a Y at the end of the entry for the database you want to restart automatically when the system reboots. You will need root priv to edit the file:

2. Paste within the file a line similar to the one below, for your environment:

db11g:/u01/app/oracle/product/11.2.0/dbhome_1:Y
Note:
The entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:N|Y:

3. As root, navigate to the /etc/init.d directory, and create a file named dbora:



Paste the following lines in the dbora file. Make sure you change the values of the variables OR_HOME and OR_OWNER to match your environment.

#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and stops Oracle processes
OR_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
OR_OWNER=oracle
case "$1" in
'start')
su - $OR_OWNER -c "$OR_HOME/bin/lsnrctl start"
su - $OR_OWNER -c $OR_HOME/bin/dbstart
;;
'stop')
su - $OR_OWNER -c "$OR_HOME/bin/lsnrctl stop"
su - $OR_OWNER -c $OR_HOME/bin/dbshut
;;
esac

4. Change the group of the dbora file to match the group assigned to the OS owner of the Oracle software (usually oinstall or dba), change the permissions on the dbora file to 750:


5. Run the following chkconfig command:

# /sbin/chkconfig --add dbora

Use the --list option to display whether a service is on or off for each runlevel:


To test wether the dbora script is working, as root, run the following command to stop you database and listener:

# /etc/init.d/dbora stop

To test the startup of your database and listener, as root, issue the following command:

# /etc/init.d/dbora start

Note!!  You may need to make a slight modification to the Oracle-supplied ORACLE_HOME/bin/dbstart and ORACLE_HOME/bin/dbshut scripts. I ran the script without the modifacation and had the message below, so if u see the same message pls make this modifications in the script:


Inspect these scripts with an OS editor (such as vi), you’ll notice the following line:

ORACLE_HOME_LISTNER=$1

I would recommend that you change it to this:

ORACLE_HOME_LISTNER=${1:-$ORACLE_HOME}

This line instructs the scripts to accept a parameter if one is passed in. If a parameter is not passed in, then set ORACLE_HOME_LISTNER to the value contained in the variable $ORACLE_HOME. This preserves the functionality of dbstart and dbshut and also makes these scripts work when called from dbora

If you can reboot your system, then I recommend that you do so to ensure that the database stops and restarts correctly. The dbstart and dbshut utilities create log files in the ORACLE_HOME directory, named startup.log and shutdown.log. You can inspect the contents of these to verify that the shutdown and startup are working as expected.




Comments