如何理解ASM裡FAILGROUP的概念

warehouse發表於2011-02-06

FAILGROUP在asm裡是一個非常重要的概念,oracle在doc上又交待的似乎不夠清楚。

下面這篇文章是小V的總結,大家也可以參考:

http://www.itpub.net/viewthread.php?tid=1348104&extra=&highlight=failgroup&page=1

[@more@]

SQL> select group_number,name,type from v$asm_diskgroup;

GROUP_NUMBER NAME TYPE
------------ ---------- ------------
1 DG1 NORMAL
2 DG2 EXTERN

SQL> select group_number,disk_number,total_mb,free_mb,name,failgroup from v$asm_disk order by group_number,disk_number,failgroup;

GROUP_NUMBER DISK_NUMBER TOTAL_MB FREE_MB NAME FAILGROUP
------------ ----------- ---------- ---------- ---------- ----------
1 0 1024 560 DG1_0000 DG1_0001
1 1 1024 558 DG1_0001 DG1_0001
1 2 2048 1120 DG1_0002 DG1_0002
2 0 1024 42 DG2_0000 DG2_0000

SQL>
--======================
SQL> select file_name,bytes from dba_data_FILES;

FILE_NAME BYTES
--------------------------------------------- ----------
+DG1/asmdb/datafile/test/system01.dbf 314572800
+DG1/asmdb/datafile/undotbs1.263.741435561 209715200
+DG1/asmdb/datafile/sysaux.264.741435571 125829120
+DG1/asmdb/datafile/users.266.741435583 5242880
+DG1/asmdb/datafile/test.dbf 10485760

SQL>
--===============================
以表空間users對應的檔案+DG1/asmdb/datafile/users.266.741435583為
例子來看asm file在disk上的data分佈以及failgroup的作用和意義
--===============================
SQL> select group_kffxp,xnum_kffxp,lxn_kffxp,disk_kffxp,failgroup
2 from x$kffxp x,v$asm_disk d
3 where number_kffxp=266 and group_kffxp=1
4 and d.disk_number=x.disk_kffxp
5 and d.group_number=x.group_kffxp
6 ;

GROUP_KFFXP XNUM_KFFXP LXN_KFFXP DISK_KFFXP FAILGROUP
----------- ---------- ---------- ---------- ----------
1 0 1 2 DG1_0002
1 3 0 2 DG1_0002
1 4 1 2 DG1_0002
1 2 0 2 DG1_0002
1 5 1 2 DG1_0002
1 1 1 2 DG1_0002
1 1 0 1 DG1_0001
1 3 1 1 DG1_0001
1 4 0 1 DG1_0001
1 2 1 0 DG1_0001
1 0 0 0 DG1_0001
1 5 0 0 DG1_0001

已選擇12行。

SQL>
--=======================================
x$kffxp全部欄位可以參考
x$kffxp裡面的欄位XNUM_KFFXP是組成asm file的au(allocate unit)的編號
LXN_KFFXP表示asm file對應的data copy的編號,0表示primary,1表示mirror
DISK_KFFXP表示disk number
從上面的查詢我們可以清楚的看到au是在2個FAILGROUP:DG1_0001和DG1_0002上各自
分配了6個,其實每個asm file的file header佔用1個au,這樣由於diskgroup dg1是
normal方式,因此其實metadata使用了2m的空間,剩下10m正好對應的是檔案
+DG1/asmdb/datafile/users.266.741435583 的大小,檔案本身是5m,由於做了mirror,所以
是10m,但是這10m是平均分佈在2個FAILGROUP裡,不管這個FAILGROUP裡包含了多少塊disk,只要
1個FAILGROUP是好用的,那麼db就可以正常使用,所以其實FAILGROUP是au和disk之間的邏輯概念
--=======================================
SQL> create diskgroup dg3 external redundancy failgroup fg1 disk 'g:asmdiskdisk5' name disk5;
create diskgroup dg3 external redundancy failgroup fg1 disk 'g:asmdiskdisk5' name disk5
*
ERROR at line 1:
ORA-15018: diskgroup cannot be created
ORA-15067: command or option incompatible with diskgroup redundancy


