normal冗余的ASM磁盘,数据只能保留两份,即使有三个失败组,也是如此,数据的分布是基于磁盘的partner关系,virtual extent是ASM的小逻辑分配单位,而AU是小的物理分配单位,我们通过测试分析冗余关系,以及数据存储的数据块再ASM磁盘的位置。
创建normal冗余的磁盘组data1 ,它包含两个失败组 data1_fg1和data1_fg2 .每个失败组两块磁盘
create diskgroup data1 normal redundancy
failgroup data1_fg1 disk '/dev/sde1' name disk1,'/dev/sdf1' name disk2
failgroup data1_fg2 disk '/dev/sdg1' name disk3, '/dev/sdh1' name disk4;
QL> select group_number,name,path,mount_status, state from v$asm_disk where group_number=3;
GROUP_NUMBER NAME PATH MOUNT_STATUS STATE
------------ -------------------- -------------------- --------------------- ------------------------
3 DISK4 /dev/sdh1 CACHED NORMAL
3 DISK3 /dev/sdg1 CACHED NORMAL
3 DISK2 /dev/sdf1 CACHED NORMAL
3 DISK1 /dev/sde1 CACHED NORMAL
SQL>select name,TOTAL_MB,FREE_MB,REQUIRED_MIRROR_FREE_MB,OFFLINE_DISKS,COMPATIBILITY,DATABASE_COMPATIBILITY from v$asm_diskgroup where group_number=3
NAME TOTAL_MB FREE_MB REQUIRED_MIRROR_FREE_MB OFFLINE_DISKS COMPATIBILITY DATABASE_COMPATIBILI
-------------------- ---------- ---------- ----------------------- ------------- -------------------- -------------------------- ---------------------------------
DATA1 4092 3982 2046 0 11.2.0.2.0 10.1.0.0.0
查磁盘组中失败组的磁盘的partner关系
SQL> select grp "Group#",disk "Disk#",NUMBER_KFDPARTNER "Partner Disk#",PARITY_KFDPARTNER,ACTIVE_KFDPARTNER
from x$kfdpartner where grp=3;
Group# Disk# Partner Disk# PARITY_KFDPARTNER ACTIVE_KFDPARTNER
---------- ---------- ------------- ----------------- -----------------
3 0 3 1 1 <<<<失败组DATA1_FG1的盘disk0对应的partner为DATA1_FG2 的disk2 和disk3
3 0 2 1 1
3 1 2 1 1
3 1 3 1 1
3 2 1 1 1
3 2 0 1 1
3 3 0 1 1
3 3 1 1 1
8 rows selected.
磁盘号对应的ASM磁盘和失败组信息
col name for a20
col path for a20
col failgroup for a20
SQL> select failgroup,name,path,disk_number from v$asm_disk where group_number=3;
FAILGROUP NAME PATH DISK_NUMBER
-------------------- -------------------- ----------------------------- ---------------------
DATA1_FG2 DISK4 /dev/sdh1 3
DATA1_FG2 DISK3 /dev/sdg1 2
DATA1_FG1 DISK2 /dev/sdf1 1
DATA1_FG1 DISK1 /dev/sde1 0
创建测试用户,测试表
SQL> create user lin identified by oracle;
User created.
SQL> create tablespace data1 datafile '+DATA1';
Tablespace created.
SQL> col file_name for a50
SQL> select file_id, file_name,bytes/1024/1024 from dba_data_files where tablespace_name='DATA1'
FILE_ID FILE_NAME BYTES/1024/1024
---------- ------------------------------------------------------------ ---------------
2 +DATA1/PROD/DATAFILE/data1.256.1082626777 100
SQL> alter user lin default tablespace data1;
User altered.
SQL> alter user lin quota unlimited on data1;
User altered.
SQL> create table lin.test as select * from all_objects;
Table created.
目前我们再ASM 磁盘组data1上存储了用户数据,
SQL> select owner,segment_name,file_id,extent_id from dba_extents where segment_name='TEST' and owner='LIN'
OWNER SEGMENT_NAME FILE_ID EXTENT_ID
-------------------- ------------------------------ ---------- ----------
LIN TEST 2 0
LIN TEST 2 1
LIN TEST 2 2
LIN TEST 2 3
LIN TEST 2 4
LIN TEST 2 5
LIN TEST 2 6
LIN TEST 2 7
LIN TEST 2 8
LIN TEST 2 9
LIN TEST 2 10
LIN TEST 2 11
LIN TEST 2 12
LIN TEST 2 13
LIN TEST 2 14
LIN TEST 2 15
LIN TEST 2 16
LIN TEST 2 17
LIN TEST 2 18
LIN TEST 2 19
LIN TEST 2 20
LIN TEST 2 21
LIN TEST 2 22
LIN TEST 2 23
LIN TEST 2 24
LIN TEST 2 25
LIN TEST 2 26
27 rows selected.
表段test都放在数据文件2上,改文件放在磁盘组data1上
下面我们查询
SQL> select failgroup ,name,path,mount_status, state,total_mb,free_mb from v$asm_disk where group_number=3 order by 1,2;
FAILGROUP NAME PATH MOUNT_STATUS STATE TOTAL_MB FREE_MB
-------------------- -------------------- -------------------- --------------------- ---------- ---------- ----------
DATA1_FG1 DISK1 /dev/sde1 CACHED NORMAL 1023 941
DATA1_FG1 DISK2 /dev/sdf1 CACHED NORMAL 1023 941
DATA1_FG2 DISK3 /dev/sdg1 CACHED NORMAL 1023 945
DATA1_FG2 DISK4 /dev/sdh1 CACHED NORMAL 1023 937
**************normal冗余的ASM磁盘组中数据到底放在哪里,深入理解ASM的normal冗余磁盘组的数据分布。***************
我们的表段的数据块放在哪里呢,我们具体分析数据放在哪里
SQL> select rowid from lin.test where object_id=100;
ROWID
------------------
AAAR5ZAACAAAACEAAe
查询改行所在的数据块
SQL> select dbms_rowid.rowid_block_number('AAAR5ZAACAAAACEAAe') "block#" from dual;
block#
----------
132
查询文件的块大小
SQL> select block_size from v$datafile where file#=2;
BLOCK_SIZE
----------
8192
下面通过ASM实例查询ASM的数据文件信息
SQL> select file_id, file_name,bytes/1024/1024 from dba_data_files where tablespace_name='DATA1'
FILE_ID FILE_NAME BYTES/1024/1024
---------- ------------------------------------------------------------ ---------------
2 +DATA1/PROD/DATAFILE/data1.256.1082626777 100
这里我们知道ASM的文件号是256
查询256号ASM文件的extent分布,extent是ASM分配空间的小逻辑单位,由AU组成
select pxn_kffxp "phy-ext#",xnum_kffxp "vir_ext#",disk_kffxp "disk#",au_kffxp "au#" from x$kffxp where number_kffxp=256
phy-ext# vir_ext# disk# au#
---------- ---------- ---------- ----------
0 0 3 34
1 0 1 31
2 1 1 32
3 1 3 35
4 2 0 32
5 2 3 36
6 3 2 29
7 3 1 33
8 4 3 37
9 4 0 33
......
由于是normal冗余,数据有两份,分布在失败组的不同磁盘中,比如extent 0 放在磁盘1,3,分别数据失败组1 ,2,也说明是失败组1 的磁盘1的partner是3.
查询AU大小
col value for a10;
SQL> select value from v$asm_attribute where name='au_size' and group_number=3
VALUE
----------
1048576
SQL> select 1048576/1024/1024 from dual;
1048576/1024/1024
-----------------
1
一个AU大小是1M,根据需要每个磁盘组可以有不同的AU大小(分配空间的效率)
我们要查的数据在256号文件的第132号块,由于每个AU为1024K,每个块大小为8k,每个AU为128个块,132号块位于第二个virtual extent的第4个块
phy-ext# vir_ext# disk# au#
---------- ---------- ---------- ----------
0 0 3 34
1 0 1 31
2 1 1 32 <<<<<数据所在磁盘1----对应失败组1
3 1 3 35 <<<<<数据所在磁盘3----对应失败组2
具体查下,会看到数据确实分布到磁盘组data1的两个失败组中,无论磁盘对应 /dev/sdh1和/dev/sdf1,实现了两份数据冗余,满足normal模式
SQL> select failgroup,disk_number,name,path from v$asm_disk where disk_number in (1,3);
FAILGROUP DISK_NUMBER NAME PATH
-------------------- ----------- -------------------- --------------------
DATA1_FG2 3 DISK4 /dev/sdh1
DATA1_FG1 1 DISK2 /dev/sdf1
测试数据块位于磁盘 /dev/sdf1的32号AU的第四个块中,我们使用dd导出数据
先导出整个AU
[grid@rac1 ~]$ rm -rf *.dd
[grid@rac1 ~]$ dd if=/dev/sdf1 bs=1024k count=1 skip=32 of=au32.dd;
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.1128 s, 9.3 MB/s
导出AU中的一个块,存储了132号数据块。
[grid@rac1 ~]$ dd if=au32.dd bs=8k count=1 skip=4 of=block132.dd
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 0.00157946 s, 5.2 MB/s
查询数据据
grid@rac1 ~]$ od -c block132.dd
0000000 006 242 \0 \0 204 \0 200 \0 6 272 . \0 \0 \0 002 004
0000020 \n $ \0 \0 001 \0 \0 \0 Y 036 001 \0 . 272 . \0
0000040 \0 200 \0 \0 003 \0 2 \0 200 \0 200 \0 377 377 \0 \0
0000060 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 200 \0 200
0000100 . 272 . \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000120 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
****查询失败组data1_fg2的磁盘文件/dev/sdh1存储的我们要查询的数据,这是冗余数据。
[grid@rac1 ~]$ dd if=/dev/sdh1 bs=1024k count=1 skip=35 of=au432.dd;
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0856258 s, 12.2 MB/s
[grid@rac1 ~]$ dd if=au432.dd bs=8k count=1 skip=4 of=block4132.dd
1+0 records in
1+0 records out
8192 bytes (8.2 kB) copied, 0.00110058 s, 7.4 MB/s
查询数据据
od -c block4132.dd
[grid@rac1 ~]$ od -c block4132.dd
0000000 006 242 \0 \0 204 \0 200 \0 6 272 . \0 \0 \0 002 004
0000020 \n $ \0 \0 001 \0 \0 \0 Y 036 001 \0 . 272 . \0
0000040 \0 200 \0 \0 003 \0 2 \0 200 \0 200 \0 377 377 \0 \0
0000060 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 200 \0 200
0000100 . 272 . \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000120 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0
*
在不同失败组的ASM磁盘块上,确实存放了两份数据。