Skip to content
Home » Oracle » How Oracle Auto Start Database in Linux

How Oracle Auto Start Database in Linux

For Solaris OS, you should check this post: How to Auto Start Oracle Database on Solaris.

Assuming that you already have some knowledge about how to start Oracle database manually and Oracle provided shell script dbstart, then we can keep going to design and deploy our automatic startup scripts.

By default, Oracle software installation does not deploy automatic startup and shutdown init scripts on the platform, you have to create them by yourself. Here I introduce my scripts for you to use or modify with.

oratab in Linux

Please turn on the startup option by changing "N" to "Y" at the last character of the line.

[oracle@test ~]$ vi /etc/oratab
ORCL:/u01/app/oracle/product/11.2.0/dbhome_1:Y

As for the format of oratab, allow me to interpret this line as followings:

"Hello, my name is ORCL ($ORACLE_SID). I live at /u01/app/oracle/product/11.2.0/dbhome_1 ($ORACLE_HOME). You can find my SPFILE or PFILE in the default location. My answer is Y if you were asking me whether startup is required."

Creating an init script for Oracle service

[oracle@test ~]$ su -
Password:
[root@test ~]# cd /etc/init.d
[root@test init.d]# vi dbora
#!/bin/sh
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_OWNER=oracle

case "$1" in
'start') # Start the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
;;
'stop') # Stop the Oracle databases and listeners
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME"
;;
esac

Also, the listener will be started or shutdown automatically at their running levels respectively.

Adding this init script to rc0, rc3 and rc5

We use 3 soft links to add them into different running levels and prioritize the execution orders by naming the file.

[root@test init.d]# chgrp dba dbora
[root@test init.d]# chmod 750 dbora
[root@test init.d]# ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
[root@test init.d]# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
[root@test init.d]# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora

Testing the script

Restart the whole server

[root@test init.d]# init 6

Then check the instance status

[oracle@test ~]$ ps -ef | grep smon | grep -v grep
oracle    3991     1  0 19:20 ?        00:00:00 ora_smon_ORCL
[oracle@test ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu May 24 19:21:39 2018

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select name, open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
ORCL      READ WRITE

Check the listener status

[oracle@test ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 24-MAY-2018 19:22:05

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                24-MAY-2018 19:19:58
Uptime                    0 days 0 hr. 2 min. 7 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/test/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test)(PORT=1521)))
Services Summary...
Service "ORCL" has 1 instance(s).
  Instance "ORCL", status READY, has 1 handler(s) for this service...
Service "ORCLXDB" has 1 instance(s).
  Instance "ORCL", status READY, has 1 handler(s) for this service...
The command completed successfully

Now the shell script will auto start Oracle database when the server boots.

For RAC databases, we can also set automatically startup for RAC cluster databases on system boot.

4 thoughts on “How Oracle Auto Start Database in Linux”

    1. OK, if you have additional listeners, say LISTENER2, you can add the following line in the start block of code.

      su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start listener2"

Leave a Reply

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