Oracle集群检测命令
阅读原文时间:2023年07月14日阅读:1

select inst_id, count(inst_id) from gv$session group by inst_id order by inst_id;

srvctl stop database -d racdb(数据库名) -o immediate 关闭数据库关闭集群中的实例所有节点

su - grid

查看所有节点状态
olsnodes -s

检查集群中各组件状态 每个组件都应该是online
crsctl check cluster -all

查看SCAN监听器
ps -ef |grep -f scan
srvctl status scan_listener

查看集群资源
crsctl stat res -t

ASM实例查询
ps -ef |grep -i asm
srvctl config asm
srvctl status asm

检查数据库当前配置
srvctl config database -d racdb(数据库名) -a

srvctl status database -d racdb -f -v

调整ASM SGA
su - grid
sqlplus / as sysasm
alter 修改
startup force;重启asm实例

调整数据库实例 SGA

su - oracle
sqlplus / as sysdba
alter system 修改
srvctl stop instance -d racdb(数据库名) -i racdb1(数据库实例名)
srvctl start instance -d racdb(数据库名) -i racdb1(数据库实例名)

集群的启动(root用户执行)
一步到位启动当前节点的CRS
crsctl start crs
二步走
crsctl start has(启动OHASD进程)
crsctl start cluster

crsctl start crs 管理本地节点
crsctl start cluster启动任何节点CRS服务
crsctl start cluster需要其它节点OHASD进程运行

集群的关闭(root用户执行)
一步到位关闭当前节点的CRS
crsctl stop crs
二步走
crsctl stop has(启动OHASD进程)
crsctl stop cluster

检查整个集群资源
olsnodes -s
crsctl check cluster
crsctl check cluster -all
crsctl check crs
crsctl stat res -t
crsctl status resource -t -init

重启网络服务
service network restart
停止CRS残留进程
ps -ef |grep ora |awk '{print $2}' |xargs kill -9
ps -ef |grep grid |awk '{print $2}' |xargs kill -9
ps -ef |grep asm |awk '{print $2}' |xargs kill -9
ps -ef |grep storage |awk '{print $2}' |xargs kill -9
ps -ef |grep grid
ps -ef |grep ora
ps -ef |grep asm
ps -ef |grep crs

--------------------------------------------
--------
--------本文件只是为了方便大家进行命令拷贝
--------使用时请进行相应的替换和修改
--------
--------------------------------------------

cat /etc/inittab
more /etc/init.d/ohasd
cd /etc/rc.d/rc5.d
ls -al *hasd*
ps -ef |grep ohasd.bin
$GRID_HOME/log/`hostname`/ohasd/ohasd.log
OLR
查找
ll |grep ha

crsctl status resource -init -t

cat /etc/oracle/scls_scr/`hostname`/root/ohasdstr
crsctl disable crs
cat /etc/oracle/scls_scr/`hostname`/root/ohasdstr
crsctl enable crs

$GRID_HOME/log/`hostname`/agent/ohasd/
$GRID_HOME/log/`hostname`/ohasd/oracssdagent_root
ll $GRID_HOME/log/`hostname`/agent/crsd

$GRID_HOME/log/`hostname`/crsd/crsd.log

ps -ef |grep agent|grep -v root

/taryartar/12c/grid_home/log/rac1/agent

cssdagent, cssdmonitor, oraagent, and oraagent_root.

SQL> alter system set sga_max_size=500M scope=spfile;
SQL> startup force;

crsctl status resource -t -init

$GRID_HOME/log/`hostname`/agent/crsd
$GRID_HOME/log/`hostname`/agent/crsd

ASM Instance

crsctl status server -f

crsctl status resource -t -init

crsctl start crs
crsctl check crs
crsctl stat res -t
crsctl status resource -t -init

crsctl start has
crsctl status resource -t -init
crsctl start cluster
crsctl status resource -t -init
crsctl start cluster
crsctl check crs
crsctl stat res -t
crsctl status resource -t -init

