How to find database name in oracle without using sqlplus or srvctl?

2.5k Views Asked by At

I want to know different ways to find the database name without making connection to the database, neither using sqlplus or srvctl

In oracle, let's suppose I have 2 nodes in a RAC running the database pstest. I can get the database name by simply connecting to any one of the db instance and query as below

SQL> select name from v$database;
NAME
---------
PSTEST

or

SQL> show parameter db_name
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_name                              string      pstest`

But I need to know how can I get the database name which is pstest here without connecting to the database by sqlplus (so both above won't be useful).

As my pstest database is running in 2 instances - pstest1 on node1 and pstest2 on node2. So I can use srvctl as below

  srvctl status database -d pstest
  Instance pstest1 is running on node1
  Instance pstest2 is running on node2

But how can I get <db_name> to use to in srvctl without using srvctl or sqlplus ?

Thanks In Advance.

3

There are 3 best solutions below

0
On BEST ANSWER

Without even understanding why you'd need this, which is kind of odd, a way to do this would be ( keeping in consideration that you are using Oracle RAC )

The utility in this case is csrsctl

Example

srvctl status database -d otcgr2ng
Instance otcgr2ng1 is running on node scglvdoraci0009
Instance otcgr2ng2 is running on node scglvdoraci0010
db_name=$(crsctl stat res -t | grep ".db$" | grep -v mgmt | awk -F '.' '{print $2}')
srvctl status database -d ${db_name}
Instance otcgr2ng1 is running on node scglvdoraci0009
Instance otcgr2ng2 is running on node scglvdoraci0010

What I did was using crsctl to get the database name. Obviously, it would only work in your scenario that you have one database.

CRSCTL is an interface between you and Oracle Clusterware, parsing and calling Oracle Clusterware APIs for Oracle Clusterware objects. You can use CRSCTL commands to perform several operations such as Starting and stopping Oracle Clusterware resources, Enabling and disabling Oracle Clusterware daemons, Checking the health of the cluster, etc...

I remove the mgmtdb which is an internal database of the Grid Infrastructure. If you had more than one database in Oracle RAC , then

for db_name in $(crsctl stat res -t | grep ".db$" | grep -v mgmt | awk -F '.' '{print $2}')
do
echo $db_name
done
0
On

The "crsctl" command give you the database unique name, not database name. These 2 can be different if this is a standby database. You need to do srvctl (from RDBMS software) to get the database name. So, if the database unique name is different from database name (for example, in case of standby databases), you

So, use crstl to get the database unique name first:

$CRS_HOME/bin/crsctl stat res -t | grep ".db$" | grep -v mgmt | awk -F '.' '{print $2}'

dbuniq_aws

Then use srvctl to get the database name, using uppercase database unique name:

$ORACLE_HOME/bin/srvctl config database -d DBUNIQ_AWS | grep 'Database name:' | cut -d":" -f2 | cut -d" " -f2

DBUNIQ

So as you see, the "srvctl config database" has information on the database name, as long as you have the database unique name information.

0
On

Try with: srvctl config database