Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if an Oracle Database is Installed

I was wondering if there was a way to tell if an instance of Oracle on a system has a database installed or not?

This is for an installation script, and I need to verify that there is an actual database in place before proceeding with the loading of my own tablespace onto that database. Has anyone tackled this problem before?

Cheers

like image 909
Chris McAtackney Avatar asked Nov 20 '08 11:11

Chris McAtackney


3 Answers

Check for the existence of an ORACLE_HOME. It's also reasonable to expect that this environment should be configured for the installation, so testing the environment variables and exiting with a sensible diagnostic (possibly suggesting they run oraenv) is a good first start. If you have an ORACLE_HOME, ORACLE_SID or other appropriate environment variable set up, you can then check for the existence of an oracle home and test for database connectivity and permissions.

like image 200
ConcernedOfTunbridgeWells Avatar answered Oct 12 '22 16:10

ConcernedOfTunbridgeWells


For Oracle 10g, on Windows :

  • Check the registry :
    • The key HKLM\SOFTWARE\ORACLE must exist.
    • A subkey must exist that :
      • Has a name starting with KEY_ (like KEY_OraDb10g_home1, the end string being an Oracle home name).
      • Has a value whose name starts with ORA_ and ends with _AUTOSTART. (like ORA_XE_AUTOSTART, the middle string being an instance name).

Beware, installing an Oracle client (without a database instance then), creates entries in the registry and can set environment variables (like ORACLE_HOME). This is why the above pattern is a bit complicated.

This pattern is very likely to work for Oracle 9i also, and possibly Oracle 8i.

like image 33
Mac Avatar answered Oct 12 '22 16:10

Mac


You could use tnsping to check whether the database listener is active, that would be a good indication. Other than that, why not just simply do a test connection? If it's part of an installer process, you could prompt the user to enter the appropriate connection credentials if you don't know what they'll be in advance.

like image 33
ninesided Avatar answered Oct 12 '22 16:10

ninesided