4.1 空间及磁盘路径
--ASM磁盘组使用情况 used_percent, asm实例无法使用计算
col name format a15
set lines 200
with temp_asm as (select name,trunc(free_mb/1024,2) free_gb,trunc(total_mb/1024,2) total_gb,trunc(REQUIRED_MIRROR_FREE_MB/1024,2) req_free_gb,trunc(USABLE_FILE_MB/1024,2) uf_gb,type,state from v$asm_diskgroup)
select * from (
select t.*,trunc((total_gb-free_gb)/total_gb*100,2) as used_percent from temp_asm t where type='EXTERN' union all
select t.*,trunc(((total_gb-free_gb)/2)/((total_gb-req_free_gb)/2)*100,2) as used_percent from temp_asm t where type='NORMAL' union all
select t.*,trunc(((total_gb-free_gb)/3)/((total_gb-req_free_gb)/3)*100,2) as used_percent from temp_asm t where type='HIGH')
order by used_percent desc;
--or
select name,free_mb,total_mb,type,state from v$asm_diskgroup;
--检查磁盘信息
set pages 999
col path format a20;
col group_name format a15
col name format a20
col FAILGROUP_TYPE format a15
col FAILGROUP format a20
col state for a10
select a.group_number,b.name as group_name,a.FAILGROUP,a.name,a.path,a.state,a.total_mb from v$asm_disk a,v$asm_diskgroup b where a.group_number=b.group_number;
4.2 磁盘修复检查
#验证asm磁盘组
kfod asm_diskstring='/dev/mapper/*' disks=all
kfed read /dev/mapper/data1 |grep grpname
#asm 读取磁盘头
kfed read /dev/raw/raw2 text=/tmp/asmdisk_raw2.txt
kfed read /dev/raw/raw2 aun=0 blkn=0
kfed read /dev/raw/raw2 blkn=510 > /tmp/1.txt
kfed read /dev/raw/raw2 aun=1 blkn=254
#修复磁盘头
kfed write /dev/raw/raw2 aunum=0 blknum=0 text=/tmp/asmdisk_raw2.txt
#or
dd if=/dev/raw/raw2 of=/tmp/raw2.txt skip=510 bs=4096 count=1
dd if=/tmp/raw2.txt of=/dev/raw/raw2
4.3 ASM相关视图
View Name | X$ Table name | Description |
---|---|---|
V$ASM_DISKGROUP | X$KFGRP | performs disk discovery and lists diskgroups |
V$ASM_DISKGROUP_STAT | X$KFGRP_STAT | diskgroup stats without disk discovery |
V$ASM_DISK | X$KFDSK, X$KFKID | performs disk discovery, lists disks and their usage metrics |
V$ASM_DISK_STAT | X$KFDSK_STAT, X$KFKID | lists disks and their usage metrics |
V$ASM_FILE | X$KFFIL | lists ASM files, including metadata/asmdisk files |
V$ASM_ALIAS | X$KFALS | lists ASM aliases, files and directories |
V$ASM_TEMPLATE | X$KFTMTA | lists the available templates and their properties |
V$ASM_CLIENT | X$KFNCL | lists DB instances connected to ASM |
V$ASM_OPERATION | X$KFGMG | lists rebalancing operations |
N.A. | X$KFKLIB | available libraries, includes asmlib path |
N.A. | X$KFDPARTNER | lists disk-to-partner relationships |
N.A. | X$KFFXP | extent map table for all ASM files |
N.A. | X$KFDAT | extent list for all ASM disks |
N.A. | X$KFBH | describes the ASM cache (buffer cache of ASM in blocks of 4K (_asm_blksize) |
N.A. | X$KFCCE | a linked list of ASM blocks. to be further investigated |
4.4 ASM内部视图X$KFFXP
X$KFFXP是ASM(Automatic Storage Management)自动存储管理特性的重要内部视图,该视图反应了File Extent Map映射关系,ASM会将文件split成多个多个piece分片,这些分片被称为Extents。 在Disk上存放这些Extent的位置,就是我们常说的”Allocation Unit”。
KFF意为Kernel File,X$KFFXP即Kernel File Extent Maps, 该内部视图的一条记录代表一个Extent
字段含义如下:
GROUP_KFFXP diskgroup number (1 - 63) ASM disk group number. Join with v$asm_disk and v$asm_diskgroup
NUMBER_KFFXP file number for the extent ASM file number. Join with v$asm_file and v$asm_alias
COMPOUND_KFFXP (group_kffxp << 24) + file # File identifier. Join with compound_index in v$asm_file
INCARN_KFFXP file incarnation number File incarnation id. Join with incarnation in v$asm_file
PXN_KFFXP physical extent number Extent number per file
XNUM_KFFXP extent number bit 31 set if indirect Logical extent
number per file (mirrored extents have the same value)
LXN_KFFXP logical extent number 0,1 used to identify primary/mirror extent,
2 identifies file header allocation unit (hypothesis) used in the query such that
we go after only the primary extents, not secondary extents
DISK_KFFXP disk on which AU is located Disk number where the extent is allocated.
Join with v$asm_disk Relative position of the allocation unit from the beginning of the disk.
AU_KFFXP AU number on disk of AU allocation unit size (1 MB) in v$asm_diskgroup
#从11g开始加入了CHK_KFFXP SIZE_KFFXP 2个新的字段
CHK_KFFXP 未知 可能是范围为[0-256]的某种校验值
SIZE_KFFXP size_kffxp is used such that we account for variable sized extents.
sum(size_kffxp) provides the number of AUs that are on that disk.
在实例级别控制ASM Diskgroup AU 和 stripe size的是2个隐藏参数 _asm_ausize 1048576 以及 _asm_stripesize 131072。从11g开始一个Extent可能包含多个AU。
可以通过以下脚本查询文件与Extent等ASM属性的映射关系:
set linesize 140 pagesize 1400
col "FILE NAME" format a40
set head on
select NAME "FILE NAME",
NUMBER_KFFXP "FILE NUMBER",
XNUM_KFFXP "EXTENT NUMBER",
DISK_KFFXP "DISK NUMBER",
AU_KFFXP "AU NUMBER",
SIZE_KFFXP "NUMBER of AUs"
from x$kffxp, v$asm_alias
where GROUP_KFFXP = GROUP_NUMBER
and NUMBER_KFFXP = FILE_NUMBER
and system_created = 'Y'
and lxn_kffxp = 0
order by name;
4.5 条带化原理和rebalance
条带化
ASM的条带化有两种:coarse和fine-gained 。AU是最小空间分配单元,缺省是1M,每个AU缺省由8个128K条带空间组成。
- 在coarse条带化中,一个磁盘对应一个AU
所以该条带化适合连续的I/O读写,比如全表扫描表 - 在fine-gained条带化里,一个AU中的8个128K条带空间,平均打散在磁盘上
也就是说,4个磁盘,1个AU是平均分布在4个磁盘,每个磁盘2个128K
适合于对数据读写延迟比较敏感的文件。如redo日志,控制文件,spfile等
重平衡
从diskgroup中添加或删除disk时候,将触发RBAL进程创建rebalance计划、计算时间开销.而后、发消息给ARBn进程(ASM Reblance)处理该请求
ARBn进程对每个extents进行locked, relocated和unlocked操作,执行过程中可以参考v$asm_operation视图.
ARBn进程的数量由参数ASM_POWER_LIMIT决定,
COD (Continuting Operation Directory)用于记录rebalances情况
如果rebalance失败,在重启instance时候,将从COD读取记录,重新启动rebalance
注意事项:
-
rebalance仅仅在diskgroup发生改变时候才进行的,并不是定时执行
如果rebalance执行过程中,server宕机,重启后会自动进行rebalance -
每个disk的大小必须是相同,如果存在一个小盘,因为rebalance将对每个盘的分配相同比例的空间,可能造成rebalance时候空间不足
如果执行过程中,空闲空间不足,造成rebalance失败,将出现ORA-15041错误,需要再添加disk
如果需要频繁添加disk,每一次都可能造成数据的频繁移动,为提高效率,最好批量添加
如果磁盘大小一样,仍然没有进行rebalance,需要查看asm_power_limit
参考