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:
mydb:/home/oracle/product/10.1.0/Db_1:N
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:
ORACLE_HOME=/home/oracle/product/10.1.0/Db_1
ORA_OWNER=oracle
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”
;;
esac
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
P.S
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
April 28th, 2009 at 6:54 pm
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.
April 28th, 2009 at 7:03 pm
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
July 21st, 2009 at 6:00 pm
URGENT PLEASE!!
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
July 21st, 2009 at 6:04 pm
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
July 22nd, 2009 at 2:52 am
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 10.2.0.1 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.127.0.0.1 database localhost.localdomain localhost
Step 03: Check the hostname and make sure you can ping your hostname.
$ hostname
database
$ ping database
PING database (127.0.0.1) 56(84) bytes of data.
64 bytes from database (127.0.0.1): icmp_seq=0 ttl=64 time=0.057 ms
64 bytes from database (127.0.0.1): icmp_seq=1 ttl=64 time=0.050 ms
64 bytes from database (127.0.0.1): 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,
127.0.0.1 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 4.2.2.2
September 24th, 2009 at 10:03 am
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
September 28th, 2009 at 8:35 am
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
October 28th, 2010 at 7:36 pm
Excellent job! Ordering the book now.
May 7th, 2011 at 12:31 am
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?
Regards
May 8th, 2011 at 12:22 am
Are you able to start the EM from outside the script? If not, then try to delete and create the EM repository again
May 8th, 2011 at 4:31 am
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
May 10th, 2011 at 7:12 am
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.
June 15th, 2011 at 8:25 pm
Where can I download orarun rpm?
I tried to find that on internet but not find yet
June 16th, 2011 at 3:01 pm
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
June 16th, 2011 at 3:01 pm
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
June 16th, 2011 at 4:14 pm
Dear Kamran,
I have installed oracle10R2 on CentOs 5.6 and followed your steps to automate but it is not working
June 16th, 2011 at 4:17 pm
Dear Tanverr, just change the commas after copy/pasting the code and verify why it is not working. The code is correct
June 16th, 2011 at 5:02 pm
where sould I place commas ?
ORACLE_HOME=/home/oracle/product/10.1.0/Db_1
ORA_OWNER=oracle
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”
;;
esac
July 11th, 2011 at 6:29 pm
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
October 18th, 2011 at 12:14 pm
hi kamran ,
can you please mention the content & path of the listener.ora and tnsname.ora file
thanks in advance
vijay
October 18th, 2011 at 5:56 pm
Hi Vijar
The path of the network configuration files is $ORACLE_HOME/network/admin folder
February 11th, 2012 at 1:49 pm
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
Thanks
February 12th, 2012 at 4:20 pm
Make sure you’ve set ORACLE_SID environment variable correctly and then start the listener and EM
March 20th, 2012 at 2:55 pm
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.
March 21st, 2012 at 6:48 pm
Hi Gagan
Check the following documentation :
http://docs.oracle.com/cd/B19306_01/backup.102/b14191/rcmasm.htm#i1016581
March 22nd, 2012 at 1:58 am
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.
March 26th, 2012 at 7:01 am
In order to start the database automatically in *nix OS, you *have* you create a script and it can’t be done via EM
April 3rd, 2012 at 3:58 pm
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.
ALSO THERE IS NO DIR APPL_TOP IN MY APP SERVER.
thanks
gagan
April 5th, 2012 at 4:55 am
Please post your question under the following topic:
https://forums.oracle.com/forums/forum.jspa?forumID=82
May 3rd, 2012 at 4:19 pm
am trying to run the scrip but it throws me java error
./OMBPlus.sh
OMB*Plus: Release 11.2.0.3.0
Copyright (c) 2000, 2011, Oracle. All rights reserved.
java.lang.reflect.InvocationTargetException
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
java.lang.reflect.InvocationTargetException
thanks
gagan
May 30th, 2012 at 5:22 pm
hi
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.
thanks
gagan
May 31st, 2012 at 6:27 am
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
July 12th, 2012 at 8:21 pm
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..
July 12th, 2012 at 8:30 pm
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
!!!!!!
July 20th, 2012 at 12:05 pm
Have you set ORACLE_HOME_LISTNER parameter?
July 13th, 2012 at 1:03 pm
Hi Mr Kamran,
I posted yesterday two messages about automating startup of database and I see now that are deleted!! where is the problem ?
Greeting.
July 20th, 2012 at 12:05 pm
They were waiting to be approved
July 22nd, 2012 at 2:42 am
Thank you Mr kamran for reply,
Yes in my dbstart script($ORACLE_HOME/bin/dbstart) I have that
ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
# First argument is used to bring up Oracle Net Listener
#ORACLE_HOME_LISTNER=$ORACLE_HOME
ORACLE_HOME_LISTNER=$ORACLE_HOME
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
November 7th, 2013 at 7:26 am
I did it auto start and stop in this way
1-Edit the #vi /etc/oratabfile :
orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
then
vi /etc/init.d/oracle
paste this script to it and save
#!/bin/bash
#
# 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
### BEGIN INIT INFO
# 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
### END INIT INFO
# 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”
failure
else
echo “Starting Oracle Enterprise Server”
success
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
fi
}
stop() {
if [ -f /var/lock/subsys/oracle ];then
echo “Shutting Down Oracle Enterprise Server”
success
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
else
echo “Shutting Down Oracle Enterprise Server”
failure
fi
}
case “$1” in
start)
start
;;
stop)
stop
;;
status)
if [ -e /var/lock/subsys/oracle ]; then
echo -n “Oracle Enterprise Server is Running”
success
echo
else
echo -n “Oracle Enterprise Server is Not Running”
failure
echo
fi
;;
restart)
stop
sleep 2
start
;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
exit 1
esac
exit 0
then
chkconfig –add oracle
chkconfig oracle on
Cheers Your done
January 7th, 2014 at 1:01 pm
Perfect, thanks for sharing !