How to setup Oracle Database to auto start at system reboot in Linux

Oracle Database

Oracle database is a relational database management system. It is also called OracleDB, or simply Oracle. It is produced and marketed by Oracle Corporation.

The system is built around a relational database framework in which data objects may be directly accessed by users (or an application front end) through structured query language (SQL). Oracle is a fully scalable relational database architecture and is often used by global enterprises which manage and process data across wide and local area networks. The Oracle database has its own network component to allow communications across networks.

Oracle DB is also known as Oracle RDBMS and, sometimes, simply as Oracle.

We have seen the Oracle Database installation in Linux in our last blog. The concern is that if we reboot our server then the Oracle Database service will not start automatically. We need to start it manually. So in this blog, we will learn how can we automate it so that whenever the server reboots Oracle Database service will auto-start. This method will work on Amazon Linux 2, RHEL/Centos 7,8 and Ubuntu (Linux OS which supports systemd).

To do this we will configure oracle database as systemd service. Let’s start configuration:

If you know oracle database home directory then it is good otherwise login with oracle user and check oracle database home directory.

su - oracle
echo $ORACLE_HOME

As we can see, in my case it is /opt/app/oracle/dbhome

Go to /usr/lib/systemd/system directory.

cd /usr/lib/systemd/system

Create one oracle.service file and give the entry as given below:-

vi oracle.service

[Unit]
Description=Oracle Database Service
After=network.target

[Service]
Type=simple
RemainAfterExit=yes
User=oracle
Group=dba

Environment="ORACLE_HOME=/opt/app/oracle/dbhome"
ExecStart=/opt/app/oracle/dbhome/bin/dbstart $ORACLE_HOME >> 2>&1 &
ExecStop=/opt/app/oracle/dbhome/dbshut $ORACLE_HOME 2>&1 &

TimeoutSec=120

[Install]
WantedBy=multi-user.target

Note: Replace /opt/app/oracle/dbhome with your oracle database home directory.

Run the below command to apply these changes.

systemctl daemon-reload

Now we can start, stop and enable oracle.service with systemd comman

To start oracle database service use below command:-

systemctl start oracle.service

To check the service status, use the below command:-

systemctl status oracle.service

To start oracle database service at server startup time, we need to enable the service. So that if our server will reboot/restart then oracle database service will start automatically. We can enable it using the below command:-

systemctl enable oracle.service

If you are configuring this on a non-production server then you can reboot the server and verify the service status after reboot.
To get more clarification, login to the database and run some commands to verify the database status.

That’s all in this blog. Thank you !!

2 thoughts on “How to setup Oracle Database to auto start at system reboot in Linux”

Leave a Comment

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