Introduction
Automatically starting and stopping database services during server reboots or shutdowns avoids manual intervention and keeps operations running smoothly. Oracle provides built-in scripts, dbstart and dbshut, for exactly this purpose. By wiring these into a Linux service through systemd or init.d, the database and listener come up automatically when the server boots and shut down cleanly when it powers off. This article walks through setting that up step by step.
Prerequisites
- Root user or sudo access.
Environment Used in This Guide
| Hostname | orcl.oraeasy.com |
|---|---|
| OS | OL9 |
| Database Name | ORCLDC |
| Database Version | 19.27.0 |
| Oracle Home | /u01/app/oracle/product/19.0.0/dbhome_1 |
Approach: We'll use Oracle's own scripts for auto startup (dbstart) and shutdown (dbshut), which live in $ORACLE_HOME/bin, wrapped in a small init script that systemd can manage.
Step 1: Enable Auto Start in /etc/oratab
dbstart and dbshut only act on entries in oratab flagged with a Y in the third field, so that needs updating first.
[oracle@orcl ~]$ cat /etc/oratab
#
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME::
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcldc:/u01/app/oracle/product/19.0.0/dbhome_1:Y
[oracle@orcl ~]$
Step 2: Create the dbservice Script
This script wraps dbstart, dbshut, and the listener commands into the standard start/stop/restart interface that Linux service management expects.
[root@orcl ~]# cat /etc/rc.d/init.d/dbservice
#!/bin/bash
# chkconfig: 35 99 10
# description: Starts and Stops Oracle database and Listener processes
ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1
ORA_OWNER=oracle
PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
case "$1" in
'start')
echo -n $"Starting the Oracle Database: "
su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" &
su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
;;
'stop')
echo -n $"Shutting down the Oracle Database: "
su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" &
su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
;;
'restart')
echo -n $"Shutting down the Oracle Database: "
su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" &
su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" &
sleep 5
echo -n $"Starting the Oracle Database: "
su - $ORA_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" &
su - $ORA_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" &
;;
*)
echo "usage: $0 {start|stop|restart}"
exit
;;
esac
# End of script dbservice
[root@orcl ~]#
Step 3: Set Permissions on the Script
The script needs to be readable and executable by the oinstall group so the oracle user's session can run it as part of service start and stop.
[root@orcl ~]# id oracle
uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba),54323(oper),54324(backupdba),54325(dgdba),54326(kmdba),54330(racdba)
[root@orcl ~]#
[root@orcl ~]# chgrp oinstall /etc/init.d/dbservice
[root@orcl ~]#
[root@orcl ~]# chmod 750 /etc/init.d/dbservice
Step 4: Register the Script with the Service Management System
chkconfig registers dbservice as a SysV service and creates the runlevel symlinks that trigger it automatically on boot and shutdown.
[root@orcl ~]# chkconfig --add dbservice
[root@orcl ~]#
[root@orcl ~]# cd /etc/rc.d
[root@orcl rc.d]#
[root@orcl rc.d]# ls
init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local
[root@orcl rc.d]#
[root@orcl rc.d]# cd rc3.d/
[root@orcl rc3.d]#
[root@orcl rc3.d]# ls -lrth
total 0
lrwxrwxrwx. 1 root root 19 Jul 15 22:21 S99dbservice -> ../init.d/dbservice
[root@orcl rc3.d]#
[root@orcl rc3.d]# chkconfig --list | grep dbservice
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
dbservice 0:off 1:off 2:off 3:on 4:off 5:on 6:off
[root@orcl rc3.d]#
Step 5: Enable the Service
Since dbservice is a legacy SysV script rather than a native systemd unit, systemd wraps it through systemd-sysv-install when enabled.
[root@orcl rc3.d]# systemctl status dbservice
Unit dbservice.service could not be found.
[root@orcl rc3.d]#
[root@orcl rc3.d]# systemctl enable dbservice
dbservice.service is not a native service, redirecting to systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable dbservice
[root@orcl rc3.d]#
[root@orcl rc3.d]# systemctl status dbservice
○ dbservice.service - SYSV: Starts and Stops Oracle database and Listener processes
Loaded: loaded (/etc/rc.d/init.d/dbservice; generated)
Active: inactive (dead)
Docs: man:systemd-sysv-generator(8)
[root@orcl rc3.d]#
Step 6: Ensure SELinux Is Permissive
An enforcing SELinux policy can silently block the su commands inside the script from starting Oracle processes, so setting it to permissive avoids that failure mode.
[root@orcl ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
# See also:
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/using_selinux/changing-selinux-states-and-modes_using-selinux#changing-selinux-modes-at-boot-time_changing-selinux-states-and-modes
#
# NOTE: Up to RHEL 8 release included, SELINUX=disabled would also
# fully disable SELinux during boot. If you need a system with SELinux
# fully disabled instead of SELinux running with no policy loaded, you
# need to pass selinux=0 to the kernel command line. You can use grubby
# to persistently set the bootloader to boot with selinux=0:
#
# grubby --update-kernel ALL --args selinux=0
#
# To revert back to SELinux enabled:
#
# grubby --update-kernel ALL --remove-args selinux
#
SELINUX=permissive
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@orcl ~]#
Step 7: Restart the Server and Verify
A full reboot is the real test: if dbservice is wired up correctly, the database instance, listener, and PDB should all come up on their own with no manual intervention.
[root@orcl ~]# init 6
[root@orcl ~]#
Remote side unexpectedly closed network connection
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Session stopped
- Press to exit tab
- Press R to restart session
- Press S to save terminal output to file
┌──────────────────────────────────────────────────────────────────────┐
│ • MobaXterm Personal Edition v23.2 • │
│ (SSH client, X server and network tools) │
│ │
│ ⮞ SSH session to oracle@192.168.101.13 │
│ • Direct SSH : ✓ │
│ • SSH compression : ✓ │
│ • SSH-browser : ✓ │
│ • X11-forwarding : ✓ (remote display is forwarded through SSH) │
│ │
│ ⮞ For more info, ctrl+click on help or visit our website. │
└──────────────────────────────────────────────────────────────────────┘
Last login: Tue Jul 15 22:34:57 2025
[oracle@orcl ~]$ ps -ef|grep pmon
oracle 4420 1 0 22:35 ? 00:00:00 ora_pmon_orcldc
oracle 5097 5029 0 22:40 pts/0 00:00:00 grep --color=auto pmon
[oracle@orcl ~]$
[oracle@orcl ~]$ ps -ef|grep pmon
oracle 4420 1 0 22:35 ? 00:00:00 ora_pmon_orcldc
oracle 5129 5029 0 22:50 pts/0 00:00:00 grep --color=auto pmon
[oracle@orcl ~]$ ps -ef|grep tns
root 6 2 0 22:34 ? 00:00:00 [netns]
oracle 2492 1 0 22:35 ? 00:00:00 /u01/app/oracle/product/19.0.0/dbhome_1/bin/tnslsnr LISTENER -inherit
oracle 5131 5029 0 22:50 pts/0 00:00:00 grep --color=auto tns
[oracle@orcl ~]$
[oracle@orcl ~]$ sqlplus / as sysdba
SQL*Plus: Release 19.0.0.0.0 - Production on Tue Jul 15 22:50:43 2025
Version 19.27.0.0.0
Copyright (c) 1982, 2024, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.27.0.0.0
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB READ WRITE NO
SQL>
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.27.0.0.0
[oracle@orcl ~]$
[oracle@orcl ~]$
[oracle@orcl ~]$ lsnrctl status
LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 15-JUL-2025 22:50:53
Copyright (c) 1991, 2025, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=orcl.oraeasy.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 - Production
Start Date 15-JUL-2025 22:35:06
Uptime 0 days 0 hr. 15 min. 48 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/orcl/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=orcl.oraeasy.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Services Summary...
Service "2c3d6bacf692345be0633350a8c050ed" has 1 instance(s).
Instance "orcldc", status READY, has 1 handler(s) for this service...
Service "ORCLDC" has 1 instance(s).
Instance "orcldc", status READY, has 1 handler(s) for this service...
Service "orcldcXDB" has 1 instance(s).
Instance "orcldc", status READY, has 1 handler(s) for this service...
Service "orclpdb" has 1 instance(s).
Instance "orcldc", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@orcl ~]$
[oracle@orcl ~]$
After the reboot, the pmon process, listener, and pluggable database are all up without any manual startup, confirming the dbservice script is correctly wired into the boot sequence.
Thank you for reading!
I hope this content has been helpful to you. Your feedback and suggestions are always welcome. Feel free to leave a comment or reach out with any queries.
Abhishek Shrivastava
Oracle DBA with hands-on experience managing production Data Guard, RAC, GoldenGate, and APEX environments. I write practical, tested installation and troubleshooting guides based on real deployment work.

I checked out for auto start and stop on many sources,
ReplyDeleteBut it wasn't working
I found step 6 - set to permissive in /etc/selinux/config here and now It is working fine
Thanks Abhishek sir
Thanks Yash
DeleteI checked out many scripts for auto start stop , but non worked,
ReplyDeleteI found 6th step here and that helped me setup auto start stop on db