How to Set up Automatic Startup and Shutdown of an Oracle Database on Linux without Using Oracle-Restart
We have all set up automatic startup and shutdown of an Oracle Database on Linux at some point. I, myself, have made some scripts to do it in the past. However, did you know there is an official way/script for this?
You can accomplish this with dbstart and dbshut scripts, which are located in the $ORACLE_HOME/bin directory.
This is documented for 12.1 in Stopping and Starting Oracle Software .
Of course, if you have Oracle Clusterware configured, you can use Oracle Restart and SRVCTL tool, and Clusterware will automatically start and stop the Oracle database instances and listeners, which is much better.
This post refers to the official procedure in case you don’t have Clusterware configured.
Quick Guide:
1) You need your Database Entry in /etc/oratab:
No mysteries with that. Just follow the pattern:
2) Create file /etc/init.d/dbora:
Edit with your environment configuration:
#! /bin/sh # 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= ORA_OWNER=
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
* You may also want to add listener commands in the script. For that, fit the following in the same syntax as shown above.
$ORACLE_HOME/bin/lsnrctllistener_name
3) Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:
# chgrp dba dbora # chmod 750 dbora
4) Create symbolic links to the dbora script:
# 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
And that’s it!
Now your database and listener are restarting automatically with the server.
* Bonus!
*.1) Register this as a service:
*.2) And now you can stop/start your database as an OS service:
# service dbora start # service dbora stop
Interesting:
– Oracle 11gR2 documentation states the use of the dbstart and dbshut scripts are deprecated. It’s supposed to be replaced by Oracle Restart.
– The Oracle 12c documentation has no mention of the deprecation of dbstart and dbshut and has reinstated the documentation about them (as I linked above). So, feel free to use dbstart and dbshut in a supported manner for all versions of the database.
Important:
Also, note that this post is focused on Linux RHEL or OL, but you can also find this procedure documented for AIX and Solaris as per official Online Doc: Stopping and Starting Oracle Software.
Oracle database autostart on linux
You can start and stop the database manually, set it to automatically after the system shuts down and starts, or using Enterprise Manager.
Shutting Down and Starting Up Using SQL*Plus
You can shut down and start the database using SQL*Plus.
To shutdown the database, login to the oracle user with its environment variables set for access to the XE database, and issue the following SQL*Plus command:
$ sqlplus / as sysdba SQL> SHUTDOWN IMMEDIATE
To start the database, issue the commands:
SQL> STARTUP SQL> ALTER PLUGGABLE DATABASE ALL OPEN;
Automating Shutdown and Startup
Oracle recommends that you configure the system to automatically start Oracle Database when the system starts, and to automatically shut it down when the system shuts down. Automating database shutdown guards against incorrect database shutdown.
To automate the startup and shutdown of the listener and database, execute the following commands as root :
# systemctl daemon-reload # systemctl enable oracle-xe-21c
# systemctl daemon-reload # systemctl enable oracle-xe-21c
Shutting Down and Starting Up Using the Configuration Services Script
The XE configuration script shows an incorrect listener status message. When the database listener is stopped or down, the script might show the following listener status message :
/etc/init.d/oracle-xe-21c status Status of the Oracle XE 21c service: LISTENER status: NOT CONFIGURED XE Database status: STOPPED
This is an incorrect listener status message. It does not mean that the script in incorrectly configured.
Run the following commands as root using sudo .
Run the following command to start the listener and database:
# systemctl start oracle-xe-21c
Run the following command to stop the database and the listener:
# systemctl stop oracle-xe-21c
Run the following command to stop and start the listener and database:
# systemctl restart oracle-xe-21c
Run the following command to start the listener and database:
# systemctl start oracle-xe-21c
Run the following command to stop the database and the listener:
# systemctl stop oracle-xe-21c
Run the following command to stop and start the listener and database:
# systemctl restart oracle-xe-21c
Related Topics