7 Replies Latest reply: Oct 7, 2013 2:39 PM by EdStevens RSS

    clarity on srvctl and crsctl commands

    EdStevens

      Oracle 11.2.0.2/3, SE-One

      Oracle GI 11.3, stand-alone ASM, no cluster, no RAC

      Oracle Linux 5.6 x86-64

       

      Trying to get a better grip on commands dealing with Oracle Restart.

       

      First, from the Database Administrator’s Guide (E25494-03), p. 4-10, under “Preparing to run SRVCTL”, it states that you must run srvctl from the ORACLE_HOME appropriate for the component to be configured.  But it seems that this is if you are configuring a component.  What about simply querying status – “srvctl config …”? My testing seems to indicate that I can “config” (a bit of a misnomer, no?) both db and ASM components from the ASM home. 

       

      The reason I ask is that I’d like to write a generic script to report all configured components without the script being hard-coded for any specific database.  I’ve got that working by hard-coding the environment for one of the databases before calling ‘srvctl config database’. But to eliminate that I either have to be able to self-discover the names of the databases, or just run it all from the ASM home.  The latter seems to work ok, but I’m not grounded enough on this part to know if I’m overlooking a ‘gotcha’.  If that’s not good, them it looks like I’m in a chicken-or-egg situation .. can’t get srvctl to give me the name of the configured databases without setting the HOME for a database, and can’t set the HOME for a database (with oraenv) until I have a database name.  And while I’m not dealing with it currently, imagine a configuration with multiple databases from multiple HOMEs.  Once I have the list of databases (say, grep'ing and awk'ing the output of 'srvctl config database') the rest is easy.  But if that initial srvctl requires the OHOME be set to the db home ... not sure how to proceed.  Can't grep oratab because nothing there is guaranteed to identify an entry for a database vs. some sometimes generic entries.  And grep'ing 'ps -ef|grep pmon' depends on the databases actually being started.

       

       

       

      I’ll be the first to admit that whenever the docs start to deal with anything having to do with the Grid Infrastructure, I have a very hard time knowing when something does NOT apply to my non-cluster, non-RAC environment. 

        • 1. Re: clarity on srvctl and crsctl commands
          Javier Francisco Ruiz

          Use the oratab file from there you can get the database name and the oracle home that the database is using.

          • 2. Re: clarity on srvctl and crsctl commands
            EdStevens

            JavierFranciscoRuiz wrote:

             

            Use the oratab file from there you can get the database name and the oracle home that the database is using.

            As I had said, I had considered the oratab file, but that's not as clear cut as you might think.

            Take this example:

             

            #

            +ASM:/u01/app/oracle/product/11.2.0.2/grid:N

            listener:/u01/app/oracle/product/11.2.0.2/grid:N

            db11g:/u01/app/oracle/product/11.2.0.2/dbhome_1:N  # generic entry, not an actual database

            hrdb:/u01/app/oracle/product/11.2.0.2/dbhome_1:N            # line added by Agent

            findb:/u01/app/oracle/product/11.2.0.1/dbhome_1:N             # line added by Agent

            olddb:/u01/app/oracle/product/10.2.0.4/db_1:N           # not registered to oracle restart

            client_1:/u01/app/oracle/product/11.2.0.2.1/db_1

             

             

            Now, what would you grep out to positively identify the relevant database homes without eyeballing it and making an educated decision?  Remember, the task is to NOT hard-code ANY database names into the script.  The script must be portable across unrelated servers.

            • 3. Re: clarity on srvctl and crsctl commands
              Javier Francisco Ruiz

              Below is example you can do on Linux / UNIX

               

              Below you can extract the database home

              export ORACLE_HOME=`cat /etc/oratab | grep -v \# | grep -i :Y | awk -F ":" '{print $2 }'`

               

              Below you can use to extract the database name

              export ORACLE_SID=`cat /etc/oratab | grep ${ORACLE_HOME} | grep -v \# | head -1 | awk -F ":" '{print $1}'`

               

              What you are looking for I already do with a similar code above.

              • 4. Re: clarity on srvctl and crsctl commands
                Levi Pereira

                Also you can use crsctl from GI HOME to get info about DATABASE and ORACLE_HOME (e.g   "crsctl status res -p").

                 

                e.g

                $ crsctl status res ora.orcl.db -p

                This return many info about your database. With grep or awk is easy to write your script.

                 

                HTH,

                Levi Pereira

                • 5. Re: clarity on srvctl and crsctl commands
                  EdStevens

                  JavierFranciscoRuiz wrote:

                   

                  Below is example you can do on Linux / UNIX

                   

                  Below you can extract the database home

                  export ORACLE_HOME=`cat /etc/oratab | grep -v \# | grep -i :Y | awk -F ":" '{print $2 }'`

                   

                  Below you can use to extract the database name

                  export ORACLE_SID=`cat /etc/oratab | grep ${ORACLE_HOME} | grep -v \# | head -1 | awk -F ":" '{print $1}'`

                   

                  What you are looking for I already do with a similar code above.

                   

                  I think you are missing my point.  I know how to grep and awk the file.  The problem is that if I use that to drive my use of srvctl, it will get false positives.  In the above example, the false positives would be on these lines:

                   

                  listener:/u01/app/oracle/product/11.2.0.2/grid:N

                  db11g:/u01/app/oracle/product/11.2.0.2/dbhome_1:N  # generic entry, not an actual database

                  olddb:/u01/app/oracle/product/10.2.0.4/db_1:N           # not registered to oracle restart

                  client_1:/u01/app/oracle/product/11.2.0.2.1/db_1

                   

                  So, my question was, is there any reason not to simply run srvcgtl from the ASM home when reporting (not actually changing) the database configuration?

                  • 6. Re: clarity on srvctl and crsctl commands
                    EdStevens

                    Levi-Pereira wrote:

                     

                    Also you can use crsctl from GI HOME to get info about DATABASE and ORACLE_HOME (e.g   "crsctl status res -p").

                     

                    e.g

                    $ crsctl status res ora.orcl.db -p

                    This return many info about your database. With grep or awk is easy to write your script.

                     

                    HTH,

                    Levi Pereira

                     

                    Yes, that looks like it will give me what I need, in addition to some other information that will be useful.

                    • 7. Re: clarity on srvctl and crsctl commands
                      EdStevens

                      EdStevens wrote:

                       

                      JavierFranciscoRuiz wrote:

                       

                      Below is example you can do on Linux / UNIX

                       

                      Below you can extract the database home

                      export ORACLE_HOME=`cat /etc/oratab | grep -v \# | grep -i :Y | awk -F ":" '{print $2 }'`

                       

                      Below you can use to extract the database name

                      export ORACLE_SID=`cat /etc/oratab | grep ${ORACLE_HOME} | grep -v \# | head -1 | awk -F ":" '{print $1}'`

                       

                      What you are looking for I already do with a similar code above.

                       

                      I think you are missing my point.  I know how to grep and awk the file.  The problem is that if I use that to drive my use of srvctl, it will get false positives.  In the above example, the false positives would be on these lines:

                       

                      listener:/u01/app/oracle/product/11.2.0.2/grid:N

                      db11g:/u01/app/oracle/product/11.2.0.2/dbhome_1:N  # generic entry, not an actual database

                      olddb:/u01/app/oracle/product/10.2.0.4/db_1:N           # not registered to oracle restart

                      client_1:/u01/app/oracle/product/11.2.0.2.1/db_1

                       

                      So, my question was, is there any reason not to simply run srvcgtl from the ASM home when reporting (not actually changing) the database configuration?

                       

                      Sometimes you just have to get away from the problem for a few hours/days and come back at it fresh.

                      First, as I just discovered after upgradeing my ASM instance but not my db instances, 'srvctl config database -d <dbname>'  simply doesn't work if the db is from a different home, or at least a different level, from the one from which you are executing srvctl.

                       

                      Second, instead of trying to parse out oratab with some fancy grep'ing and awk'ing, I could just use it as intended, within the construct I already had.  (DOH!)

                      So, after getting what I wanted from crsctl commands, it was still useful to report from srvctl, so I finally arrived at this to give me a nicely formatted output:

                       

                      # at this point, env is set for +ASM home

                      # and ORAENV_ASK=NO

                      echo ============ configured databases ============

                      srvctl config database

                      echo

                      echo ============ database details ============

                      srvctl config database | \

                      awk -F\" '{print "export ORACLE_SID="$1  \

                              RS ". oraenv" \

                              RS "srvctl config database -d " $1 " -a" \

                              RS "echo =================================================="}' | sh