How to auto startup shutdown Oracle Database on Linux

   

1. Login as oracle, Identified Oracle Home

env | grep ORACLE_HOME

The results

ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1

2. Login as root

su - 

Change Directory to /usr/lib/systemd/system

cd /usr/lib/systemd/system

Create file oracle.service

vi oracle.service

Create This Script


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

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

Environment="ORACLE_HOME=/u01/app/oracle/product/12.1.0/dbhome_1"
ExecStart=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbstart $ORACLE_HOME >> 2>&1 &
ExecStop=/u01/app/oracle/product/12.1.0/dbhome_1/bin/dbshut $ORACLE_HOME 2>&1 &

TimeoutSec=120

[Install]
WantedBy=multi-user.target

3. UPDATE /etc/oratab


vi /etc/oratab

The result


orcl:/u01/app/oracle/product/12.1.0/dbhome_1:N

Change From N to Y


orcl:/u01/app/oracle/product/12.1.0/dbhome_1:Y

4. Enable the service and test


systemctl enable oracle.service

and then reload daemon


systemctl daemon-reload

Grep Smon


ps -ef | grep smon

Start Oracle Service


systemctl start oracle.service

Check Status Oracle Service


systemctl status oracle.service

Grep smon


ps -ef | grep smon

Restart server


init 6

Login as user oracle

Check Smon


ps -ef | grep smon

The result is


oracle    1717     1  0 09:06 ?        00:00:00 ora_smon_orcl
root      7517  6931  0 10:02 pts/1    00:00:00 grep --color=auto smon

Login sqlplus


sqlplus / as sysdba

Verify the database status by running :


SELECT status FROM v$instance;

The result is


SQL> SELECT status FROM v$instance;

STATUS
------------
OPEN

SQL>

The status should be OPEN if the database has started successfully.