Dinesh Chandra Choubey
4 min readMay 12, 2021

Scripts for Oracle DB auto startup after Server Reboot for RHEL 5/6 and 7

In RHEL/Centos 5/6 version , to managing and starting the processes at boot, we have to create a script in /etc/init.d and enable it with the help of chkconfig but in RHEL/Centos 7 it replaced by systemd, which have more advantages like its capable to launching services in parallel and for multiple core CPU machine can be leverages this feature, also we get Faster booting time, by deferring service startup until they are actually needed through systemd, its offer systemctl command to make sysadmin life easier as its provide more detailed logs about service startup including warning and errors.

So here I will show you, how we can configure Oracle DB auto startup once server rebooted in RHEL 5/6 & RHEL 7.

In RHEL 7

Steps to create oracle DB auto startup service after reboot of server for oracle 10g/11g/12c on RHEL 7/Centos 7

We have to follow below steps:-

First we have to change in /etc/oratab file

For each database for which we want to automate shutdown and startup, we have to change the ’N’ to ‘Y’ in /etc/oratab

<DBName1>:/data/oracle/product/<version>/db_1:Y

<DBName2>:/data/oracle/product/<version>/db_1:Y

2. Then we have to do below changes in dbshut & dbstart files on following location in case we are not using default listener name so we have to mention the listener_name which we are using

File Location:- /data/oracle/product/<version>/db_1/bin/

Changes:-

Searchlsnrctl startstring you will get below line in dbstart file.

$ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &

And then we can replace above line with below line

$ORACLE_HOME_LISTNER/bin/lsnrctl start listener_name>> $LOG 2>&1 &

Same way we have to change on dbshut script

Searchlsnrctl stopstring you will get below line in dbshut file.

$ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 &

And then we can replace above line with below line

$ORACLE_HOME_LISTNER/bin/lsnrctl stop listener_name>> $LOG 2>&1 &

3. Create service script at below path and then enable it

Path:- /usr/lib/systemd/system/

$ vim /usr/lib/systemd/system/oracledb.service

[Unit]

Description=The Oracle Database Service

After=syslog.target network.target

[Service]

Type=oneshot

RemainAfterExit=yes

User=oracle

Group=oinstall

Restart=no

ExecStart=/usr/bin/echo ‘Starting Oracle Databases with Y in /etc/oratab’

ExecStart=/data/oracle/product/<version>/db_1/bin/dbstart /data/oracle/product/<version>/db_1

ExecStart=/usr/bin/echo ‘dbstart has completed’

ExecStop=/usr/bin/echo ‘Stopping Oracle Databases’

ExecStop=/data/oracle/product/<version>/db_1/bin/dbshut /data/oracle/product/<version>/db_1

ExecStop=/usr/bin/echo ‘dbshut has completed’

[Install]

WantedBy=multi-user.target

Save the file.

4.

Now we have to reload systemd manager via below command, convert configuration files that are not native unit files dynamically into native unit files.

$ systemctl daemon-reload

Now we have to execute below command to enable the service at boot.

$ systemctl enable oracledb

Now we can start / stop the oracle service via below commands.

$ systemctl start oracledb

$ systemctl stop oracledb

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

In RHEL 5/6

RHEL 5 & 6 (Automatic startup of oracle DB service after server reboot)

First we have to change in /etc/oratab file

$ cat /etc/oratab

<DBName1>:/data/oracle/product/<version>/db_1:Y

<DBName2>:/data/oracle/product/<version>/db_1:Y

Then we have to do below changes in dbshut & dbstart files on following location as we are not using default listener name so we have to mention the listener_name.

File Location:- /data/oracle/product/<version>/db_1/bin/

Changes:-

Searchlsnrctl startstring you will get below line in dbstart file.

$ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &

And then we can replace above line with below line

$ORACLE_HOME_LISTNER/bin/lsnrctl start LSNR_11g>> $LOG 2>&1 &

Same way we have to change on dbshut script

Searchlsnrctl stopstring you will get below line in dbshut file.

$ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 &

And then we can replace above line with below line

$ORACLE_HOME_LISTNER/bin/lsnrctl stop LSNR_11g>> $LOG 2>&1 &

Create service script at below path and then add in chkconfig

$ vim /etc/init.d/oracledb

#! /bin/sh

# chkconfig: 345 99 10

# description: Oracle auto start-stop script.

#

# Set ORACLE_HOME to be equivalent to the $ORACLE_HOME

# from which you wish to execute dbstart and dbshut;

#

# Set ORA_OWNER to the user id of the owner of the

# Oracle database in ORACLE_HOME.

ORA_HOME=/data/oracle/product/<version>/db_1

ORA_OWNER=oracle

case “$1” in

‘start’)

# Start the Oracle databases:

# The following command assumes that the oracle login

# will not prompt the user for any values

# Remove “&” if you don’t want startup as a background process.

####su — $ORA_OWNER -c “$ORA_HOME/bin/lsnrctl start lsnr_10g” &

su — $ORA_OWNER -c “$ORA_HOME/bin/dbstart $ORA_HOME” &

touch /var/lock/subsys/oracledb

;;

‘stop’)

# Stop the Oracle databases:

# The following command assumes that the oracle login

# will not prompt the user for any values

####su — $ORA_OWNER -c “$ORA_HOME/bin/lsnrctl stop lsnr_10g” &

su — $ORA_OWNER -c “$ORA_HOME/bin/dbshut $ORA_HOME” &

rm -f /var/lock/subsys/oracledb

;;

*)

echo “usage: $0 {start|stop|restart}”

exit

;;

esac

exit

$ chgrp dba /etc/init.d/oracledb

$ chmod dba /etc/init.d/oracledb

$ ln -s /etc/init.d/oracledb /etc/rc.d/rc0.d/K01oracledb

$ ln -s /etc/init.d/oracledb /etc/rc.d/rc3.d/S99oracledb

$ ln -s /etc/init.d/oracledb /etc/rc.d/rc5.d/S99oracledb

$ chkconfig — add oracledb

$ chkconfig oracledb on

$ chkconfig — list | grep oracledb #####To check if oracledb service is on with runlevel 0, 3 & 5

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Dinesh Chandra Choubey
Dinesh Chandra Choubey

Written by Dinesh Chandra Choubey

Open Source Enthusiast, Working as Database Administrator. MySQL, MongoDB, Cassandra, Linux, AWS. Passionate to know about new technologies.

No responses yet

Write a response