How to start oracle automatically after a system restart

Here I am explaining the simplest way to start oracle database and listener automatically after a restart of the server. This will be the best method to implement on your test or development server.

When you do a search on how to start oracle database automatically after a system restart, you will find out the method to start oracle database and the corresponding listener by editing the oratab file and creating scripts in init.d directory. That method is the traditional one and it will start the database along with the system reboot. It will result in a long reboot time for the server depending up on the size of your database.

In the method described here to start oracle database and listener automatically, the database startup will happen after the system reboot only. So you can do other activities on the server by the time the database gets started.

What are the steps you follow to start the database manually after a system reboot? Just write them in a file to create a script. Then run the script after reboot using crontab. This is my idea. It is very simple right?

Now, lets check how to implement this method to start the oracle database and listener automatically after every server reboot.

Just look into the example given below.
1. create a file (db.sh in /root) with the following content. (changes has to be made with respect to your database environment)

su - oracle <<EOS
export ORACLE_SID=orcl
sqlplus -s /nolog <<SQL
conn / as sysdba
startup
exit
SQL
lsnrctl start
EOS

I create the file with this content because these are the commands I use to start the database and listener manually. I have already given the ORACLE_HOME and other environment variables in the bash_profile of the user.

May the "<<EOS" will not be familiar for you, it says the commands between two EOS has to be run as oracle user. In the same way the commands between two SQL has to be run inside the sqlplus. (instead of EOS and SQL you can give any thing say.. ABC, XYZ)

OK. fine.
Now how to run this script at boot or immediately after the boot so that we can start the database and listener automatically. We have an amazing option in crontab.

execute crotab -e and add the following line to it
@reboot /bin/sh /root/db.sh

Done!!!
You have configured the database and the listener to start automatically after reboot of the server.
Restart your server to test if it is working.