The Blog from the DBA Classroom

By: Joel Goodman

Teach Yourself Some OCR

Posted by Joel Goodman on 11/02/2009

The Oracle Clusterware Repository or OCR is a file containing metadata describing the Cluster configuration, the locations of the voting disks, the resources managed by the Clusterware processes and their attributes and interrelationships.

Two of the utilities which access the OCR file and display certain details are:

1. srvctl – this will display certain attributes relating to ASM, Databases, Database and ASM instances, Services, Listeners and Nodeapps. We can see this with a simple invocation of “srvctl”:

Oracle$ srvctl
Usage: srvctl <command> <object> [<options>]

objects: database|instance|service|nodeapps|asm|listener
For detailed help on each command and object and its options use:
srvctl <command> <object> -h

I have highlighted the list of objects that may be managed with any of the commands listed above but notice that the resources in the object do not include clusterware components or metadata and there is no reference to clusterware attributes. Note that the nodeapps include the VIPs which are not part of the clusterware but rather are resources managed by the clusterware.

2. crs_stat – this utility has many flags controlling the level of detail displayed on the screen but essentially this will display clusterware resources in a formatted output. Here are the options:

Oracle$ crs_stat -h
Usage:  crs_stat [resource_name […]] [-v] [-l] [-q] [-c cluster_member]
crs_stat [resource_name […]] -t [-v] [-q] [-c cluster_member]
crs_stat -p [resource_name […]] [-q]
crs_stat [-a] application -g
crs_stat [-a] application -r [-c cluster_member]
crs_stat -f [resource_name […]] [-q] [-c cluster_member]
crs_stat -ls [resource_name […]] [-q]

If “crs_stat” is invoked with no arguments then a terse output is produced containing the name and 3 attributes of resources such as Databases, ASM, Instances of Databases and ASM, Services and their preferred instances, Listeners, and Nodeapps. Here is some example output:

Oracle$ crs_stat

STATE=ONLINE on abcduc1

STATE=ONLINE on abcduc2

STATE=ONLINE on abcduc1

A popular alternative is to use the -t flag to restrict output to one line per resource as follows:

Oracle$ crs_stat -t
Name              Type           Target       State       Host
ora….A1.inst   application    ONLINE     OFFLINE
ora….A2.inst   application    ONLINE     OFFLINE
ora….l1.inst   application     ONLINE     ONLINE     abcduc1
ora….l2.inst   application     ONLINE     ONLINE     abcduc2
ora.angel.db   application    ONLINE     ONLINE     abcduc1


Note that the resource name is not fully printed with this formatting. Also the list of resources is still restricted to the ones I mentioned above.

One way to get the full resource name is to use a script to format the name and other attributes as follows:

# Sample 10g CRS resource status query script
# Description:
#    – Returns formatted version of crs_stat -t, in tabular
#      format, with the complete rsc names and filtering keywords
#   – The argument, $RSC_KEY, is optional and if passed to the script, will
#     limit the output to HA resources whose names match $RSC_KEY.
# Requirements:
#   – $ORA_CRS_HOME should be set in your environment

AWK=/usr/bin/awk    # if not available use /usr/bin/awk

# Table header:echo “”
$AWK \
‘BEGIN {printf “%-45s %-10s %-18s\n”, “HA Resource”, “Target”, “State”;
printf “%-45s %-10s %-18s\n”, “———–“, “——“, “—–“;}’

# Table body:
$ORA_CRS_HOME/bin/crs_stat $QSTAT | $AWK \
‘BEGIN { FS=”=”; state = 0; }
$1~/NAME/ && $2~/’$RSC_KEY’/ {appname = $2; state=1};
state == 0 {next;}
$1~/TARGET/ && state == 1 {apptarget = $2; state=2;}
$1~/STATE/ && state == 2 {appstate = $2; state=3;}
state == 3 {printf “%-45s %-10s %-18s\n”, appname, apptarget, appstate; state=0;}’

This will return output containing the complete resource name:

HAResource                                       Target         State

—————                                        ——–         ——

ora.TUTOR1A.TUTOR1A1.inst      ONLINE     ONLINE on abcduc1


If however, you wish to examine all the metadata in the OCR including details of the clusterware files, network addresses, ports, processes and their attributes then use the “ocrdump” utility in the clusterware home bin directory:

To get help simply do:

Oracle$ ocrdump -h

ocrdump – Dump contents of Oracle Cluster Registry to a file.

ocrdump [<filename>|-stdout] [-backupfile <backupfilename>] [-keyname <keyname>] [-xml] [-noheader]

Default filename is OCRDUMPFILE. Examples are:

prompt> ocrdump
writes cluster registry contents to OCRDUMPFILE in the current directory

prompt> ocrdump MYFILE
writes cluster registry contents to MYFILE in the current directory

prompt> ocrdump -stdout -keyname SYSTEM
writes the subtree of SYSTEM in the cluster registry to stdout

prompt> ocrdump -stdout -xml
writes cluster registry contents to stdout in xml format
The header information will be retrieved based on best effort basis.
A log file will be created in $ORACLE_HOME/log/<hostname>/client/ocrdump_<pid>.log. Make sure  you have file creation privileges in the above directory before running this tool.

So now do the following:

Oracle$ ocrdump MYOCRDUMP

This will produce a formatted dump called MYOCRDUMP of all the OCR file contents in the current directory which may them be explored using any convenient editing tool.

The Dumpfile has 3 main parts:

1. SYSTEM – Desribes attributes of the clusterware such as interfaces, cluster name, cluster parameters such as misscount, locations of voting disks, location of OCR backups, cluster node names and numbers, hostnames and much more. This metadata is used by the clusterware processes CRSD, CSSD and EVMD.

2. DATABASE – Contains metadata for all the resources managed by the clusterware. This is the information that is formatted for output by the “crs_stat” utility and  by “srvctl” and lists databases, ASM, instances, services, nodeapps, atc..

3. CRS – Contains metadata for any Non-RAC resources that are managed for high availability by the clusterware. These resources will have been created by the “crs_profile” utility, and then registered in the OCR using the “crs_register” utility. Once all related resources have been registered then they will have been activated using the “crs_start” utility. If no such resources are managed by the clusterware then the CRS section will be virtually empty with a single entry for Scurity.

When I began using Oracle clusterware for 10g, I used the “ocrdump” utility primarily as a learning tool to improve my understanding of the Clustereware architecture and encourage all DBAs using or learning RAC to do the same. I now use it as a teaching tool in the DBA Classroom.

Note that an OCR DUMP file is quite large but an example may be found at thie link:

>>  Sample OCR Dump


3 Responses to “Teach Yourself Some OCR”

  1. Neil said

    Hi Joel

    When oh when will crs_stat be modified to include the output in for the form provided by the shell script ?

    It seems such a commonly used script now in so many sites, it seems logical to include it as part of the standard seeded utility.



  2. Uwe Hesse said

    Hi Joel,
    I like the idea to encourage people to use Oracle utilities for investigating the technology and thereby getting a better understanding!

    As a little addendum to your posting: Simply typing

    srvctl -h

    gives a quite useful syntax help – filling the complete screen. If you already have a clue about what to manage (services, for instance), than you may filter that with grep like

    srvctl -h | grep service

    That gives you all commands for managing services. With this approach, I rarely have to visit the documentation for my srvctl usage.

    Kind regards

  3. Surachart said

    Hi Joel Goodman,

    Thank you about OCR and some utilities. That’s a good idea to use some utilities with learning.
    Oracle Cluster has many utilities…
    I used more to understand and learn.
    Anyway I still find idea with them.

    Thank You

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: