Kamran Agayev's Oracle Blog

Oracle Certified Master

Automatically StartUp and Shutdown an Oracle Database in Linux OS

Posted by Kamran Agayev A. on December 22nd, 2008

Today I want to show you how we can Start-up and Shutdown an Oracle database on Linux OS automatically
In Windows, when we install an Oracle database, it creates a Windows Service which starts the database automatically as soon as OS starts. But in Linux, it’s different. You need to create your own service to start and shutdown your database when you start and shutdown your OS respectively. Now we’ll go through this example step by step to show how we can do it

1. First of all we’ve to change our /etc/oratab file. Why do we use it? Oratab file is used by Oracle utilities. It’s created by root.sh script, when we install an Oracle Server, and is updated each time by DBCA (Database Configuration Assistant) when we create a new database. After having installed a new database (in this case, our database name is mydb), entering by root user, let us see the source of this file. At the end of this file, you’ll find:


The first field is the name of my database (mydb), the second one is my home directory (/home/oracle/product/10.1.0/Db_1), and the third indicates to the dbstart utility whether the database should, or should not be brough up at the system boot time with “Y” or “N” parameters respectively
As a root user, we’ll change last field of this line from “N” to “Y” to let dbstart utility start this database when it runs

2. In this step, we’ll create a file with name startdb and write a small script to be run when our system starts or shuts down. If you want this file to be added as a service which starts when your OS boots, you should put it in /etc/init.d/ directory. In this script, we’ll define two variables, ORA_OWNER and ORACLE_HOME and then, we’ll start (or shutdown) our database by connecting with oracle user and running lsnrctl (Listener utility), dbstart (utility which starts the database) and dbshut (utility which shutdowns the database) utilities depending on our OS state.
This is the source of our startdb file:


case “$1” in
 ‘start’)  #If the system is starting, then …
su – $ORA_OWNER -c “$ORACLE_HOME/bin/lsnrctl start” #Start the listener
su – $ORA_OWNER -c “$ORACLE_HOME/bin/dbstart #Start the database

‘stop’)   #If the system is stops, that is we’re shutting down our OS, then …
  su -$ORA_OWNER -c $ORACLE_HOME/bin/dbshut
  su -$ORA_OWNER -c “$ORACLE_HOME/bin/lsnrctl stop”

3. Once you’ve saved your file into this directory, make sure that it’s executable by running:
chmod 750  startdb

4. Then you need to add the appropriate symbolic links to cause the script to be executed when the system goes down, or comes up. Create it with ln -s command.

# ln -s /etc/init.d/startdb /etc/rc.d/rc3.d/K01startdb
# ln -s /etc/init.d/startdb /etc/rc.d/rc3.d/S99startdb
# ln -s /etc/init.d/startdb /etc/rc.d/rc5.d/K01startdb
# ln -s /etc/init.d/startdb /etc/rc.d/rc5.d/S99startdb

Let’s analyze these commands:
The first line creates symbolic link of our script in rc3.d directory. At startup, Linux runs /etc/rc.d/rc script at the current level (normally 3 or 5). rc3.d indicates 3rd runlevel, “K” indicates OS’s shutdown (on servers shutdown, Linux calls the scripts in /etc/rc.d/rc3/K* in order)
The second line creates another symbolic link of our script, to be run at startup of our OS, indicating “S99” and the name of our script
Another two lines creates symoblic links for 5th runlevel.

That’s all. Your script and your service is ready for use. Just restart your OS and upon startup you’ll see your newly created service running. Then open new terminal, enter you database and issue :
SQL>SELECT status FROM v$instance;

You’ll see your database’s status is OPEN

In some releases, even when we create a new service, it doesn’t work. When we issue dbstart command manually from OS, we’re getting an error:
cat: /var/opt/oracle/oratab: No such file or directory

It has simple reason and solution
If the directory /var/opt/oracle exists during the Oracle installation the dbhome script will have the parameter ORATAB set to “/var/opt/oracle/oratab” instead of “/etc/oratab”. The normal DBCA process during a default installation will still add the instance entry to /etc/oratab.

It has two solutions:
1. You can either copy the original oratab file to this directory :
cp /etc/oratab /var/opt/oracle/

2. Or you can edit dbstart and dbshut scripts, find the variable ORATAB, and you’ll find that it’s addressing to  /var/opt/oracle/oratab file. Just change it to /etc/oratab

