[20190507]crs_stat与crsctl.txt
--//管理rac,遇到问题一般首先通过crs_stat与crsctl查看资源的状况.
--//10g下一般使用crs_stat ,我记忆里面好像没有crsctl命令,这个是11g才有的命令,用来取代crs_stat.
--//实际上11g命令crs_stat还是存在的.
--//一般加入-t命令执行如下:
$ crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora.DATA.dg ora....up.type ONLINE ONLINE xxyyy1
ora....ER.lsnr ora....er.type ONLINE ONLINE xxyyy1
ora....N1.lsnr ora....er.type ONLINE ONLINE xxyyy2
ora....N2.lsnr ora....er.type ONLINE ONLINE xxyyy1
ora....N3.lsnr ora....er.type ONLINE ONLINE xxyyy1
ora.OCR.dg ora....up.type ONLINE ONLINE xxyyy1
ora.asm ora.asm.type ONLINE ONLINE xxyyy1
ora.cvu ora.cvu.type ONLINE ONLINE xxyyy1
ora.xxyyy.db ora....se.type ONLINE ONLINE xxyyy1
ora....rcl.svc ora....ce.type ONLINE ONLINE xxyyy1
ora....SM1.asm application ONLINE ONLINE xxyyy1
ora....S1.lsnr application ONLINE ONLINE xxyyy1
ora.xxyyy1.gsd application OFFLINE OFFLINE
ora.xxyyy1.ons application ONLINE ONLINE xxyyy1
ora.xxyyy1.vip ora....t1.type ONLINE ONLINE xxyyy1
ora....SM2.asm application ONLINE ONLINE xxyyy2
ora....S2.lsnr application ONLINE ONLINE xxyyy2
ora.xxyyy2.gsd application OFFLINE OFFLINE
ora.xxyyy2.ons application ONLINE ONLINE xxyyy2
ora.xxyyy2.vip ora....t1.type ONLINE ONLINE xxyyy2
ora.gsd ora.gsd.type OFFLINE OFFLINE
ora....network ora....rk.type ONLINE ONLINE xxyyy1
ora.oc4j ora.oc4j.type ONLINE ONLINE xxyyy1
ora.ons ora.ons.type ONLINE ONLINE xxyyy1
ora....ry.acfs ora....fs.type ONLINE ONLINE xxyyy1
ora.scan1.vip ora....ip.type ONLINE ONLINE xxyyy2
ora.scan2.vip ora....ip.type ONLINE ONLINE xxyyy1
ora.scan3.vip ora....ip.type ONLINE ONLINE xxyyy1
--//加入-t参数缺点是看到的name显示不全.为此网上有许多blog通过awk过滤更好的显示,我记录的脚本如下:
$ cat dba_crs
#!/bin/bash
#
# 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
RSC_KEY=$1
#export ORA_CRS_HOME=/orahomes/CRS
#export ORA_CRS_HOME=/u01/app/oracle/product/10.2.0/crs
export ORA_CRS_HOME=/u01/app/11.2.0.4/grid
QSTAT=-u
AWK=/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:
$ORACLE_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;}'
--//执行例子如下:
$ ./dba_crs
HA Resource Target State
-------------------------------------------- ------- -----------------
ora.DATA.dg ONLINE ONLINE on xxyyy1
ora.LISTENER.lsnr ONLINE ONLINE on xxyyy1
ora.LISTENER_SCAN1.lsnr ONLINE ONLINE on xxyyy2
ora.LISTENER_SCAN2.lsnr ONLINE ONLINE on xxyyy1
ora.LISTENER_SCAN3.lsnr ONLINE ONLINE on xxyyy1
ora.OCR.dg ONLINE ONLINE on xxyyy1
ora.asm ONLINE ONLINE on xxyyy1
ora.cvu ONLINE ONLINE on xxyyy1
ora.xxyyy.db ONLINE ONLINE on xxyyy1
ora.xxyyy.orcl.svc ONLINE ONLINE on xxyyy1
ora.xxyyy1.ASM1.asm ONLINE ONLINE on xxyyy1
ora.xxyyy1.LISTENER_xxyyy1.lsnr ONLINE ONLINE on xxyyy1
ora.xxyyy1.gsd OFFLINE OFFLINE
ora.xxyyy1.ons ONLINE ONLINE on xxyyy1
ora.xxyyy1.vip ONLINE ONLINE on xxyyy1
ora.xxyyy2.ASM2.asm ONLINE ONLINE on xxyyy2
ora.xxyyy2.LISTENER_xxyyy2.lsnr ONLINE ONLINE on xxyyy2
ora.xxyyy2.gsd OFFLINE OFFLINE
ora.xxyyy2.ons ONLINE ONLINE on xxyyy2
ora.xxyyy2.vip ONLINE ONLINE on xxyyy2
ora.gsd OFFLINE OFFLINE
ora.net1.network ONLINE ONLINE on xxyyy1
ora.oc4j ONLINE ONLINE on xxyyy1
ora.ons ONLINE ONLINE on xxyyy1
ora.registry.acfs ONLINE ONLINE on xxyyy1
ora.scan1.vip ONLINE ONLINE on xxyyy2
ora.scan2.vip ONLINE ONLINE on xxyyy1
ora.scan3.vip ONLINE ONLINE on xxyyy1
$ ./dba_crs ora.LISTENER_SCAN
HA Resource Target State
-------------------------------------------- ------- -----------------
ora.LISTENER_SCAN1.lsnr ONLINE ONLINE on xxyyy2
ora.LISTENER_SCAN2.lsnr ONLINE ONLINE on xxyyy1
ora.LISTENER_SCAN3.lsnr ONLINE ONLINE on xxyyy1
$ ./dba_crs | egrep "HA Resource |OFFLINE|^---"
HA Resource Target State
-------------------------------------------- ------- -----------------
ora.xxyyy1.gsd OFFLINE OFFLINE
ora.xxyyy2.gsd OFFLINE OFFLINE
ora.gsd OFFLINE OFFLINE
--//我的机器还有一个perl的脚本:
$ cat dba_crs.pl
#!/usr/bin/perl
$s=".";
if($#ARGV>=0){$s=$ARGV[0];chomp$s;}
printf("%-45s%-18s%-12s%-18s\n","HA Resource","TYPE","Target","State");
printf("%-45s%-18s%-12s%-18s\n","-----------","-----","------","-----");
open(CRS_STAT,"crs_stat -u|");
while($line=<CRS_STAT>)
{
if($line =~ m/=/)
{
chomp$line;
($n,$v)=split(/=/,$line);
if($n eq "NAME"){$name=$v;}
elsif($n eq "TYPE"){$type=$v;}
elsif($n eq "TARGET"){$target=$v;}
elsif($n eq "STATE")
{
$state=$v;
if($name=~ m/$s/)
{
printf("%-45s%-18s%-12s%-18s\n",$name,$type,$target,$state);
}
}
}
}
--//这样显示更加清晰.不过从11g开始已经使用crsctl取代crs_stat这个命令.
$ crsctl status resource -t
$ crsctl status res -t
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.DATA.dg
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
ora.LISTENER.lsnr
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
ora.OCR.dg
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
ora.asm
ONLINE ONLINE xxyyy1 Started
ONLINE ONLINE xxyyy2 Started
ora.gsd
OFFLINE OFFLINE xxyyy1
OFFLINE OFFLINE xxyyy2
ora.net1.network
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
ora.ons
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
ora.registry.acfs
ONLINE ONLINE xxyyy1
ONLINE ONLINE xxyyy2
--------------------------------------------------------------------------------
Cluster Resources
--------------------------------------------------------------------------------
ora.LISTENER_SCAN1.lsnr
1 ONLINE ONLINE xxyyy2
ora.LISTENER_SCAN2.lsnr
1 ONLINE ONLINE xxyyy1
ora.LISTENER_SCAN3.lsnr
1 ONLINE ONLINE xxyyy1
ora.cvu
1 ONLINE ONLINE xxyyy1
ora.xxyyy.db
1 ONLINE ONLINE xxyyy1 Open
2 ONLINE ONLINE xxyyy2 Open
ora.xxyyy.orcl.svc
1 ONLINE ONLINE xxyyy1
ora.xxyyy1.vip
1 ONLINE ONLINE xxyyy1
ora.xxyyy2.vip
1 ONLINE ONLINE xxyyy2
ora.oc4j
1 ONLINE ONLINE xxyyy1
ora.scan1.vip
1 ONLINE ONLINE xxyyy2
ora.scan2.vip
1 ONLINE ONLINE xxyyy1
ora.scan3.vip
1 ONLINE ONLINE xxyyy1
--//oracle的crsctl区分开Local Resources以及Cluster Resources,name单独显示一行,解决这个问题.
--//感觉oracle设计这个命令按照80列显示宽度来设计的.
--//另外crsctl status resource还增加-w参数过滤,这样可以更快看到那些资源OFFLINE.
$ crsctl status resource -h
Usage:
crsctl status resource [<resName>[...]|-w <filter>] [<-p|-v> [-e]] | [[-f|-l|-g]] | [[-k <cid>|-n <server>] [-d <did>]] | [-s -k <cid> [-d <did>]]
Check status of designated resources
crsctl status resource [<resName>[...]|-w <filter>] -t
Print status of resources in tabular format
crsctl status resource [<resName>[...]] -dependency [-stop | -pullup]
Print resource dependencies
where
resName [...] One or more blank-separated resource names
-w Resource filter (e.g., "TYPE = ora.database.type")
-p Print static configuration
-v Print runtime configuration
-e Evaluate a resource instance's special values
-f Print full configuration
-l Print all cardinal and degree members
-g Check if resources are registered
-k Cardinality ID
-d Degree ID
-n Server name
-s Get target servers for relocation
-t Tabular display
-dependency Display resource dependencies, default is start dependencies
-stop Display resource stop dependencies
-pullup Display resource pullup dependencies
$ crsctl stat res -t -w "((TARGET != ONLINE) or (STATE != ONLINE)) "
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.gsd
OFFLINE OFFLINE xxyyy1
OFFLINE OFFLINE xxyyy2
$ crsctl stat res -t -w "((TARGET != ONLINE) or (STATE != ONLINE)) and (TYPE != ora.gsd.type)"
--//注意一点TARGET,STATE,TYPE大写.
$ crsctl stat res -t -w "name = ora.gsd"
--//没有输出.
$ crsctl stat res -t -w "NAME = ora.gsd"
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.gsd
OFFLINE OFFLINE xxyyy1
OFFLINE OFFLINE xxyyy2
$ crsctl stat res -t -w "TARGET = offline"
--//没有输出.
$ crsctl stat res -t -w "TARGET = OFFLINE"
--------------------------------------------------------------------------------
NAME TARGET STATE SERVER STATE_DETAILS
--------------------------------------------------------------------------------
Local Resources
--------------------------------------------------------------------------------
ora.gsd
OFFLINE OFFLINE xxyyy1
OFFLINE OFFLINE xxyyy2
--//还有注意 = 两边留空.
$ crsctl stat res -t -w "TARGET=OFFLINE"
CRS-2594: Filter specification 'TARGET=OFFLINE' is invalid
Sample filters:
1. TYPE = type1
2. ((TYPE = type1) AND (CHECK_INTERVAL > 50))
3. (TYPE = type1) AND ((CHECK_INTERVAL > 30) OR (AUTO_START co never))
Filter Operators: =, >, <, !=, co, st, en
Sample command: crsctl status res -w "TYPE = type1"
CRS-4000: Command Status failed, or completed with errors.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-2643598/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/267265/viewspace-2643598/