比较好用的查看磁盘信息
1.
column PATh format a15
column FAILGROUP for a10
set linesize 228
column name format a10
col path for a20
select group_number, disk_number, OS_MB,name, mount_status, header_status,
mode_status, state, path, failgroup, mount_date, total_mb, free_mb,REPAIR_TIMER
from v$asm_disk order by group_number, disk_number;
2.
select GROUP_NUMBER,DISK_NUMBER,MOUNT_STATUS,STATE,NAME,FAILGROUP,PATH,VOTING_FILE from v$asm_disk_stat;
3.看磁盘组
select COMPATIBILITY,group_number,name,state,type from v$asm_diskgroup;
4.看vote(10g中ocr和vote是分开的,2 个group)
crsctl query css votedisk
5.看ocr(10g中ocr和vote是分开的,2 个group)
ocrcheck
视图(如果属组不对,disk会显示不出来):
v$asm_disk
v$asm_disk_stat
v$asm_diskgroup
10g
11g
ORA-15032: not all alterations performed
ORA-15283: ASM operation requires compatible.rdbms of 11.2.0.0.0 or higher (DBD ERROR: OCIStmtExecute)
1.查看版本
ASMCMD> lsattr -G OCRVT -l
Name Value
access_control.enabled FALSE
access_control.umask 066
au_size 1048576
cell.smart_scan_capable FALSE
compatible.asm 11.2.0.0.0
compatible.rdbms 10.1.0.0.0
disk_repair_time 3.6h
sector_size 512
2.修改版本
sqlplus / as sysasm
alter diskgroup data set attribute 'compatible.rdbms'='11.2.0.0.0';
3.查看修改后的版本
[grid@rac11gn2 ~]$ asmcmd
ASMCMD> lsattr -G OCRVT -l
Name Value
access_control.enabled FALSE
access_control.umask 066
au_size 1048576
cell.smart_scan_capable FALSE
compatible.asm 11.2.0.0.0
compatible.rdbms 11.2.0.0.0
disk_repair_time 3.6h
sector_size 512
建议操作ocr前留个asm的参数文件
看位置和db一样,就是grid下进sysdba或者sysasm,show parameter spfile
[root@rac1 bin]# su - grid
[grid@rac1 ~]$ sqlplus / as sysdba
SQL> create spfile='+OCRVOTE' from pfile='/oracle/grid/crs_1/dbs/asm_pfile.ora';
都做个ocr备份或者确认他有备份
检查ocr备份情况:
ocrconfig -showbackup(全部的备份)
ocrconfig -showbackup auto(自动的备份)
ocrconfig -showbackup manual(手动的备份)
ocr物理备份(物理恢复ocrconfig -restore /oracle/grid/backup_20210818_234406.ocr)
ocrconfig -manualbackup
ocr逻辑备份(逻辑恢复ocrconfig -import /tmp/ocr_bak)
ocrconfig -export /tmp/ocr_bak
查看ocr信息
crsctl query css votedisk
检查ocr备份情况:
ocrconfig -showbackup
备份ocr:
ocrconfig -manualbackup
关集群不行就加-f强制
/oracle/app/11.0.0/grid/bin/crsctl stop crs
独占模式起
/oracle/app/11.0.0/grid/bin/crsctl start crs -excl -nocrs
dd盘(2种方式轮着来)
dd if=/dev/zero of=/dev/udev/asm_sda_ocr bs=1048576 count=10
dd if=/dev/zero of=/dev/udev/asm_sdb_ocr bs=1048576 count=10
dd if=/dev/zero of=/dev/udev/asm_sdc_ocr bs=1048576 count=10
dd if=/dev/zero of=/dev/udev/asm_sda_ocr bs=8192 count=128000
dd if=/dev/zero of=/dev/udev/asm_sdb_ocr bs=8192 count=128000
dd if=/dev/zero of=/dev/udev/asm_sdc_ocr bs=8192 count=128000
建组,名字要和老的相同
create diskgroup VOT normal redundancy disk '/dev/asm_vote01','/dev/asm_vote02','/dev/asm_vote03' attribute 'compatible.rdbms'='11.2','compatible.asm'='11.2';
改路径(我感觉不改也行,一般默认是ok的)
alter system set asm_diskstring='/dev/asm_vote*','/dev/asm_data*';
恢复(备份片选上面ocrconfig -showbackup找到的)
/oracle/app/11.0.0/grid/bin/ocrconfig -restore /oracle/app/11.0.0/grid/cdata/his/backup00.ocr
确认vote
/oracle/app/11.0.0/grid/bin/crsctl query css votedisk
如果vote不存在
替换vote 文件
crsctl replace votedisk +OCRVT
再报错的话
路径选对,所有的都要包括
alter system set asm_diskstring='/dev/mapper/*';
替换成功
检查成功
退出独占模式:crsctl stop crs
重新开启集群:crsctl start crs
1.dd新的盘
dd if=/dev/zero of=/dev/mapper/mpathd bs=1M count=1024
2.创建新的ocr磁盘组(1节点)
create diskgroup VOT external redundancy disk '/dev/asm-diskd' attribute 'compatible.rdbms'='11.2','compatible.asm'='11.2';
3.2节点mount磁盘组
alter diskgroup VOT mount;
4.用ocrcheck查看ocr信息
[grid@ear1 ~]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2984
Available space (kbytes) : 259136
ID : 1650000229
Device/File Name : +OCR
Device/File integrity check succeeded
Device/File not configured
Device/File not configured
Device/File not configured
Device/File not configured
Cluster registry integrity check succeeded
Logical corruption check bypassed due to non-privileged user
5.新的磁盘组添加ocr
/oracle/grid/crs_1/bin/ocrconfig -add +VOT
6.用ocrcheck查看ocr信息
[grid@ear1 ~]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2980
Available space (kbytes) : 259140
ID : 1650000229
Device/File Name : +OCR
Device/File integrity check succeeded
Device/File Name : +VOT
Device/File integrity check succeeded
Device/File not configured
Device/File not configured
Device/File not configured
Cluster registry integrity check succeeded
Logical corruption check bypassed due to non-privileged user
7.查看vote信息
[grid@ear1 ~]$ crsctl query css votedisk
## STATE File Universal Id File Name Disk group
-- ----- ----------------- --------- ---------
1. ONLINE 9884ef58d7f64ff2bf0ac7302563830b (/dev/asm-diskb) [OCR]
Located 1 voting disk(s).
8.vote替换磁盘组
crsctl replace votedisk +VOT
9.再次查看vote信息
[grid@ear1 ~]$ crsctl query css votedisk
## STATE File Universal Id File Name Disk group
-- ----- ----------------- --------- ---------
1. ONLINE b0669b6b47b74f94bfe83061594de6d5 (/dev/asm-diskd) [VOT]
Located 1 voting disk(s).
10.查看集群状态
crsctl stat res -t
11.重建spfile(gi)
show parameter spfile;
create pfile='/tmp/asmpfile.ora' from spfile;
create spfile='+VOT' from pfile='/tmp/asmpfile.ora';
12.重启crs(cluster -all是2边同时关、开)(1边操作即可)
/oracle/grid/crs_1/bin/crsctl stop cluster -all
/oracle/grid/crs_1/bin/crsctl start cluster -all
13.确认spfile更改自动更改过
SQL> show parameter spfile;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
spfile string +VOT/ear-cluster/asmparameterf
ile/registry.253.1088567353
14.查看ocr.loc文件
[root@ear1 ~]# more /etc/oracle/ocr.loc
#Device/file getting replaced by device +VOT
ocrconfig_loc=+OCR
ocrmirrorconfig_loc=+VOT
local_only=false
15.删除旧ocr盘的ocr信息(1节点)
/oracle/grid/crs_1/bin/ocrconfig -delete +OCR
16.2节点dismount掉旧ocr磁盘组(如果先dismount再跑上一步,会报ORA-15027: active use of diskgroup "OCR" precludes its dismount)
alter diskgroup OCR dismount;
17.1节点删除磁盘组
drop diskgroup OCR including contents;
如果使用上述方法无法删除ocrvote磁盘组,采用强制删除的方法来完成(以下命令分别在一二节点执行):
alter diskgroup OCRVOTE dismount force;
drop diskgroup OCRVOTE including contents;
18.确认vote迁移完成
方法一、
[grid@ear1 ~]$ ocrcheck
Status of Oracle Cluster Registry is as follows :
Version : 3
Total space (kbytes) : 262120
Used space (kbytes) : 2960
Available space (kbytes) : 259160
ID : 1650000229
Device/File Name : +VOT
Device/File integrity check succeeded
Device/File not configured
Device/File not configured
Device/File not configured
Device/File not configured
Cluster registry integrity check succeeded
Logical corruption check bypassed due to non-privileged user
方法二、
[grid@ear1 ~]$ crsctl query css votedisk
## STATE File Universal Id File Name Disk group
-- ----- ----------------- --------- ---------
1. ONLINE b0669b6b47b74f94bfe83061594de6d5 (/dev/asm-diskd) [VOT]
Located 1 voting disk(s).
方法三、
[grid@ear1 ~]$ more /etc/oracle/ocr.loc
#Device/file +OCR getting replaced by device +VOT
ocrconfig_loc=+VOT
local_only=false
1.dd
dd if=/dev/zero of=/dev/mapper/mpathd bs=1M count=1024
2.创建磁盘组(1节点)
create diskgroup VOT external redundancy disk '/dev/asm-diskd' attribute 'compatible.rdbms'='11.2','compatible.asm'='11.2';
create diskgroup VOT normal redundancy disk '/dev/asm_vote01','/dev/asm_vote02','/dev/asm_vote03' attribute 'compatible.rdbms'='11.2','compatible.asm'='11.2';
3.2节点mount磁盘组
alter diskgroup VOT mount;
都在sqlplus / as sysasm里跑
1.先2节点dismount掉
alter diskgroup OCR_VOTING dismount
2.2节点查
select group_number,name,state,type from v$asm_diskgroup
0 OCR_VOTING DISMOUNTED
3.1节点查
select group_number,name,state,type from v$asm_diskgroup;
4 OCR_VOTING MOUNTED NORMAL
4.1节点删除盘
drop diskgroup OCR_VOTING including contents;
5.1节点再查
select group_number,name,state,type from v$asm_diskgroup;
如果使用上述方法无法删除ocrvote磁盘组,采用强制删除的方法来完成(以下命令分别在一二节点执行):
alter diskgroup OCRVOTE dismount force;
drop diskgroup OCRVOTE including contents;
1.先dd盘
dd if=/dev/zero of=/dev/mapper/mpathd bs=1M count=1024
2.添加disk
alter diskgroup OCRVT add disk '/dev/mapper/mpathe' rebalance power 11;
3.查看Rebanlance
select * from v$asm_operation;
其他:
Alter diskgroup data add failgroup cell01 disk ‘磁盘路径’
1.删除disk
用磁盘名,不要跟path!!!!!!!!!!!!!!!!
alter diskgroup OCR drop disk OCR_0001 rebalance power 11;
2.查看Rebanlance
select * from v$asm_operation;
但是加入不成功,无法读到drop的盘:
检查磁盘状态:
col name for a30
col VALUE for a10
col DESCRIB for a40
set lines 200
SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
FROM SYS.x$ksppi x, SYS.x$ksppcv y
WHERE x.inst_id = USERENV ('Instance')
AND y.inst_id = USERENV ('Instance')
AND x.indx = y.indx
AND x.ksppinm LIKE '%&par%';
12c中又新增了一个参数FAILGROUP_REPAIR_TIME(默认值24h),同样表示:如果一个FAILGROUP OFFLINE超过规定时间,那么也会被DROP掉。
修改11和12中的隐藏参数的格式
ALTER DISKGROUP data SET ATTRIBUTE 'disk_repair_time' = '4.5h';
ALTER DISKGROUP data SET ATTRIBUTE 'FAILGROUP_REPAIR_TIME' = '270m';
磁盘仍处在dropping的状态,原因是因为创建磁盘组是用了参数
' compatible.asm'='11.2',开启了11g中ASM新特性:快速镜像同步以及参数disk_repair_time,详见如下解释:
在Oracle Database 11g以前,如果ASM磁盘的损坏,那就是一种灾难,即使你的ASM磁盘组是受Normal Redundancy或High Redundancy的保护。
因为在Oracle 10g中,损坏的ASM磁盘会马上offline,进而这个损坏的磁盘立刻会被Oracle drop掉。
为了避免这个问题,Oracle 在11g里引入了一个参数disk_repair_time,其默认值是3.6小时并且用户可以修改。
这个参数的单位可以是分钟(m or M)或者是小时(h or H)。 如果我们在指定属性时没有指定单位,那么默认单位是小时。
该属性只能通过ALTER 命令来进行修改。
当损坏的磁盘offline后,Oracle并不会马上将其drop,而是会等待参数disk_repair_time所表示的时间。
在这段时间内,Oracle会记录下对损坏的磁盘上的extent所做的修改,一旦这个offline的损坏的磁盘在disk_repair_time所表示的时间内重新online,则Oracle会将之前所记录的对这个磁盘上extent所做的修改重新同步到这块盘上,从而高效地同步了数据(因为这里只同步了offline后修改的extent上的数据),避免了极为耗时的重构全部数据的rebalance过程。
这个过程就是11g中的:快速镜像同步(Fast Mirror Reync),必须将磁盘组的COMPATIBLE.ASM的属性值设置大于11.1。
当出现disk 出现故障被offline 后,我们可以查看V$ASM_DISK视图的REPAIR_TIMER。 该列显示的是disk 被drop 之前的剩余时间,单位是秒。
一旦超过disk_repair_time指定的时间,disk 就会被drop 掉。那么我们就需要进行rebalance操作,而不能进行快速镜像同步。
查看drop 之前的剩余时间:
SQL> col name for a15
SQL>select disk_number,name,path,MODE_STATUS,REPAIR_TIMER from v$asm_disk where group_number=X;
ASM_POWER_LIMIT参数为rebalance并发参数,默认为1,设置为0就禁止rebalance(并行参数可以0-1024,越大越快)
Alter system set asm_power_limit=2 scope=both sid='*';
Show parameter asm_power_limit
查看rebalance进度看以下
v$asm_operation的STAT和EST_MINUTES(剩余时间)(影响是个综合考量,主要是磁盘相关负载)
rebalance的三个阶段
1.rebalance plan阶段
计算出rebalance的计划,会根据磁盘大小个数,磁盘吞吐,au大小等计算出大致计划,该过程一般只需几分钟。
2.extent relocating阶段
真正进行重平衡的过程,将extent均匀的分配在各个磁盘中。该过程通常是整个rebalance最耗时的过程。
3.compacting阶段
asm11.1.0.7以上才开始支持,将磁盘上存的数据尽可能的移动到磁盘的外圈磁道上去(机械盘的外圈速度更快),花费时间较少。
如果添加磁盘,删减磁盘时没带上自动rebalance的参数,就需要手动rebalance
1.手动rebalance
alter diskgroup data_dg rebalance power 5;
1 SQL> select group_number,operation,state,power from v$asm_operation;
2
3 GROUP_NUMBER OPERA STAT POWER
4 ------------ ----- ---- ----------
5 1 REBAL RUN 5
2.暂停rebalance
1 SQL> alter diskgroup data_dg rebalance power 0;
2
3 Diskgroup altered.
4
5 SQL> select group_number,operation,state,power from v$asm_operation;
6
7 GROUP_NUMBER OPERA STAT POWER
8 ------------ ----- ---- ----------
9 1 REBAL WAIT 0
3.继续rebalance
1 SQL> alter diskgroup data_dg rebalance power 8;
2
3 Diskgroup altered.
4
5 SQL> select group_number,operation,state,power from v$asm_operation;
6
7 GROUP_NUMBER OPERA STAT POWER
8 ------------ ----- ---- ----------
9 1 REBAL RUN 8
4.查看
1 SQL> select group_number,operation,state,power from v$asm_operation;
2
3 no rows selected