# Configuring Automatic Restart of an Oracle Database
# systemd
[Unit] | |
Description=Oracle Database Start/Stop Service | |
After=syslog.target network.target local-fs.target remote-fs.target | |
[Service] | |
# systemd, by design does not honor PAM limits | |
# See: https://bugzilla.redhat.com/show_bug.cgi?id=754285 | |
LimitNOFILE=65536 | |
LimitNPROC=16384 | |
LimitSTACK=32M | |
LimitMEMLOCK=infinity | |
LimitCORE=infinity | |
LimitDATA=infinity | |
Type=simple | |
User=oracle | |
Group=oinstall | |
Restart=no | |
ExecStartPre=/bin/rm -rf /u01/app/oracle/product/12.2.0/dbhome_1/listener.log | |
ExecStartPre=/bin/rm -rf /u01/app/oracle/product/12.2.0/dbhome_1/startup.log | |
ExecStart=/bin/bash /u01/app/oracle/product/12.2.0/dbhome_1/bin/dbstart /u01/app/oracle/product/12.2.0/dbhome_1 | |
RemainAfterExit=yes | |
ExecStop=/bin/rm -rf /u01/app/oracle/product/12.2.0/dbhome_1/shutdown.log | |
ExecStop=/bin/bash /u01/app/oracle/product/12.2.0/dbhome_1/bin/dbshut /u01/app/oracle/product/12.2.0/dbhome_1 | |
TimeoutStopSec=5min | |
[Install] | |
WantedBy=multi-user.target |
# rc.d
RHEL 8.10 - Oracle 19.3.0.0
Modify the /etc/oratab file.
sed -i '/^orcl/s/N$/Y/' /etc/oratab |
Create a file called dbora in initialization file directory.
/etc/init.d/dbora
#! /bin/sh | |
# description: Oracle auto start-stop script. | |
# | |
# Set ORA_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=/u01/app/oracle/product/19.0.0/dbhome_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/dbstart $ORA_HOME" & | |
touch /var/lock/subsys/dbora | |
;; | |
'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/dbshut $ORA_HOME" & | |
rm -f /var/lock/subsys/dbora | |
;; | |
esac |
This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER, then you must specify the listener name in the stop and start commands:
$ORACLE_HOME/bin/lsnrctl {start|stop} listener_name |
Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750.
chgrp dba /etc/init.d/dbora | |
chmod 750 /etc/init.d/dbora |
Create symbolic links to the dbora script in the appropriate run-level script directories.
ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora | |
ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora | |
ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora |
Reference:
・ Stopping and Starting Oracle Software