SQL> create diskgroup dg3 external redundancy disk 'g:asmdiskdisk5' name disk5;

Diskgroup created.

SQL> create diskgroup dg4 normal redundancy failgroup fg1 disk 'g:asmdiskdisk6' name disk6;
create diskgroup dg4 normal redundancy failgroup fg1 disk 'g:asmdiskdisk6' name disk6
*
ERROR at line 1:
ORA-15018: diskgroup cannot be created
ORA-15072: command requires at least 2 failure groups, discovered only 1


SQL> create diskgroup dg4 normal redundancy failgroup fg1 disk 'g:asmdiskdisk6' name disk6 failgroup fg2 disk 'g:asmdiskdisk7' name disk7;

Diskgroup created.

SQL> select group_number,failgroup from v$asm_disk;

GROUP_NUMBER FAILGROUP
------------ ----------
0
1 DG1_0002
1 DG1_0001
2 DG2_0000
1 DG1_0001
3 DISK5
4 FG1
4 FG2

8 rows selected.

SQL>
SQL> alter diskgroup dg3 add failgroup disk5 disk 'G:asmdiskDISK8' name disk8;
alter diskgroup dg3 add failgroup disk5 disk 'G:asmdiskDISK8' name disk8
*
ERROR at line 1:
ORA-15067: command or option incompatible with diskgroup redundancy


SQL> alter diskgroup dg3 add disk 'G:asmdiskDISK8' name disk8;

Diskgroup altered.

SQL>
SQL> select group_number,failgroup from v$asm_disk order by group_number;

GROUP_NUMBER FAILGROUP
------------ ----------
1 DG1_0002
1 DG1_0001
1 DG1_0001
2 DG2_0000
3 DISK8
3 DISK5
4 FG1
4 FG2

8 rows selected.

SQL>
--==========================
SQL> create tablespace test1 datafile '+dg3/test1.dbf' size 5m;

表空間已建立。

SQL>
--==========================
ASMCMD> pwd
+dg3
ASMCMD> ls
ASMDB/
test1.dbf
ASMCMD> ls -l test1.dbf
Type Redund Striped Time Sys Name
N test1.dbf => +DG3/ASMDB/DATAFILE/TEST1.256.742432737
ASMCMD>
--==================================
SQL> select group_kffxp,xnum_kffxp,lxn_kffxp,disk_kffxp,failgroup
2 from x$kffxp x,v$asm_disk d
3 where number_kffxp=256 and group_kffxp=3
4 and d.disk_number=x.disk_kffxp
5 and d.group_number=x.group_kffxp
6 ;

GROUP_KFFXP XNUM_KFFXP LXN_KFFXP DISK_KFFXP FAILGROUP
----------- ---------- ---------- ---------- ----------
3 0 0 0 DISK5
3 2 0 0 DISK5
3 4 0 0 DISK5
3 3 0 1 DISK8
3 5 0 1 DISK8
3 1 0 1 DISK8

6 rows selected.

SQL>
--===================================
oracle要求
A normal redundancy disk group must contain at least two failure groups.
A high redundancy disk group must contain at least three failure groups.
external redundancy在語法上不支援或者說不提供failgroup,但是事實上oracle內部
還是給每一個disk分配了1個failgroup,只不過external redundancy這種方式的diskgroup
裡不管有多少塊disk,也不管有多少個failgroup(最終當然是1個disk oracle給對應了一個
failgroup),只要一個failgroup包含的disk出現問題,最終使用該diskgroup的db都會出現問題,
因為該failgroup裡包含的disk上的data沒有任何mirror。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/19602/viewspace-1045623/,如需轉載,請註明出處,否則將追究法律責任。

相關文章