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:ORACLE_HOME:{Y|N|W}
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.
test:/u01/app/oracle/product/11.2.0/dbhome_1:Y
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.
1
2
3
4
5
|
[[email protected] 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 [[email protected] 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
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# First argument is used to bring up Oracle Net Listener ORACLE_HOME_LISTNER=$1 if [ ! $ORACLE_HOME_LISTNER ] ; then echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener" echo "Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to # a different ORACLE_HOME for each entry in the oratab. export ORACLE_HOME=$ORACLE_HOME_LISTNER # 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 else echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr" fi fi |
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.
1
2
3
|
[[email protected] etc]$ dbstart $ORACLE_HOME Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log [[email protected] 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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/bin/sh # chkconfig: 345 99 10 # description: Service to start and stop Oracle Database and Listener # # processname: oracle # config: /etc/oratab # pidfile: /var/run/oracle.pid # Source function library. . /etc/init.d/functions RETVAL=0 ORA_OWNER="oracle" ORA_HOME="/u01/app/oracle/product/11.2.0/dbhome_1" # See how we were called. prog="oracle" start() { echo -n $"Starting $prog: " su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME" RETVAL=$? echo [ $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=$? echo [ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora return $RETVAL } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac 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.
1
2
3
4
5
|
[[email protected] ~]# chgrp dba /etc/init.d/dbora [[email protected] ~]# chmod 750 /etc/init.d/dbora [[email protected] ~]# ls -al /etc/init.d/dbora -rwxr-x--- 1 root dba 877 Sep 6 12:16 /etc/init.d/dbora [[email protected] ~]# |
While still logged in as the root user execute the dbora
script with both the start and stop arguments.
1
2
3
4
5
6
7
|
[[email protected] init.d]# ./dbora start Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log [[email protected] init.d]# ./dbora stop Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log [[email protected] 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
.
1
|
[[email protected] ~]# chkconfig --level 345 dbora on |
With the service registered starting and stopping the oracle services can be done with the service command.
1
2
3
4
5
6
7
|
[[email protected] init.d]# service dbora start Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log [[email protected] init.d]# service dbora stop Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log [[email protected] 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.