Autostart your oracle database and listener on linux

Remco van Rijn 4

Have you ever been wondering like me why DBCA doesn’t present you with the option, whilst creating your single instance database, to have it autostarted upon system boot? I mean like, what’s the point in (re)booting your database server, and not have it autostart the database(s) and listener running on it as well? They should have never been down in the first place!

It’s an easy fix though, you just need to call the the dbstart script in your $ORACLE_HOME/bin directory whilst the system is booting, which can be done by creating a service. To do this, create the below script called /etc/init.d/oracledb, as user root:

# oracledb – little shell script to autostart your oracle database(s) and listener
# chkconfig: 2345 90 90

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network


start() {
[ “$NETWORKING” = “no” ] && exit 1
echo -n “Starting $prog: ”
daemon –user=oracle “$ORACLE_HOME/bin/dbstart $ORACLE_HOME > /dev/null 2>&1”
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL

stop() {
echo -n “Stopping $prog: ”
daemon –user=oracle “$ORACLE_HOME/bin/dbshut $ORACLE_HOME > /dev/null 2>&1”
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL

# See how we were called.
case “$1″ in
echo $”Usage: $0 {start|stop|restart}”
exit 2


Next, set the correct permissions:

chmod 755 /etc/init.d/oracledb

And finally, to make the script execute during system boot:

chkconfig –-add oracledb

The chkconfig line of the script above, although it appears to be commented out, actually serves as input to determine to which run levels, and at what stage, the script should be executed. In this case it is runlevels 2345, and start scripts are added at position 90. Kill scripts are added to level 0 (shutdown), level 1 (single user mode) and level 6 (reboot). You can easily check this by using for example the following command:

[root@cc12c ~]# find /etc -name “*oracledb*” -exec ls -l {} \; |sort
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc0.d/K90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc1.d/K90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc2.d/S90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc3.d/S90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc4.d/S90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc5.d/S90oracledb -> ../init.d/oracledb
lrwxrwxrwx 1 root root 18 Jan 13 16:09 /etc/rc.d/rc6.d/K90oracledb -> ../init.d/oracledb
-rwxr-xr-x 1 root root 885 Jan 13 16:09 /etc/rc.d/init.d/oracledb
[root@cc12c ~]#


You can now also call this service as the root user whilst your system is running, it will stop and start all databases listed in /etc/oratab, that have a Y listed for their last column:



And one more thing, in case you’re running your database(s) inside a local VM, which makes convenience far more of an issue than security, I always edit the /etc/sudoers file as well. This way, I can become the root user without having to enter a password, which would just be a waste of time otherwise:


In case you didn’t know how to configure this, become the root user, and do:

visudo –f /etc/sudoers

and add the following line to this file:

oracle    ALL=(ALL)     NOPASSWD:ALL

Now let’s just hope this will be an option in DBCA sometime soon, to be able to run some predefined script as the root user after creating your enterprise database, to have it autostart upon system boot.

4 thoughts on “Autostart your oracle database and listener on linux

  1. I’m recieving the below error .Please help

    service oracledb does not support chkconfig

Comments are closed.

Next Post

ADF performance tuning: Overview Video published on the ADF Performance Monitor

A good performance is the key to the success of a web application. Oracle ADF applications are no exception to this rule. ADF performance tuning can be time intensive, costly and quite a challenge when performance issues require developers to delve deep into the inner workings of the ADF framework. […]
Adf performance tuning
%d bloggers like this: