Automatically start Oracle 11g on Oracle Linux 6.2 after server reboot
Environment: Oracle database 11.2.0.3.0, Oracle Linux 6.2
Oracle 11g includes 2 scripts which can be used to start or shut down
Oracle databases on Linux. Both scripts are installed in
$ORACLE_HOME/bin and are called
dbstart and
dbshut.
However, these scripts are not executed automatically after you reboot
your server. I will explain here how you can configure that.
First, you need to make sure that any database instances you want to autostart are set to “Y” in the
/etc/oratab file. This is how mine looks like:
|
baldbsms: /u01/app/oracle/product/11 .2.0 /db_1 :Y
|
The
/etc/oratab file is normally created by running the
root.sh
script at the end of the installation. If you don’t have the file, you
can always add it to your system by creating it manually (with user
root!).
Next, we are going to create 2 scripts under /home/oracle/scripts:
ora_start.sh and
ora_stop.sh. These scripts will call
dbstart and
dbshut
and will also allow us to add some more actions, for example the start
of the Enterprise Manager database control or any other services you
might have.
$ su – oracle
$ vi /home/oracle/scripts/ora_start.sh
|
#!/bin/bash
. ~/.bash_profile
$ORACLE_HOME /bin/dbstart $ORACLE_HOME
$ORACLE_HOME /bin/emctl start dbconsole
exit 0
|
$ vi /home/oracle/scripts/ora_stop.sh
|
#!/bin/bash
. ~/.bash_profile
$ORACLE_HOME /bin/emctl stop dbconsole
$ORACLE_HOME /bin/dbshut $ORACLE_HOME
exit 0
|
You see that inside the scripts, we are calling the
.bash_profile file of the user “oracle”. This is needed to set the ORACLE_HOME environment variable.
Next, give execute rights to the scripts:
$ chmod u+x /home/oracle/scripts/ora_start.sh
$ chmod u+x /home/oracle/scripts/ora_stop.sh
You could now test these scripts to see if they correctly shut down and start up your Oracle database.
We will now create a wrapper script that can be used to schedule as a service.
With user
root, create a file called “oracle” under /etc/init.d.
$ vi /etc/init.d/oracle
|
#!/bin/bash
ORA_OWNER=oracle
RETVAL=0
case "$1" in
'start' )
su - $ORA_OWNER -c "/home/oracle/scripts/ora_start.sh"
touch /var/lock/subsys/oracle
;;
'stop' )
su - $ORA_OWNER -c "/home/oracle/scripts/ora_stop.sh"
rm -f /var/lock/subsys/oracle
;;
*)
echo $ "Usage: $0 {start|stop}"
RETVAL=1
esac
exit $RETVAL
|
$ chmod 750 /etc/init.d/oracle
To create a service of this script, run the following command:
$ chkconfig --add oracle
Next, check the script by running “
service oracle stop” or “
service oracle start” from the command line:
$ service oracle stop
Oracle Enterprise Manager 11g Database Control Release 11.2.0.3.0
Copyright (c) 1996, 2011 Oracle Corporation. All rights reserved.
Stopping Oracle Enterprise Manager 11g Database Control …
… Stopped.
Processing Database instance “oratst”: log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log
$ service oracle start
Processing Database instance “oratst”: log file /u01/app/oracle/product/11.2.0/db_1/startup.log
Oracle Enterprise Manager 11g Database Control Release 11.2.0.3.0
Copyright (c) 1996, 2011 Oracle Corporation. All rights reserved.
Starting Oracle Enterprise Manager 11g Database Control …… started.
After this, it’s time for the final test: reboot your server and
check if your Oracle database is automatically started after the reboot.
Happy Reading ..........