oracle-databaseoracle-rac

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


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.


Solution

  • 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