===停止集群===
crsctl stop crs
crsctl stop crs -f
crsctl check crs
crsctl stat res -t
crsctl status resource -t -init

ps -ef |grep ora |awk '{print $2}' |xargs kill -9
ps -ef |grep grid |awk '{print $2}' |xargs kill -9
ps -ef |grep asm |awk '{print $2}' |xargs kill -9
ps -ef |grep storage |awk '{print $2}' |xargs kill -9
ps -ef |grep grid
ps -ef |grep ora
ps -ef |grep asm
ps -ef |grep storage

ifconfig -a

service network restart

crsctl stop cluster
crsctl check has
ps -ef |grep has
crsctl stop has
ifconfig -a
service network restart

crsctl status resource -t -init
crsctl check crs
crsctl stat res -t

ps -ef |grep ora |awk '{print $2}' |xargs kill -9
ps -ef |grep grid |awk '{print $2}' |xargs kill -9
ps -ef |grep asm |awk '{print $2}' |xargs kill -9
ps -ef |grep storage |awk '{print $2}' |xargs kill -9
ps -ef |grep grid
ps -ef |grep ora
ps -ef |grep asm
ps -ef |grep crs

Stop cluster will shutdown across all nodes and will NOT shutdown HAS – crsctl stop cluster
===启动集群===
crsctl start crs
crsctl check crs
crsctl check has
crsctl stat res -t
crsctl status resource -t -init

ps -ef |grep grid
ps -ef |grep ora
ps -ef |grep asm

ifconfig -a

CRS-4639: Could not contact Oracle High Availability Services
CRS-4535: Cannot communicate with Cluster Ready Services
CRS-4530: Communications failure contacting Cluster Synchronization Services
daemon
CRS-4534: Cannot communicate with Event Manager

crsctl start has
crsctl status resource -t -init
crsctl check crs

crsctl start cluster -h
crsctl start cluster # Start CRS stack
crsctl start cluster -all
crsctl status resource -t -init
crsctl check crs
crsctl stat res -t

ps -ef |grep grid
ps -ef |grep ora
ps -ef |grep asm

ifconfig -a

olsnodes -s
crsctl check cluster
crsctl check cluster -all
crsctl check crs
crsctl stat res -t

cat $ORACLE_BASE/diag/rdbms/"$DB_UNIQUE_NAME"/"$ORACLE_SID"/trace/"alert_${ORACLE_SID}.log" |grep -i asm

SELECT instance_name, db_name, status FROM V$ASM_CLIENT;
SELECT INSTANCE_NAME FROM V$ASM_CLIENT;

[root]# /u01/app/grid/bin/crsctl start crs
CRS-4123: Oracle High Availability Services has been started.
只表示 开始启动 并不表示成功,成功还要花很长时间

===表决盘的管理
asmcmd lsdg
crsctl query css votedisk
表决盘迁移到ocfs
crsctl replace votedisk /myocfs1/storage/vd6C
表决盘迁移到ASM
crsctl replace votedisk +DG1

crsctl query css votedisk
添加表决盘,如果表决盘存放在ASM中,则表决文件的镜像由磁盘组完成,不再需要另外一个磁盘组做镜像。
不允许表决盘同时存在ASM和集群文件系统中
crsctl add css votedisk /myocfs1/vdfile5
crsctl add css votedisk +DG2
crsctl add css votedisk /myocfs1/storage/vd5
crsctl query css votedisk

crsctl query css votedisk
crsctl delete css votedisk afb49b9a67304f9ebfaf4278c2eeeb71

===OCR
ocrcheck

touch /myocfs1/ocr_mirror1
chown root:oinstall /myocfs1/ocr_mirror1
chmod 640 /myocfs1/ocr_mirror1

ocrconfig -add /myocfs1/ocr_mirror1
ocrconfig -add +DG2
ocrconfig -delete /myocfs1/ocr_mirror1
ocrconfig -delete +DG2

touch /myocfs1/ocr_new
chown root:oinstall /myocfs1/ocr_new
chmod 640 /myocfs1/ocr_new

OCR替换
touch /myocfs1/ocr_new
chown root:oinstall /myocfs1/ocr_new
chmod 640 /myocfs1/ocr_new
ocrconfig -replace /myocfs1/ocr_mirror1 -replacement /myocfs1/ocr_new
ASM中不用创建文件
ocrconfig -replace /myocfs1/ocr_new -replacement +DG1
ocrconfig -replace +DG1 -replacement /myocfs1/ocr_new

OCR备份
ocrconfig -manualbackup
ocrconfig -showbackup
dump备份的ocr文件,会生成一个文件,查看生成文件
ocrdump -backupfile /taryartar/12c/grid_home/cdata/mycluster/backup_20150520_231258.ocr

导出ocr文件,文件名ocrEXP
ocrconfig -export ocrEXP
ocrconfig -import ocrEXP

ocr恢复关系
ocrconfig -manualbackup and ocrconfig -restore
ocrconfig -export and ocrconfig -import

===ocr voting disk 恢复试验(集群文件系统)======

检查ocr文件位置
ocrcheck
/myocfs1/ocr_new
检查表决盘位置
crsctl query css votedisk
/myocfs1/storage/vd6B
手动备份ocr
ocrconfig -manualbackup
/taryartar/12c/grid_home/cdata/mycluster/backup_20150521_152003.ocr
ocrconfig -showbackup

删除
rm -rf /myocfs1/ocr_new
rm -rf /myocfs1/storage/vd6B
查看ocr和表决盘是否存在
ocrcheck
crsctl query css votedisk

####恢复#####
首先查看集群的节点数目
olsnodes
每个节点上面强行关闭
crsctl stop crs -f
sudo su - grid关闭实例,两个节点执行
sqlplus / as sysasm
SQL> shutdown abort;
ps -ef |grep ora|awk '{print $2}'|xargs kill -9
ps -ef |grep asm|awk '{print $2}'|xargs kill -9
ps -ef |grep grid|awk '{print $2}'|xargs kill -9

ocr的恢复
ocrconfig -showbackup

on one node
ll /myocfs1/ocr_new
创建文件
touch /myocfs1/ocr_new
chown root:oinstall /myocfs1/ocr_new
chmod 640 /myocfs1/ocr_new
ll /myocfs1/ocr_new
从备份中恢复
ocrconfig -restore /taryartar/12c/grid_home/cdata/mycluster/backup_20150521_152003.ocr
ll /myocfs1/ocr_new
ocrcheck

on one node
启动集群,将集群启动到排他模式,在排他模式可以重建表决盘
crsctl start crs -excl
crsctl query css votedisk
如果原来的文件可以用,可以使用replace替换
crsctl replace votedisk /myocfs1/storage/vd6B
如果原来的文件不可用,可以新增加表决盘
crsctl add css votedisk /myocfs1/storage/vd6C
crsctl query css votedisk

crsctl stop crs -f

正式的启动集群,每个节点都执行
crsctl start crs
cluvfy comp ocr -n all -verbose
cluvfy comp vdisk -n all -verbose
crsctl check cluster -all

crsctl stat res -t

检查ocr和votedisk的完整新
cluvfy comp ocr -n all -verbose
cluvfy comp vdisk -n all -verbose

===ocr voting disk 恢复试验(ASM篇)======
ocrcheck
crsctl query css votedisk

COLUMN PATH FORMAT A20;
SET LINESIZE 500
select dg.NAME as disk_group,d.NAME,MOUNT_STATUS,HEADER_STATUS,MODE_STATUS,PATH from V$ASM_DISK d ,V$ASM_DISKGROUP dg
where d.GROUP_NUMBER=dg.GROUP_NUMBER
order by dg.NAME;

破坏
dd if=/dev/zero of=/dev/raw/raw3 bs=1024k count=1

#####恢复#####
olsnodes
crsctl stop crs -f
sudo su - grid关闭实例
sqlplus / as sysasm
SQL> shutdown abort;
ps -ef |grep ora|awk '{print $2}'|xargs kill -9
ps -ef |grep asm|awk '{print $2}'|xargs kill -9
ps -ef |grep grid|awk '{print $2}'|xargs kill -9

on one node
crsctl start crs -excl -nocrs (表示不启动crsd进程)
crsctl stop resource ora.crsd -init

sudo su - grid
select name,state from v$asm_diskgroup;
drop diskgroup dg1 force including contents;

重建磁盘组
create diskgroup dg1
external redundancy
disk
'/dev/raw/raw3' name nr_1;

ALTER DISKGROUP dg1 SET ATTRIBUTE 'compatible.asm' = '12.1.0.0.0' ;
ALTER DISKGROUP dg1 SET ATTRIBUTE 'compatible.rdbms' = '12.1.0.0.0';
ALTER DISKGROUP dg1 SET ATTRIBUTE 'compatible.advm' = '12.1.0.0.0';

drop diskgroup dg1 force including contents;

ocrconfig -showbackup
重启一下集群,crsctl stop/start crs,再执行还原
ocrconfig -restore /taryartar/12c/grid_home/cdata/mycluster/backup00.ocr
ocrcheck

表决盘恢复
crsctl query css votedisk
将表决盘恢复到+dg1,也可以恢复到其他磁盘组
crsctl replace votedisk +dg1
crsctl query css votedisk
crsctl stop crs -f

crsctl start crs

crsctl check cluster -all
crsctl stat res -t
cluvfy comp ocr -n all -verbose
cluvfy comp vdisk -n all -verbose

====本地注册表=================
ll $GRID_HOME/cdata/"`hostname`.olr"
ocrcheck -local
ocrdump -local -stdout
ocrconfig -local -manualbackup
ocrconfig -local -showbackup
ocrdump -local -backupfile /taryartar/12c/grid_home/cdata/rac1/backup_20150521_172006.olr

ocrconfig -local -backuploc /taryartar/12c/grid_home

ocrconfig -local -export olr_dump
ocrconfig -local -import olr_dump

ocrconfig -local -restore file_name
ocrconfig -local -manualbackup

--还原OLR:
ocrcheck -local
/taryartar/12c/grid_home/cdata/rac1.olr

ocrconfig -local -showbackup
/taryartar/12c/grid_home/backup_20150521_172440.olr

ocrconfig -local -manualbackup

rm -rf 模拟本地注册表丢失
crsctl stop crs -f
ps -ef |grep ora|awk '{print $2}'|xargs kill -9
ps -ef |grep asm|awk '{print $2}'|xargs kill -9
ps -ef |grep grid|awk '{print $2}'|xargs kill -9

hostname
touch /taryartar/12c/grid_home/cdata/rac1.olr
chmod 600 /taryartar/12c/grid_home/cdata/rac1.olr
chown root:oinstall /taryartar/12c/grid_home/cdata/rac1.olr

执行恢复
ocrconfig -local -restore /taryartar/12c/grid_home/backup_20150521_172440.olr
ocrcheck -local

crsctl start crs
crsctl check cluster -all
crsctl stat res -t
cluvfy -local comp olr

=================公有网络管理==========

--SCAN监听器
cluvfy comp scan -verbose
srvctl config scan_listener
srvctl status scan_listener
crsctl status resource ora.scan1.vip -p

srvctl stop scan_listener
srvctl status scan_listener
ps -ef |grep -i scan
srvctl start scan_listener

--
ifconfig -a |grep inet
ps -ef |grep -i scan
srvctl relocate scan -i 1 -n rac2

SCAN VIP
192.168.0.61---》 192.168.0.71
192.168.0.62---》 192.168.0.72
192.168.0.63---》 192.168.0.73
VIP
192.168.0.55---》 192.168.0.74
192.168.0.56---》 192.168.0.75

srvctl stop service -d tar
ifconfig -a |grep inet
srvctl stop scan_listener
srvctl stop scan
停止节点普通的监听器和普通vip
srvctl stop listener -n rac1
srvctl stop listener -n rac2
srvctl stop vip -n rac1
srvctl stop vip -n rac2
ifconfig -a |grep inet

nslookup myscan
srvctl config scan
srvctl config vip -n rac1

DNS服务器
cat /etc/named.conf
修改正向和反向解析文件
cp /var/named/192.168.0.db /var/named/192.168.0.dbBK
cp /var/named/taryartar.com.db /var/named/taryartar.com.dbBK

sed -i 's/61/71/' /var/named/taryartar.com.db
sed -i 's/62/72/' /var/named/taryartar.com.db
sed -i 's/63/73/' /var/named/taryartar.com.db
sed -i 's/55/74/' /var/named/taryartar.com.db
sed -i 's/56/75/' /var/named/taryartar.com.db

sed -i 's/61/71/' /var/named/192.168.0.db
sed -i 's/62/72/' /var/named/192.168.0.db
sed -i 's/63/73/' /var/named/192.168.0.db
sed -i 's/55/74/' /var/named/192.168.0.db
sed -i 's/56/75/' /var/named/192.168.0.db

cat /var/named/taryartar.com.db
cat /var/named/192.168.0.db

cp /var/named/192.168.0.dbBK /var/named/192.168.0.db
cp /var/named/taryartar.com.dbBK /var/named/taryartar.com.db

nslookup myscan
service named reload
nslookup myscan

srvctl config scan
srvctl modify scan -n myscan
srvctl config scan

srvctl config vip -n rac1
srvctl modify nodeapps -n rac1 -A 192.168.0.74/255.255.255.0/bond0
srvctl modify nodeapps -n rac2 -A 192.168.0.75/255.255.255.0/bond0
srvctl config vip -n rac1

srvctl start vip -n rac1
srvctl start listener -n rac1
lsnrctl status

srvctl start scan
srvctl start scan_listener

cluvfy comp nodecon -n all -verbose

==SCAN 端口号的修改=========
srvctl config scan_listener
srvctl modify scan_listener -p 1528
srvctl stop scan_listener
srvctl start scan_listener
ps -ef |grep -i scan
lsnrctl status LISTENER_SCAN1
alter system set remote_listener ='myscan:1528' scope=both;
lsnrctl status LISTENER_SCAN3

======私有IP的修改=========
oifcfg getif
oifcfg iflist
crsctl stop crs
ifconfig -a |grep -C1 eth2
10.0.10.1
crsctl stop crs
vi /etc/sysconfig/network-scripts/ifcfg-eth2
service network restart
oifcfg setif -global eth2/10.0.0.0:cluster_interconnect

ps -ef |grep ora |awk '{print $2}' |xargs kill -9
ps -ef |grep grid |awk '{print $2}' |xargs kill -9
ps -ef |grep asm |awk '{print $2}' |xargs kill -9
ps -ef |grep storage |awk '{print $2}' |xargs kill -9
ps -ef |grep ohasd |awk '{print $2}' |xargs kill -9

crsctl start crs

--------------------------------------------
--------
--------本文件只是为了方便大家进行命令拷贝
--------使用时请进行相应的替换和修改
--------
--------------------------------------------

=============数据库管理==============

srvctl start instance -d tar -n rac2
srvctl status database -d tar -f -v
srvctl stop database -d tar

show parameter spfile;
show parameter parallel_max_servers;

create spfile='+DG_ZERO/zerodb/spfilezerodb.ora' from pfile='/zerodb/11g/db_base/db_home/dbs/initzero.ora'

*.parallel_max_servers =40
tar2.parallel_max_servers=42

