I've a Linux VM with Oracle database serve and it gets restarted periodically and hence next time, oracle listener is not running. So I've to start it manually with following commands –
export ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=orcl;
$ORACLE_HOME/bin/lsnrctl start LISTENER
sqlplus
sys as sysdba/password
startup
This activity I've to do every time machine is restarted.
Is there a way with which oracle listener is started along with machine start? i.e. something like windows services which gets automatically started with machine start.
Best Answer
This question has been asked and answered hundreds, if not thousands, of times. A simple google search turns up dozens of hits. When in doubt, refer to the official oracle docs: https://docs.oracle.com/database/121/UNXAR/strt_stp.htm#UNXAR140
As an aside, there is no reason for you to manually enter all those commands to set the oracle environment. That is what the 'oraenv' utility is provided for. First, as a one-time setup, make sure your database is properly listed in /etc/oratab. Creating the database with dbca should have done this for you. Mine looks like this (the 'cat' command types the file, piping the output to 'grep -v' filters out the comment lines.
The format of the entry is
Now before invoking oraenv, let's check our enviornment:
The 'env' command shows all environment variables. Piping the output to 'grep' allows me to show only those that contain the string 'ORA'. And you see I have none. Also, you see that $ORACLE_HOME/bin is not in my PATH.
Now envoke oraenv. When prompted, enter the value of ORACLE_SID, as listed in /etc/oratab
Now let's check the environment again:
And you can see that 'oraenv' set it all for me.
I take it one step further, and put that in by .bash_logon script, so that my environment is set 'automagicly" when I log on to the server:
Relevent contents of my .bash_profile: