Tuesday, December 25, 2007

Oracle crs_stat command

The crs_stat command provide status information for resource on the cluster node. To query resource with the crs_stat command.

Resource are either ONLINE or OFFLINE as shown in the STATE attribute. An application resource in the ONLINE state is running successfully on a cluster node.

The TARGET value shows the state to which Oracle Clusterware attempt to set the resource. If the TARGET value is ONLINE and a cluster node fails, then Oracle Clusterware attempts to restart the application on another node if possible. If there is a condition forcing a resource STATE to be OFFLINE, such as a required resource that is OFFLINE, then the TARGET value remains ONLINE and Oracle Clusterware attempts to start the application or application resource once the condition is corrected.

A TARGET value for all non-application resources should be ONLINE unless the resource has a failure count higher than the failure threshold, in which case the TARGET is changed to OFFLINE. The Oracle Clusterware then treats the resource as if its STATE were OFFLINE. If the STATE is ONLINE and the TARGET is OFFLINE, then you can reset the target value to ONLINE using the crs_start command.

Syntax and Options for crs_stat
Use the crs_stat command with the following syntax:

crs_stat [resource_name [...]] [-v] [-l] [-q] [-c cluster_node]

crs_stat [resource_name [...]] -t [-v] [-q] [-c cluster_node]

crs_stat -p [resource_name [...]] [-q]

crs_stat [-a] resource_name -g

crs_stat [-a] resource_name -r [-c cluster_node]

crs_stat -f [resource_name [...]] [-q] [-c cluster_node]

crs_stat -ls resource_name

* -v— Displays extended information about the status of resources. Extra attributes shown include RESTART_COUNT and FAILURE_COUNT. The RESTART_COUNT attribute shows the number of restarts of the application that have been attempted since it was started. The FAILURE_COUNT attribute shows how many failures have occurred during the last FAILURE_THRESHOLD in seconds. The attribute FAILOVER_STATUS shows the time at which an application resource started while waiting to relocate due to a cluster node failure if the resource has a FAILOVER_DELAY value greater than 0. It is not displayed otherwise.

* -l— Displays the status in a list (non-tabular) format. This is the default format.

* -t— Displays the status in tabular format.

* -p resource_name [...]]— Displays the status of the in-memory profile for the specified resources. If no resources are specified, then the status of the in-memory profile for all registered resources is displayed. If a resource is not registered, its status is not displayed.

* -a resource_name— Used with the -g or -r option to verify whether the specified resource is registered or running under Oracle Clusterware. Specify the name of the resource as listed in its application profile.

* -f— Displays all information about the resource including extended information (-v) and the in-memory profile (-p).

* -g— Returns 0 (zero) if the specified application or application resource is registered with Oracle Clusterware; returns 1 if it is not. This option only works if a single resource is specified with the -a option.

* -r— Returns 0 (zero) if the specified application or application resource is running under Oracle Clusterware; returns 1 if it is not. This option can only be successful if a single resource is specified with the -a option.

* -c cluster_node— Displays information about applications or application resources on the specified cluster node.

Examples of crs_stat
NAME=ora.DB.SDB.DB3.srv
TYPE=application
TARGET=ONLINE
STATE=ONLINE on db04

NAME=ora.DB.SDB.cs
TYPE=application
TARGET=ONLINE
STATE=ONLINE on db03

Examples of crs_stat -v
NAME=ora.DB.SDB.DB3.srv
TYPE=application
RESTART_ATTEMPTS=0
RESTART_COUNT=0
FAILURE_THRESHOLD=0
FAILURE_COUNT=0
TARGET=OFFLINE
STATE=OFFLINE

NAME=ora.DB.SDB.DB4.srv
TYPE=application
RESTART_ATTEMPTS=0
RESTART_COUNT=0
FAILURE_THRESHOLD=0
FAILURE_COUNT=0
TARGET=OFFLINE
STATE=OFFLINE


Examples of crs_stat -t

Name Type Target State Host
------------------------------------------------------------
ora....DB3.srv application OFFLINE OFFLINE
ora....DB4.srv application OFFLINE OFFLINE
ora....B1.inst application ONLINE ONLINE db01
ora....B2.inst application ONLINE ONLINE db02

Anyway we can write script to easy.
Example "crstat" script>>
#!/usr/bin/ksh
RSC_KEY=$1
QSTAT=-u
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;}'
----------->>>
#./crstat
HA Resource Target State
----------- ------ -----
ora.DB.SDB.DB3.srv OFFLINE OFFLINE
ora.DB.SDB.DB4.srv OFFLINE OFFLINE
ora.DB.DB1.inst ONLINE ONLINE on db01
ora.DB.DB2.inst ONLINE ONLINE on db02

That is a good command help us to provide status information for resource on the cluster node.

No comments: