Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix script to check oracle database 5

Status
Not open for further replies.
Jan 21, 2005
4
US
Hey there,
I would like to know how to write a unix script to check whether the oracle database is up or not. Any tips or guidance is appreciated.
Thanks,
p.
 
You could try connecting to the database something like this:

sqlplus user/password <<!
exit
!

and check for the return code, $?. If it's zero all is well, if not, your database isn't available for whatever reason. Be aware that this carries the security risk of a username/password in plain text within a script.
 
That said, I guess if you created a user with the minimum permissions within the database, the security issue might not be so much of a stumbling block. Others might disagree, however....
 
At the site where I work, we wanted to use a UNIX script that didn't actually access the database, so we use the following:
Pass the Oracle SID to a function
Check the existence of the 4 essential processes:
(ie ora_pmon_SID , ora_smon_SID , ora_dbw0_SID & ora_lgwr_SID)
Set a variable to the count of the ones that are present
Any value less than 4 means the database is not up
(value of 0 means not even started, values 1 to 3 mean a process is missing)

Whilst I acknowledge that a value of 4 doesn't always guarantee that a database is up, we have yet to come across a situation where the value was 4 and the database was not available.

I hope that helps.

Mike
 
You must also check if the listener( or multiple listeners) is running, otherwise the database is running, but nobody can connect

ps -ef|grep LISTENER|grep -v grep

greetz,

R.
 
There's an Oracle utility called [tt]tnsping[/tt] that will ping the listener. This doesn't guarantee the database is up, but is a good first step in a script.

If the default test account has been left in, you can try the login test above using the userid [tt]scott[/tt] with the password [tt]tiger[/tt].

Hope this helps.
 
instead of
Code:
ps -ef|grep LISTENER|grep -v grep
I would use
Code:
ps -C tnslsnr
if your ps supports commandnames.

To issue an 'select sysdate from dual' seems to be more secure as stated above.

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top