40 Responses to “Automatically StartUp and Shutdown an Oracle Database in Linux OS”

  1. AJA Says:

    Would it not be tons easier to install the orarun RPM? This will create a file /etc/init.d/oracle and etc/sysconfig/oracle We use the sysconfig file to tell the init.d file which oracle products/services to start and how we want the kernel parameters set. I have found it most simple and reliable.

  2. Kamran Agayev A. Says:

    You’re right AJA. It would be easier than doing all these steps. But I want to show how we can do it step by step by ourselfs and to show a little bit from Linux startup and shutdown process

  3. david Says:


    I tried the above steps for Automatic StartUp and Shutdown an Oracle Database in my Linux OS and my database has refused to start since then.
    It displays the message below:

    ORA-00600: internal error code, arguments: [ keltnfy-ldmInit],[46],[1],[],[],[],[],[]

    please how do I recover my database

  4. Kamran Agayev A. Says:

    Hi David
    Please for your Urgent questions, open an SR in metalink (contact Oracle Support)
    Or you can post a question in Oracle Forums

    For ORA-00600 errors (internal errors) you should open contact Oracle Support. There’s no any written documentation for such errors

  5. david Says:

    For the benefit of others. Below is the solution I found most valuable on yahoo search engine:

    ORA-00600 arguments: [keltnfy-ldmInit], [46], [1]
    Problem Description
    In oracle while creating database with dbca it fails with message below.
    ORA-00600: internal error code, arguments: [keltnfy-ldmInit], [46], [1], [], [], [], [], []

    If you try to create your database manually then also the command startup nomount fails with above error message.

    Cause of the Problem
    In the error ldmInit indicates that the problem is related while getting host information of oracle during startup. The first argument 46 indicates the exception LDMERR_HOST_NOT_FOUND which is “gethostbyname system call fails”. Oracle was unable to get host information from OS and bug fires.

    Solution of the Problem
    Step 01: Check permission on /etc/hosts

    $ ls -l /etc/hosts-rw-r–r– 1 root root 153 Nov 24 2007 /etc/hosts

    Note that you need read permission of all users.

    Step 02: Check the contents of /etc/hosts
    Open the contents of /etc/hosts and check the contents inside it.
    $ less /etc/hosts
    Note that the contents of this files follow following format.

    IP Address fully qualified hostname simple or short hostname Alias

    A simple example,

    $ cat /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail. database localhost.localdomain localhost

    Step 03: Check the hostname and make sure you can ping your hostname.
    $ hostname

    $ ping database
    PING database ( 56(84) bytes of data.
    64 bytes from database ( icmp_seq=0 ttl=64 time=0.057 ms
    64 bytes from database ( icmp_seq=1 ttl=64 time=0.050 ms
    64 bytes from database ( icmp_seq=2 ttl=64 time=0.041 ms

    If you get the following message,
    $ ping database
    ping: unknown host database

    then possibly you will hit above bug.
    And you need to modify /etc/hosts files. In the alias section you can give the name of your machine name. If your machine name is “database” you can give /etc/hosts entry as, database localhost.localdomain localhost

    And then ping database again. Make sure you are able to ping your host.

    Step 04: Diagnosis DNS problem if you have DNS setup
    If you have DNS setup, ping is not a tool to diagnose DNS problem. A better tool to use is nslookup, dnsquery, or dig.

    $nslookup http://www.google.com
    The forward and reverse lookup should succeed.

    Step 05: Check nsswitch.conf

    $ cat /etc/nsswitch.confhosts: files dns

    Make sure host lookup is also done through the /etc/hosts file and not just dns. The keyword files should come before dns.

    Step 06: Check resolv.conf

    $ cat /etc/resolv.confnameserver

  6. rohit Says:

    i tried all steps mentioned by u bt it did not work
    i was found again the same error
    plz tell me the best solution for this problem
    its very urgent

    thank u

  7. Kamran Agayev A. Says:

    Hi Rohit

    The best solution is not to “Copy/paste” the script because there may be problem with commas and so on. So, just try to write down a script without copying it from web browser to your system

  8. Mu Savvy Says:

    Excellent job! Ordering the book now.

  9. Victor Says:

    Dear Kamran:

    I want to use the auto startup/shutdown process for my 11gR2 install on OEL. This worked fine on CentOS, but on OEL with 11g I get the following message when starting Enterprise Manager:

    [oracle@localhost ~]$ emctl start dbconsole
    OC4J Configuration issue. /u01/home/oracle/product/11.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_localhost.localdomain_vv not found.

    Are there any changes or additional steps I need to do?


  10. Kamran Agayev A. Says:

    Are you able to start the EM from outside the script? If not, then try to delete and create the EM repository again

  11. Victor Says:

    Was only able to run EM upon initial startup of newly created database, after restarting OEL next day, couldn’t get EM to work.

    Are these the correct commands to delete & recreate EM repo?

    $ emca -deconfig dbcontrol db -repos drop

    $ emca -config dbcontrol db -repos create

  12. Victor Says:

    This worked:
    $ emca -deconfig dbcontrol db -repos drop
    $ emca -config dbcontrol db -repos recreate (& not create)

    When prompted for SYSMAN user, need to enter password in quotes “password” or you will continue to get invalid user/password prompt.

    also need to use the database control url given at the end of the enterprise manager configuration completed successfully message.

  13. tanveer Says:

    Where can I download orarun rpm?
    I tried to find that on internet but not find yet :(

  14. Kamran Agayev A. Says:

    Dear Tanveer

    You shouldn’t download any rpm to automate the startup and shutdown of the Oracle database. Just follow my steps and you will succeeed

  15. Kamran Agayev A. Says:

    Dear Tanveer

    You shouldn’t download any rpm to automate the startup and shutdown of the Oracle database. Just follow my steps and you will succeeed

  16. tanveer Says:

    Dear Kamran,
    I have installed oracle10R2 on CentOs 5.6 and followed your steps to automate but it is not working :(

  17. Kamran Agayev A. Says:

    Dear Tanverr, just change the commas after copy/pasting the code and verify why it is not working. The code is correct

  18. tanveer Says:

    where sould I place commas ?


    case “$1″ in
    ’start’) #If the system is starting, then …
    su – $ORA_OWNER -c “$ORACLE_HOME/bin/lsnrctl start” #Start the listener
    su – $ORA_OWNER -c “$ORACLE_HOME/bin/dbstart #Start the database

    ‘stop’) #If the system is stops, that is we’re shutting down our OS, then …
    su -$ORA_OWNER -c $ORACLE_HOME/bin/dbshut
    su -$ORA_OWNER -c “$ORACLE_HOME/bin/lsnrctl stop”

  19. erwin amin Says:

    Hello Kamran
    I got “Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr”, when I start the script, “/etc/init.d/stardb start”
    but the oracle start successfully.

    To resolve this problem I got the answer from http://www.riccardoriva.com/archives/168.

    Anyway, your article is very helpful.

    thank you

  20. vijay Says:

    hi kamran ,

    can you please mention the content & path of the listener.ora and tnsname.ora file

    thanks in advance

  21. Kamran Agayev A. Says:

    Hi Vijar
    The path of the network configuration files is $ORACLE_HOME/network/admin folder

  22. sameer Says:

    Dear All,

    Thanks for this excellent tutorial and my issues is .

    after installation and preparing all requirement and open database control after that i shutdown my VMware and back again to open it but it’s not open and inform me it can’t make establish a connection to the server localhost:1158 .

    and for SQL i can connect and do any active ,,,, please provide me solution for this problem

    please ASAP


  23. Kamran Agayev A. Says:

    Make sure you’ve set ORACLE_SID environment variable correctly and then start the listener and EM

  24. gagan Says:

    hi kamran,
    i am trying to upgrate my database from 10g to 11g .also my existing database has asm storage type.i want to convert it into non asm(file system).
    my first concern is to install 11g in new oracle home.
    then i need to take backup of database and import it into 11g.
    is it possible i take backup as asm and while importing i can covert into filesystem.
    should i go for rman or datapump.

    or can you recommend any steps for that.

  25. Kamran Agayev A. Says:

    Hi Gagan
    Check the following documentation :

  26. Murthy Says:

    hi, kamran,

    can we use oracle enterprise manager(OEM) to start the oracle database automatically. there is option like manual and automatic. please clear me.

  27. Kamran Agayev A. Says:

    In order to start the database automatically in *nix OS, you *have* you create a script and it can’t be done via EM

  28. gagan Says:

    hi i am trying to compile saaadms.fmb form but generating error

    frmcmp_batch module=/u01/app/sghe/inb/PPRD/forms/fmb/saaadms.fmb
    baninst1/********** module_type=form
    output_file=/u01/app/sghe/inb/PPRD/forms/fmx/SAAADMS.fmx compile_all=yes

    ksh: frmcmp_batch: not found

    i just need to compile the from and generate new fmx file how could i do that. one of my oracle form is not running.


  29. Kamran Agayev A. Says:

    Please post your question under the following topic:

  30. gagan Says:

    am trying to run the scrip but it throws me java error

    OMB*Plus: Release
    Copyright (c) 2000, 2011, Oracle. All rights reserved.
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:592)
    at Launcher.main(Launcher.java:175)
    Caused by: tcl.lang.TclRuntimeError: Unexpected TclException while executing custom application initialization: tcl.lang.TclException
    at tcl.lang.TclShell.run(TclShell.java:124)
    at tcl.lang.TclShell.run(TclShell.java:72)
    at oracle.owb.scripting.OMBShell.main(OMBShell.java:30)
    … 5 more


  31. gagan Says:

    we are doing upgradation of 10g db to 11g and i have already cloned the 10g db to 11g using full datapump and since then we are working on 11g for additional application software .

    now we need to studown 10g db and make 11g db in use. so i just need to refresh the 11g db with the changes we made to existing db sinse last time i cloned the db.

    is full datapump is gonna work as it will drop everything and overrites it but we have created new tables and tablespaces for applications on 11g db ,so this will drop them too.

    what is the effecting method to refresh the database.



  32. Kamran Agayev A. Says:

    What is the size of the database?
    Do you have an option for the downtime?

    If the size is not so big and you can stop the database for a while, stop it, open in readonly mode, export all data, import to the new database and use it
    If you don’t have downtime option, then you have to use either Standby database or Replication migration

  33. MESLI Abdelhadi Says:

    Hi Kamran;

    i do the same thing like you but he did not work for me can you please give me any suggestion ?

    os version= centos 5
    database version oracle 11.2.0

    Thank you in advance..

  34. MESLI Abdelhadi Says:

    I forget to tell you that when I executed:
    [oracle@localhost bin]$ dbstart the output was
    ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
    Usage: /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME
    Processing Database instance “orcl”: log file /home/oracle/app/oracle/product/11.2.0/dbhome_1/startup.log

    the same result with
    [root@localhost bin]# dbstart the output was the same
    ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
    Usage: /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME
    Processing Database instance “orcl”: log file /home/oracle/app/oracle/product/11.2.0/dbhome_1/startup.log


  35. Kamran Agayev A. Says:

    Have you set ORACLE_HOME_LISTNER parameter?

  36. MESLI Abdelhadi Says:

    Hi Mr Kamran,

    I posted yesterday two messages about automating startup of database and I see now that are deleted!! where is the problem ?


  37. Kamran Agayev A. Says:

    They were waiting to be approved

  38. MESLI Abdelhadi Says:

    Thank you Mr kamran for reply,

    Yes in my dbstart script($ORACLE_HOME/bin/dbstart) I have that

    # First argument is used to bring up Oracle Net Listener
    and when i execute this

    [oracle@localhost ~]$ vi $ORACLE_HOME/bin/dbstart
    [oracle@localhost ~]$ dbstart
    /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart: line 94: /home/oracle/app/oracle/product/11.2.0/dbhome_1/listener.log: Permission non accordée
    /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart: line 95: /home/oracle/app/oracle/product/11.2.0/dbhome_1/listener.log: Permission non accordée
    Processing Database instance “orcl”: log file /home/oracle/app/oracle/product/11.2.0/dbhome_1/startup.lo

    I dont understand what means “Permission non accordée in line 94 & 95” ?
    thank you in advance

  39. Ishanka Anuradha Ranasooriya Says:

    I did it auto start and stop in this way

    1-Edit the #vi /etc/oratabfile :


    vi /etc/init.d/oracle

    paste this script to it and save

    # oracle This shell script takes care of starting and stopping
    # the Oracle subsystem (oracle).
    # chkconfig: – 64 36
    # description: Oracle database server.
    # processname: oracle
    # pidfile: /var/run/oracle/oracle.pid
    # Provides: oracle
    # Required-Start: $local_fs $remote_fs $network $named $syslog $time
    # Required-Stop: $local_fs $remote_fs $network $named $syslog $time
    # Short-Description: start and stop Oracle server
    # Description: Oracle database server

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

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

    start() {
    if [ -e /var/lock/subsys/oracle ];then
    echo “Starting Oracle Enterprise Server”
    echo “Starting Oracle Enterprise Server”
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Listeners” >> /var/log/oracle/oracle.log
    su – oracle -c “lsnrctl start” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Databases” >> /var/log/oracle/oracle.log
    su – oracle -c “dbstart” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Starting Oracle Enterprise Manager” >> /var/log/oracle/oracle.log
    su – oracle -c “emctl start dbconsole” >> /var/log/oracle/oracle.log
    touch /var/lock/subsys/oracle

    stop() {
    if [ -f /var/lock/subsys/oracle ];then
    echo “Shutting Down Oracle Enterprise Server”
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Enterprise Manager” >> /var/log/oracle/oracle.log
    su – oracle -c “emctl stop dbconsole” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Listeners” >> /var/log/oracle/oracle.log
    su – oracle -c “lsnrctl stop” >> /var/log/oracle/oracle.log
    echo “`date “+%m/%d/%Y %H:%M:%S”` : Shutting Down Oracle Databases” >> /var/log/oracle/oracle.log
    su – oracle -c “dbshut” >> /var/log/oracle/oracle.log
    rm -f /var/lock/subsys/oracle
    echo “Shutting Down Oracle Enterprise Server”

    case “$1” in
    if [ -e /var/lock/subsys/oracle ]; then
    echo -n “Oracle Enterprise Server is Running”
    echo -n “Oracle Enterprise Server is Not Running”
    sleep 2
    echo $”Usage: $0 {start|stop|restart|status}”
    exit 1

    exit 0

    chkconfig –add oracle
    chkconfig oracle on

    Cheers Your done

  40. Kamran Agayev A. Says:

    Perfect, thanks for sharing !

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>