show parameter parallel_max_servers;
alter system set parallel_max_servers=42 sid='*' scope=both;
alter system set parallel_max_servers=42 scope=both;
alter system set parallel_max_servers=42 sid='tar2' scope=both;
show parameter parallel_max_servers;

create user c##test identified by Xtyt2008;
grant dba to c##test;

select inst_id, sid, serial#,USERNAME from gv$session;
alter system kill session '85, 90,@2';

column name format a20;
column value format a20;
select inst_id,name,value from gv$parameter where name like '%undo_tablespace%';

CREATE UNDO TABLESPACE UNDOTBS_TYT
DATAFILE '+DATA/TAR/DATAFILE/TYT.db' SIZE 900M AUTOEXTEND ON;

alter system set UNDO_TABLESPACE=UNDOTBS_TYT sid='tar2' scope=both;

select inst_id,name,value from gv$parameter where name like '%undo_tablespace%';

select GROUP#,thread# from v$log;

column MEMBER format a50;
select group#,status,member from v$logfile order by GROUP#;

不要使用gv$log,gv$logfile,其列出的信息是冗余的,容易误导
select thread#,group# from gv$log;
select INST_ID,group#,member from gv$logfile;

ALTER DATABASE
ADD LOGFILE INSTANCE 'tar1'
GROUP 6
('+DATA/TAR/ONLINELOG/redo_z111','+DATA/TAR/ONLINELOG/redo_z222') SIZE 50M reuse;

ALTER DATABASE DROP LOGFILE GROUP 5;

====负载均衡测试
srvctl config scan_listener
lsnrctl status

配置tnsnames.ora
tyt_normal=
(DESCRIPTION =
(FAILOVER = ON)
(LOAD_BALANCE = ON)
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.74)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.75)(PORT=1521))
(CONNECT_DATA =
(SERVICE_NAME = tar)
)
)

sqlplus system/Xtyt2008@tyt_fo

tyt_scan=
(DESCRIPTION =
(ADDRESS=(PROTOCOL=tcp)(HOST=myscan)(PORT=1528))
(CONNECT_DATA =
(SERVICE_NAME = tar)
)
)

sqlplus system/Xtyt2008@tyt_normal

SELECT INSTANCE_NAME FROM V$INSTANCE;

====失败转移

MYFL =
(DESCRIPTION =
(FAILOVER = ON)
(LOAD_BALANCE = ON)
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.71)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.72)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.0.73)(PORT=1521))
(CONNECT_DATA =
(SERVICE_NAME = orcl_ac)
)
)

sqlplus system/Xtyt2008@MYFL

create table t_failover
as
select owner,object_name,object_id from dba_objects;

insert into t_failover
select owner,object_name,object_id from dba_objects;

sqlplus system/Xtyt2008@MYFL

SELECT INSTANCE_NAME FROM V$INSTANCE;
SELECT HOST_NAME FROM V$INSTANCE;
--1.idle
select sysdate from dual;

--2.long query
alter system flush buffer_cache;

column OWNER format a50;
select owner,COUNT(*) from
(
select * from system.t_failover
where object_id in (select object_id from system.t_failover ) and object_name not in (select owner from system.t_failover )
UNION ALL
select * from system.t_failover
where object_id in (select object_id from system.t_failover )
UNION ALL
select * from system.t_failover
where owner in (select owner from system.t_failover )
)
group by owner;

--3.DML
insert into system.t_failover values('system','LOGMNR_88888',88888);
select object_name from system.t_failover where object_name='LOGMNR_88888';

--4.new session

查看是否发生会话漂移
select
username,
sid,
serial#,
failover_type,
failover_method,
failed_over
from
gv$session
where
username not in ('SYS','PERFSTAT')
and
failed_over = 'YES';

SELECT MACHINE, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER, COUNT(*)
FROM GV$SESSION
GROUP BY MACHINE, FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER;