Detecting if an Oracle Database is Installed
-
08-07-2019 - |
Question
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
Solution
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.
OTHER TIPS
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_
(likeKEY_OraDb10g_home1
, the end string being an Oracle home name). - Has a value whose name starts with
ORA_
and ends with_AUTOSTART
. (likeORA_XE_AUTOSTART
, the middle string being an instance name).
- Has a name starting with
- The key
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.
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.
Look up the /etc/oratab file for oracle homes.These homes have the database software installed as well as the database name from that home.Then you can check whether the database is sound or not by starting it.
I'm not sure about Oracle, but for MySQL and PostgreSql I do the following:
$yum grouplist | grep SQL
This returns:
MySQL Database client
MySQL Database server
PostgreSQL Database client
PostgreSQL Database server
So I assume you should try:
$yum grouplist | grep Orac