Oracle ASM Disk Partner

ASM的数据冗余机制是通过将extent的镜像副本复制到同一磁盘组不同failgroup的磁盘上来实现的,这个磁盘被称为partner磁盘。在11GR2版本,一个冗余(Normal,High)的磁盘组,每一个ASM磁盘最多可以拥有8个partner磁盘,而在11GR2版本之前每一个磁盘最多拥有10个partner。在external冗余方式的磁盘组内既没有failgroup,磁盘之间也没有partner关系。其实可以通过隐含参数_asm_partner_target_disk_part来调整partner的数量。

如果正常冗余磁盘组有两个磁盘,他们就互为伙伴。磁盘0中的每个区的镜像会存储在磁盘1中,并且磁盘1中的每个区的镜像会存储在磁盘0中。因此每个磁盘都有一个伙伴磁盘。对于有3个磁盘的正常冗余磁盘组,如果在创建时没有手动指定故障磁盘组,那么每个磁盘将有两个伙伴磁盘。磁盘0的伙伴为磁盘1与磁盘2,磁盘1的伙伴为磁盘0与磁盘2,磁盘2的伙伴为磁盘0与磁盘1.当一个区存储在磁盘0上时,它的镜像副本将会存储在磁盘1或磁盘2上,但不是在磁盘1与磁盘2上都存在镜像副本。对于正常冗余磁盘,每个区有两个副本而不是三个。类似的,磁盘1上的一个区,它的镜像副本可能存储在磁盘0或磁盘2上,磁盘2上的一个区,它的镜像副本可能存储在磁盘0或磁盘1。对于存储元数据的区来说,如果故障磁盘组的数量大于三,那么在正常冗余磁盘组上会有三份副本。如果正常冗余磁盘组有大量磁盘,每个磁盘将有8个伙伴磁盘。这意味着任何磁盘上的一个区将会有一个镜像副本存储在它的8个伙伴磁盘中的一个磁盘上。对于正常冗余磁盘组来说,任何一个区只有一个镜像副本存储在它的一个伙伴磁盘上。

对于由3个磁盘所创建的high冗余磁盘组,每个磁盘将有两个伙伴磁盘。磁盘0的伙伴为磁盘1与磁盘2,磁盘1的伙伴为磁盘0与磁盘2,磁盘2的伙伴为磁盘0与磁盘1。磁盘0上的每个区的镜像将会存储磁盘1与磁盘2上。磁盘1上的每个区的镜像将会存储磁盘0与磁盘2上。

可以查询x$kfdpartner来找出关于磁盘伙伴关系的更多信息。

SQL> SELECT count(disk_number)
FROM v$asm_disk
WHERE group_number = 1;

COUNT(DISK_NUMBER)
------------------
               14

查询结果显示磁盘组内包含的磁盘数量着实不少,接下来看单个磁盘拥有多少个partner

SQL> SELECT disk "Disk", count(number_kfdpartner) "Number of partners"
FROM x$kfdpartner
WHERE grp=1
GROUP BY disk
ORDER BY 1;

      Disk Number of partners
---------- ------------------
         0                  8
         1                  8
         2                  8
         3                  8
         4                  8
         5                  8
         6                  8
         7                  8
         8                  8
         9                  8
        10                  8
        11                  8
        12                  8
        13                  8
        14                  8

14 rows selected.

查询结果显示单个磁盘都准确的拥有8个partner磁盘

SQL> set pages 1000
SQL> break on Group# on Disk#
SQL> SELECT d.group_number "Group#", d.disk_number "Disk#", p.number_kfdpartner "Partner disk#"
FROM x$kfdpartner p, v$asm_disk d
WHERE p.disk=d.disk_number and p.grp=d.group_number
ORDER BY 1, 2, 3;

    Group#      Disk# Partner disk#
---------- ---------- -------------
         1          0            1
                                 3
                                 5
                                 6
                                 7
                                 9
                                 11
                                 14
                    1            2
                                 3
                                 4
                                 5
                                 6
                                 8
                                 12
                                 13

....

partner关系是在创建磁盘组时由ASM自动分配的,在每次添加和删除磁盘操作时会自动更新。磁盘之间的partner关系信息是记录在磁盘的partner关系状态表即PST表和磁盘目录中,这两项都是重要的ASM元数据结构。

SQL> select disk_number, name, path from v$asm_disk_stat where group_number = (select group_number from v$asm_diskgroup_stat where name='DATADG') order by disk_number asc;

DISK_NUMBER NAME                           PATH
----------- ------------------------------ ------------------------------
          0 DATADG_0001                    /dev/raw/raw11
          1 DATADG_0003                    /dev/raw/raw4
          2 DATADG_0002                    /dev/raw/raw3
          3 DATADG_0000                    /dev/raw/raw10

[grid@jyrac1 ~]$ kfed read /dev/raw/raw11 aun=1 blkn=0 | more
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                           17 ; 0x002: KFBTYP_PST_META
kfbh.datfmt:                          2 ; 0x003: 0x02
kfbh.block.blk:                     256 ; 0x004: blk=256
kfbh.block.obj:              2147483648 ; 0x008: disk=0
kfbh.check:                   465161100 ; 0x00c: 0x1bb9cb8c
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdpHdrPairBv1.first.super.time.hi:33042831 ; 0x000: HOUR=0xf DAYS=0xc MNTH=0xc YEAR=0x7e0
kfdpHdrPairBv1.first.super.time.lo:2457171968 ; 0x004: USEC=0x0 MSEC=0x15e SECS=0x27 MINS=0x24
kfdpHdrPairBv1.first.super.last:      2 ; 0x008: 0x00000002
kfdpHdrPairBv1.first.super.next:      2 ; 0x00c: 0x00000002
kfdpHdrPairBv1.first.super.copyCnt:   3 ; 0x010: 0x03
kfdpHdrPairBv1.first.super.version:   1 ; 0x011: 0x01
kfdpHdrPairBv1.first.super.ub2spare:  0 ; 0x012: 0x0000
kfdpHdrPairBv1.first.super.incarn:    1 ; 0x014: 0x00000001
kfdpHdrPairBv1.first.super.copy[0]:   0 ; 0x018: 0x0000
kfdpHdrPairBv1.first.super.copy[1]:   1 ; 0x01a: 0x0001
kfdpHdrPairBv1.first.super.copy[2]:   2 ; 0x01c: 0x0002
kfdpHdrPairBv1.first.super.copy[3]:   0 ; 0x01e: 0x0000
kfdpHdrPairBv1.first.super.copy[4]:   0 ; 0x020: 0x0000
kfdpHdrPairBv1.first.super.dtaSz:     4 ; 0x022: 0x0004
kfdpHdrPairBv1.first.asmCompat:186646528 ; 0x024: 0x0b200000
kfdpHdrPairBv1.first.newCopy[0]:      0 ; 0x028: 0x0000
kfdpHdrPairBv1.first.newCopy[1]:      0 ; 0x02a: 0x0000
kfdpHdrPairBv1.first.newCopy[2]:      0 ; 0x02c: 0x0000
kfdpHdrPairBv1.first.newCopy[3]:      0 ; 0x02e: 0x0000
kfdpHdrPairBv1.first.newCopy[4]:      0 ; 0x030: 0x0000
kfdpHdrPairBv1.first.newCopyCnt:      0 ; 0x032: 0x00
kfdpHdrPairBv1.first.contType:        1 ; 0x033: 0x01
kfdpHdrPairBv1.first.spare0:          0 ; 0x034: 0x00000000
kfdpHdrPairBv1.first.ppat[0]:         0 ; 0x038: 0x0000
kfdpHdrPairBv1.first.ppat[1]:         0 ; 0x03a: 0x0000
kfdpHdrPairBv1.first.ppat[2]:         0 ; 0x03c: 0x0000
kfdpHdrPairBv1.first.ppat[3]:         0 ; 0x03e: 0x0000
kfdpHdrPairBv1.first.ppatsz:          0 ; 0x040: 0x00
kfdpHdrPairBv1.first.spare1:          0 ; 0x041: 0x00
kfdpHdrPairBv1.first.spare2:          0 ; 0x042: 0x0000
kfdpHdrPairBv1.first.spares[0]:       0 ; 0x044: 0x00000000
kfdpHdrPairBv1.first.spares[1]:       0 ; 0x048: 0x00000000
kfdpHdrPairBv1.first.spares[2]:       0 ; 0x04c: 0x00000000

信息kfdpHdrPairBv1.first.super.copyCnt: 3 ; 0x010: 0x03说明存在3个PST副本,说明在磁盘0,1和2上有pst的副本(kfdpHdrPairBv1.first.super.copy

[0],kfdpHdrPairBv1.first.super.copy[1]和kfdpHdrPairBv1.first.super.copy[2]处有值)

[grid@jyrac1 ~]$ kfed read /dev/raw/raw11 aun=1 blkn=3 | more
kfbh.endian: 1 ; 0x000: 0x01
kfbh.hard: 130 ; 0x001: 0x82
kfbh.type: 18 ; 0x002: KFBTYP_PST_DTA
kfbh.datfmt: 2 ; 0x003: 0x02
kfbh.block.blk: 259 ; 0x004: blk=259
kfbh.block.obj: 2147483648 ; 0x008: disk=0
kfbh.check: 2182382336 ; 0x00c: 0x82148300
kfbh.fcn.base: 0 ; 0x010: 0x00000000
kfbh.fcn.wrap: 0 ; 0x014: 0x00000000
kfbh.spare1: 0 ; 0x018: 0x00000000
kfbh.spare2: 0 ; 0x01c: 0x00000000
kfdpDtaEv1[0].status: 127 ; 0x000: I=1 V=1 V=1 P=1 P=1 A=1 D=1
kfdpDtaEv1[0].fgNum: 1 ; 0x002: 0x0001
kfdpDtaEv1[0].addTs: 2199451943 ; 0x004: 0x8318f927
kfdpDtaEv1[0].partner[0]: 49154 ; 0x008: P=1 P=1 PART=0x2
kfdpDtaEv1[0].partner[1]: 49153 ; 0x00a: P=1 P=1 PART=0x1
kfdpDtaEv1[0].partner[2]: 49155 ; 0x00c: P=1 P=1 PART=0x3

以上输出代表磁盘0(kfdpDtaEv1[0])所在failgroup号为1,它有3个partner磁盘,分别为PART=0x2,PART=0x1,PART=0x3,也就是磁盘号2(/dev/raw/raw3),1(/dev/raw/raw4),3

(/dev/raw/raw10)

Oracle ASM Free Space Table

在进行创建文件或者文件resize过程中,需要有一个快捷入口,可以迅速的知道当前磁盘有哪些可用的(free状态的)AU,ASM Free Space Table 简称FST表就是提供一个这样的功能,通过它可以快速的知道哪些allocation table(AT表)元数据块中有空闲的AU,它存储的是一个个的AT表元数据块的号码,FST指示了那个AT表可能包含可用的AUs。当一个磁盘被选择用来分配AU时,ASM会咨询磁盘的FST。这允许ASM跳过那些被占用殆尽的AT块。FST对于分配是一种最佳方法。FST存储在每个AT中的第二个块中。FST表和AT表都被称为物理元数据,它们经常位于ASM磁盘的固定的位置。

FST存储位置
FST存储在ASM磁盘头,通过kfed工具可以查看磁盘头信息,其中kfdhdb.fstlocn的值代表了FST位于磁盘头的第几个块(AU)。例如下面的输出代表了,FST块位于磁盘头的块1,也就是AU 0的第二个块。(块从0开始编号)。不管是10g还是11g,FST存储在每个AT中的第二个块中。
10g ASM中的PST所在位置

[oracle@jyrac3 lib]$ kfed read /dev/raw/raw3 aun=0 blkn=0 | grep fstlocn
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001

11g ASM中的PST所在位置

[grid@jyrac1 ~]$ kfed read /dev/raw/raw10 aun=0 blkn=0 | grep fstlocn
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001
[grid@db1 disks]$ kfed read /dev/oracleasm/disks/RLZY_DATA1 aun=0 blkn=1 | more
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            2 ; 0x002: KFBTYP_FREESPC
kfbh.datfmt:                          2 ; 0x003: 0x02
kfbh.block.blk:                       1 ; 0x004: blk=1
kfbh.block.obj:              2147483651 ; 0x008: disk=3
kfbh.check:                  4111437318 ; 0x00c: 0xf50f8e06
kfbh.fcn.base:                     3323 ; 0x010: 0x00000cfb
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdfsb.aunum:                         0 ; 0x000: 0x00000000
kfdfsb.max:                         254 ; 0x004: 0x00fe
kfdfsb.cnt:                          12 ; 0x006: 0x000c
kfdfsb.bound:                         0 ; 0x008: 0x0000
kfdfsb.flag:                          1 ; 0x00a: B=1
kfdfsb.ub1spare:                      0 ; 0x00b: 0x00
kfdfsb.spare[0]:                      0 ; 0x00c: 0x00000000
kfdfsb.spare[1]:                      0 ; 0x010: 0x00000000
kfdfsb.spare[2]:                      0 ; 0x014: 0x00000000
kfdfse[0].fse:                        0 ; 0x018: FREE=0x0 FRAG=0x0
kfdfse[1].fse:                        0 ; 0x019: FREE=0x0 FRAG=0x0
kfdfse[2].fse:                        0 ; 0x01a: FREE=0x0 FRAG=0x0
kfdfse[3].fse:                      119 ; 0x01b: FREE=0x7 FRAG=0x7
kfdfse[4].fse:                       16 ; 0x01c: FREE=0x0 FRAG=0x1
kfdfse[5].fse:                       16 ; 0x01d: FREE=0x0 FRAG=0x1
kfdfse[6].fse:                       16 ; 0x01e: FREE=0x0 FRAG=0x1
kfdfse[7].fse:                       16 ; 0x01f: FREE=0x0 FRAG=0x1
kfdfse[8].fse:                       16 ; 0x020: FREE=0x0 FRAG=0x1
kfdfse[9].fse:                       16 ; 0x021: FREE=0x0 FRAG=0x1
kfdfse[10].fse:                      16 ; 0x022: FREE=0x0 FRAG=0x1
kfdfse[11].fse:                      16 ; 0x023: FREE=0x0 FRAG=0x1
kfdfse[12].fse:                       0 ; 0x024: FREE=0x0 FRAG=0x0
kfdfse[13].fse:                       0 ; 0x025: FREE=0x0 FRAG=0x0
kfdfse[14].fse:                       0 ; 0x026: FREE=0x0 FRAG=0x0
kfdfse[15].fse:                       0 ; 0x027: FREE=0x0 FRAG=0x0
kfdfse[16].fse:                       0 ; 0x028: FREE=0x0 FRAG=0x0
kfdfse[17].fse:                       0 ; 0x029: FREE=0x0 FRAG=0x0
kfdfse[18].fse:                       0 ; 0x02a: FREE=0x0 FRAG=0x0
kfdfse[19].fse:                       0 ; 0x02b: FREE=0x0 FRAG=0x0
kfdfse[20].fse:                       0 ; 0x02c: FREE=0x0 FRAG=0x0
kfdfse[21].fse:                       0 ; 0x02d: FREE=0x0 FRAG=0x0
kfdfse[22].fse:                       0 ; 0x02e: FREE=0x0 FRAG=0x0
kfdfse[23].fse:                       0 ; 0x02f: FREE=0x0 FRAG=0x0
....省略....
kfdfse[4031].fse:                     0 ; 0xfd7: FREE=0x0 FRAG=0x0
kfdfse[4032].fse:                     0 ; 0xfd8: FREE=0x0 FRAG=0x0
kfdfse[4033].fse:                     0 ; 0xfd9: FREE=0x0 FRAG=0x0
kfdfse[4034].fse:                     0 ; 0xfda: FREE=0x0 FRAG=0x0
kfdfse[4035].fse:                     0 ; 0xfdb: FREE=0x0 FRAG=0x0
kfdfse[4036].fse:                     0 ; 0xfdc: FREE=0x0 FRAG=0x0
kfdfse[4037].fse:                     0 ; 0xfdd: FREE=0x0 FRAG=0x0
kfdfse[4038].fse:                     0 ; 0xfde: FREE=0x0 FRAG=0x0
kfdfse[4039].fse:                     0 ; 0xfdf: FREE=0x0 FRAG=0x0

对于这个FST块,第一个AT表元数据块位于AU0:

kfdfsb.aunum:                         0 ; 0x000: 0x00000000

这个FST块最大数量的FST条目可以达到254个,虽然上面kfed的输出中kfdfse[i]的编号到了4039,也就是有4039+1=4040个条目,但是有效条目只有254个。

kfdfsb.max:                         254 ; 0x004: 0x00fe

大的ASM磁盘可能会有超过一个stride,ASM磁盘头的kfdhdb.mfact显示了stride的大小(单位为AU),每一个stride有它自己的物理元数据,这意味着会有它自己的FST表。第二个stride的物理元数据位于这个stride的第一个AU,我们通过kfed工具看一下:

$ kfed read /dev/sdc1 | grep mfact
kfdhdb.mfact:                    113792 ; 0x0c0: 0x0001bc80

以上显示了stride的大小为113792个AU,由于AU是从0开始编号,因此第一个stride最后的AU号是AU 113791,我们可以推算出第二个stride的FST位置是,AU 113792的第一个块:

[grid@db1 disks]$ kfed read /dev/oracleasm/disks/RLZY_DATA1 aun=113792 blkn=1 | grep type
kfbh.type:                            2 ; 0x002: KFBTYP_FREESPC

如预期,我们在AU 113792上有另一个FTS表,如果我们还有其他的stride,同样会在stride的开始AU处有FST表。如下面所示,一个大的ASM磁盘,会有数个stride,这里展示了在第3到5个stride的开始处的FST表:

[grid@db1 disks]$ kfed read /dev/oracleasm/disks/RLZY_DATA1 aun=227584 blkn=1 | grep type
kfbh.type:                            2 ; 0x002: KFBTYP_FREESPC
[grid@db1 disks]$ kfed read /dev/oracleasm/disks/RLZY_DATA1 aun=341376 blkn=1 | grep type
kfbh.type:                            2 ; 0x002: KFBTYP_FREESPC
[grid@db1 disks]$ kfed read /dev/oracleasm/disks/RLZY_DATA1 aun=455168 blkn=1 | grep type
kfbh.type:                            2 ; 0x002: KFBTYP_FREESPC

参考
Oracle Automatic Storage Management: Under-the-Hood & Practical Deployment Guide
http://asmsupportguy.blogspot.jp/2013/08/free-space-table.html

Oracle ASM Disk Header

ASM Disk Header
每个ASM磁盘有一个disk header。disk header它标识了磁盘属于ASM磁盘,disk header占用了每个磁盘的第一个allocation unit(AU 0)中的第一个块(block 0)。disk header条目包括以下内容:
1.disk name
2.disk number
3.diskgroup name
4.failure group name
5.disk size
6.allocation unit(AU) size
7.creation time
8.mount time
9.ASM compatibility
10.RDBMS compatibility
11.file directory pointer
12.ASMLIB reserved block

这些内容从它们的名字就可以知道其作用。如果在特定的磁盘组中有两个磁盘都要使用相同的磁盘名称与磁盘号,那么在mount磁盘组时mount time与creation time被用来决定选择正确的磁盘。这种情况可能出现在一个磁盘临时出现故障而向磁盘组中添加另一块磁盘。

ASM compatibility指示mount磁盘组的ASM实例的最小软件版本。Oracle 10g软件总是使用10.1。录compatible.asm属性被推进到11.1后,ASM将在PST中存储版本号,但也会更新磁盘组中的disk headers来确保Oracle 10g软件将不能访问不兼容的磁盘组。

RDBMS compatibility指示RDBMS实例访问磁盘组兼容性参数的最小设置。这个值在disk header中将总是10.1。Oracle 10g软件从不更新这个值,并且如果compatible.asm设置为11.1或更高,Oracle 11g软件将对于RDBMS compatibility询问属性目录。

如果磁盘包含文件目录,那么file directory pointer描述了文件目录的第一个区所在位置。对于引导虚拟ASM元数据这个指针是需要的。

ASMLIB供应商可以在disk header中的ASMLIB保留块中存储达32 bytes的信息。Oracle的ASMLIB在这里存储了磁盘的ASMLIB名称。

因为disk header是磁盘特定的,在另一磁盘上对它进行镜像没有意义。磁盘目录包含了与disk header相同的信息。执行alter diskgroup … check命令可以验证磁盘目录与disk header的一致性

ASM磁盘是以AU为单位进行格式化的,部分AU会存放ASM元数据,其他AU存放数据库中的相关数据(如数据文件、备份文件、归档文件等等)。包含ASM元数据的AU会以元数据块的方式进行格式化(一个元数据块的大小为4K)。AU0位于ASM磁盘的起始位置,它始终用于存储ASM元数据。AU0的第一个块,即block 0,就是ASM的磁盘头。ASM 磁盘头的大部分内容仅与本磁盘相关,但也有部分信息与整个磁盘组相关,有些甚至于与整个cluster相关。

在10g中查询会得到如下结果

SQL> SELECT number_kffxp file#, disk_kffxp disk#,COUNT(disk_kffxp) extents FROM x$kffxp WHERE group_kffxp=1 AND disk_kffxp <>65534 GROUP BY number_kffxp, disk_kffxp;

     FILE#      DISK#    EXTENTS
---------- ---------- ----------
         1          0          1
         1          1          1
         2          0          1
         2          1          1
         3          0          6
         3          1          6
         4          0          1
         4          1          1
         5          0          1
         5          1          1
         6          0          1
         6          1          1
       256          0         29
       256          1         29
       257          0         35
       257          1         35
       258          0          3
       258          1          3
       259          0          1
       259          1          1
       260          0          1
       260          1          1
       261          0          4
       261          1          4
       262          0          4
       262          1          4
       263          0          2
       263          1          2
       264          0          7
       264          1          7
       265          0          4
       265          1          4
       266          0          4
       266          1          4
       267          0          4
       267          1          4
       268          0          1
       268          1          1
       269          0          7
       269          1          7
       270          0          1
       270          1          1

42 rows selected.

上述查询的file信息,对于10g版本中asm所涉及的元数据信息,对应关系如下:

file#   1   ---ASM file 1,file directory
file#   2   ---ASM file 2,disk directory
file#   3   ---ASM file 3,active Change Directory(ACD)
file#   4   ---ASM file 4,continuing Operations Directory (COD)
file#   5   ---ASM file 5,template directory
file#   6   ---ASM file 6,alias directory

File Directory
文件目录包含与ASM文件相关的所有元数据。目录对于每个ASM文件都有一个条目并且通过文件号来进行索引。文件目录在每个磁盘组中都是文件号1(F1)。

文件目录包含以下内容:

.Incarnation number
.File size
.File block size
.File type
.Redundancy(none,normal,or high)
.Striping(coarse or fine-grained)
.File creation time
.File modification time(the time that the file was last opened for writing))
.File layout

如果一个文件被删除,对于新创建的文件ASM会使用它的文件号,那么文件号将是唯一的,有不同的incarnation号。incarnation号是当文件创建时由时间来推算出来的,它保证对于相同文件号来说incarnation号是唯一的。

ASM文件的块大小是独立于ASM元数据块大小。所有的ASM元数据目录的块大小为4K。RDBMS数据文件在创建表空间时指定的块大小可以是2K,4K,8K,16K或32K。RDBMS的redo log文件通常的块大小是512 byte。ASM跟踪逻辑文件大小,通过数据库,与磁盘组中所占用的物理空间,考虑文件的冗余可以很显然的看出。RDBMS在文件创建时也提供了文件类型。对于不是由RDBMS实例显式创建的文件(比如由XML DB ftp命令或ASMCMD cp命令所创建的文件),ASM为了在创建时判断文件类型会检查文件头。

文件创建时间有一个明显的语义。文件修改时间,然后不是每次更新时间文件都会写入。而是当文件被打开执地写操作时文件修改时间会被更新。这意味着即使文件没有被写入,文件的修改时间也可能发生改变,并且存储的修改时间可能比修改文件内容所处的时间早。为了减小在集群ASM实例中的buffer cache中的文件目录块的竞争,修改时间以小时为精度。因此,在RAC中多个实例以较短时间打开文件,那么只有第一个访问文件的实例需要更新文件修改时间。

文件的布局信息由一系列的区指针组成。区指针指定了磁盘号与区所在的AU号。文件目录条目包含了一个文件的前60个区指针,有时也叫direct extens。文件目录剩余的部分包含了指向indirect extents的指针。indirect extents是其它虚拟元数据区,包含ASM文件的区指针。每个indirect extent是一个AU。每个文件目录条目可以包含最多300个indirect exten。indirect指针的概念存在于大多数传统文件系统中,比如Unix的BSD文件系统。文件布局的解释也叫extent map,文件布局受条带与冗余的影响。

Disk Directory
磁盘目录包含磁于磁盘组中所有磁盘的信息。磁盘目录信息比PST更详细。磁盘组中的每块磁盘通过磁盘号在磁盘目录索引中有一个条目。这个磁盘目录在每个磁盘组中的文件号为2(F2)
Disk Directory条目包含以下内容:

.Disk name
.Failure group name
.Disk size
.Disk free space
.Disk creation time

在磁盘目录中的许多信息在磁盘头中也可用。执行alter diskgroup … check可以验证关于磁盘这些结构的详细信息。
磁盘目录当磁盘组被mount时总是可用状态,因此对于正常或高级冗余磁盘组中的脱机磁盘也能提供信息。

Active Change Directory(ACD)

ACD是一个日志允许ASM对多个数据结构执行原子性改变。它类似于RDBMS的重做日志。每个实例将得到一个大小为42MB的ACD大块。每个大块的第一个块包含打开/关闭的状态与检查点。检查点每3秒更新一次。剩下的块被作为ACD改变记录的循环缓存区。ACD为了适应亲的ASM实例并根据需要动态增长。ASM使用ACD来执行崩溃恢复与实例恢复来确保ASM元数据的一致性。ACD在每个磁盘组中的文件号为3(F3)。

Continuing Operations Directory(COD)
COD用来跟踪长时间执行的磁盘组操作,比如文件创建与rebalance操作。长时间执行操作不适用于ACD。COD条目允许ASM在执行长时间操作期间从故障状态恢复。对于实例,ASM可以回滚没有完成的文件创建操作。RDBMS故障或用户操作可能导致这样的情况。对于磁盘的rebalance操作,如果实例执行rebalance失败,ASM可以在正常节点上重启rebalance或者当磁盘组再次在单实例ASM中mount时重启rebalance。COD在每个磁盘组中的文件号为4(F4)。

Template Directory
Template Directory包含关于磁盘组所有文件模板的信息。创建磁盘组时对于每种支持的文件类型将使用缺省的系统模板进行填充。如果用户创建自己的模板将会增加新的条目。模板目录通过模板号进行索引。
每种模板条目包含以下内容:

.Template name
.File redundancy
.File striping policy
.System flag

Template Directory在每个磁盘组中的文件号为5(F5)。缺省模板的模板名与文件类型相关。文件冗余默认为磁盘组冗余。文件条带默认是文件类型特定。system flag被设置为系统模板。用户创建的模板不会设置system flag。

Alias Directory
Alias Directory包含所有别名元数据以及每种系统别名,系统目录,用户目录与用户别名。通过别名号进行索引。
别名目录条目包含以下信息:

.Alias name(or directory name)
.Alias incarnation number
.File number
.File incarnation number
.Parent directory
.System flag

Alias Directory在每个磁盘组中的文件号为6(F6)。Alias incarnation number,很像file incarnation number,被用来区分可能重复使用相同别名号的别名或目录。system flag被设置给系统创建的别名与目录,但不对用户创建的别名或目录进行设置。

在11gr2中执行以下查询得到如下结果:

SQL> SELECT number_kffxp file#, disk_kffxp disk#,COUNT(disk_kffxp) extents FROM x$kffxp WHERE group_kffxp=3 AND disk_kffxp <>65534 GROUP BY number_kffxp, disk_kffxp;

     FILE#      DISK#    EXTENTS
---------- ---------- ----------
         1          0          1
         1          1          2
         1          2          2
         1          3          1
         2          0          1
         2          1          1
         2          2          1
         3          0         64
         3          1         63
         3          2         64
         3          3         64
         4          0          6
         4          1          5
         4          2          6
         4          3          7
         5          0          1
         5          1          1
         5          3          1
         6          1          1
         6          2          1
         6          3          1
         8          0          1
         8          1          1
         8          2          1
         9          1          1
         9          2          1
         9          3          1
       256          0          1
       256          1          1
       257          0         19
       257          1         19
       257          2         19
       257          3         18
       258          0        611
       258          1        612
       258          2        611
       258          3        611
       259          0        382
       259          1        381
       259          2        381
       259          3        381
       260          0        175
       260          1        174
       260          2        174
       260          3        174
       261          0         77
       261          1         75
       261          2         76
       261          3         77
       262          0         52
       262          1         51
       262          2         51
       262          3         51
       263          0          3
       263          1          2
       263          2          4
       263          3          3
       264          0         25
       264          1         26
       264          2         27
       264          3         27
       265          0         27
       265          1         25
       265          2         26
       265          3         27
       266          0         26
       266          1         26
       266          2         26
       266          3         27
       267          0         27
       267          1         26
       267          2         24
       267          3         28
       268          0         11
       268          1         10
       268          2         10
       268          3         11
       269          1          1
       269          2          1
       270          0         52
       270          1         51
       270          2         50
       270          3         52

83 rows selected.

可以看到,file 1到9都是元数据信息。前面的file 1到 6与10g中的对应一样,后面的file 7,file 8,file 9为以下内容:

file# 7 —volume directory (使用ACFS才会有)
file# 8 —disk Used Space Directory (USD)
file# 9 —attributes directory

volume directory
ASM元信息7号文件,是ASM的逻辑卷目录,用于跟踪与ADVM有关的文件。
ASM动态逻辑卷设备是由ASM动态逻辑卷构建的。一个磁盘组中可以配置一个或多个ASM动态逻辑卷设备。ASM集群文件系统通过ADVM接口构建在ASM磁盘组之上。ADVM像数据库一样,也是ASM的一个客户端。当一个逻辑卷被访问时,相应的ASM文件会被打开并且ASM extent的信息会被发送到ADVM驱动。

disk Used Space Directory (USD)
ASM元信息8号文件是磁盘空间使用目录Used Space Directory,简称USD,它记录了每个ASM磁盘组中每个磁盘的每个zone上被使用的AU数。一个磁盘的zone包含hot zone-热区(磁盘外圈)和cold zone-冷区(磁盘内圈)。USD目录为每个磁盘提供了一个条目,条目信息记录了2个zone(COLD和HOT)的AU使用数。USD结构是在11.2版本中引入的,并且与智能数据存放特性有关。USD元数据文件在ASM兼容性参数设置为11.2以上时会存在。

attributes directory
Attributes Directory包含了关于磁盘组属性的元数据。只有当compatible.asm设置为11.1或更高版本时目录才会在磁盘组中存在。Attribute Directory在磁盘组中的文件号为9(F9)(文件号7与8被保留给将来的功能使用,在11g中file 7为volume directory,file 8为disk Used Space Directory (USD))。AU_SIZE属性为了引导实际存储在disk header中。如果compatible.asm

设置为11.1或更高版本那么compatible.asm将会存储在PST中,否则compatible.asm将会被存储在disk header中。在Oracle 11gr1中,compatible.rdbms与disk_repair_time以及compatible.asm被存储在属性目录中。将来的版本将支持额外的属性。

这里将使用kfed工具来查看asm disk header的内容,对于10g首先需要统计kfed工具,如下:

[root@jyrac3 ~]# su - oracle
[oracle@jyrac3 ~]$ cd $ORACLE_HOME/rdbms/lib
[oracle@jyrac3 lib]$ make -f ins_rdbms.mk ikfed

Linking KFED utility (kfed)
rm -f /u01/app/oracle/product/10.2.0/db/rdbms/lib/kfed
gcc -o /u01/app/oracle/product/10.2.0/db/rdbms/lib/kfed -L/u01/app/oracle/product/10.2.0/db/rdbms/lib/ -L/u01/app/oracle/product/10.2.0/db/lib/ -

L/u01/app/oracle/product/10.2.0/db/lib/stubs/ -L/usr/lib -lirc  /u01/app/oracle/product/10.2.0/db/lib/s0main.o /u01/app/oracle/product/10.2.0/db/rdbms/lib/sskfeded.o 

/u01/app/oracle/product/10.2.0/db/rdbms/lib/skfedpt.o  /u01/app/oracle/product/10.2.0/db/rdbms/lib/defopt.o -ldbtools10 -lclntsh  `cat 

/u01/app/oracle/product/10.2.0/db/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat 

/u01/app/oracle/product/10.2.0/db/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10  -lvsn10 -lcommon10 -lgeneric10 -lmm 

-lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 `cat 

/u01/app/oracle/product/10.2.0/db/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lnro10 `cat 

/u01/app/oracle/product/10.2.0/db/lib/ldflags`    -lnsslb10 -lncrypt10 -lnsgr10 -lnzjs10 -ln10 -lnnz10 -lnl10 -lclient10 -lnnetd10  -lvsn10 -lcommon10 -lgeneric10   -

lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10 -lclient10 -lnnetd10  -lvsn10 -

lcommon10 -lgeneric10 -lsnls10 -lnls10  -lcore10 -lsnls10 -lnls10 -lcore10 -lsnls10 -lnls10 -lxml10 -lcore10 -lunls10 -lsnls10 -lnls10 -lcore10 -lnls10   `cat 

/u01/app/oracle/product/10.2.0/db/lib/sysliblist` -Wl,-rpath,/u01/app/oracle/product/10.2.0/db/lib -lm    `cat /u01/app/oracle/product/10.2.0/db/lib/sysliblist` -ldl 

-lm   -L/u01/app/oracle/product/10.2.0/db/lib
mv -f /u01/app/oracle/product/10.2.0/db/bin/kfed /u01/app/oracle/product/10.2.0/db/bin/kfedO
mv /u01/app/oracle/product/10.2.0/db/rdbms/lib/kfed /u01/app/oracle/product/10.2.0/db/bin/kfed
chmod 751 /u01/app/oracle/product/10.2.0/db/bin/kfed
[oracle@jyrac3 lib]$ which kfed
/u01/app/oracle/product/10.2.0/db/bin/kfed
[oracle@jyrac3 lib]$ cd /u01/app/oracle/product/10.2.0/db/bin/kfed
-bash: cd: /u01/app/oracle/product/10.2.0/db/bin/kfed: Not a directory
[oracle@jyrac3 lib]$ kfed -h
as/mlib         ASM Library [asmlib='lib']
aun/um          AU number to examine or update [AUNUM=number]
aus/z           Allocation Unit size in bytes [AUSZ=number]
blkn/um         Block number to examine or update [BLKNUM=number]
blks/z          Metadata block size in bytes [BLKSZ=number]
ch/ksum         Update checksum before each write [CHKSUM=YES/NO]
cn/t            Count of AUs to process [CNT=number]
d/ev            ASM device to examine or update [DEV=string]
o/p             KFED operation type [OP=READ/WRITE/MERGE/REPAIR/NEW/FORM/FIND/STRUCT]
p/rovnm         Name for provisioning purposes [PROVNM=string]
s/eek           AU number to seek to [SEEK=number]
te/xt           File name for translated block text [TEXT=string]
ty/pe           ASM metadata block type number [TYPE=number]

11gR2版本中的kfed工具,你会发现其更为强大了,还具有修复功能,在11gR2中你可以直接使用kfed修复disk header block,如下(11gR2中是不需要编译即可使用的)

[grid@jyrac1 ~]$ kfed -h
as/mlib         ASM Library [asmlib='lib']
aun/um          AU number to examine or update [AUNUM=number]
aus/z           Allocation Unit size in bytes [AUSZ=number]
blkn/um         Block number to examine or update [BLKNUM=number]
blks/z          Metadata block size in bytes [BLKSZ=number]
ch/ksum         Update checksum before each write [CHKSUM=YES/NO]
cn/t            Count of AUs to process [CNT=number]
de/v            ASM device to examine or update [DEV=string]
dm/pall         Don't suppress repeated lines when dumping corrupt blocks [DMPALL=YES/NO]
o/p             KFED operation type [OP=READ/WRITE/MERGE/REPAIR/NEW/FORM/FIND/STRUCT]
p/rovnm         Name for provisioning purposes [PROVNM=string]
s/eek           AU number to seek to [SEEK=number]
te/xt           File name for translated block text [TEXT=string]
ty/pe           ASM metadata block type number [TYPE=number]

下面使用kfed来查看ASM磁盘头的内容:
10g操作如下:
查询磁盘组相关磁盘信息

SQL> select group_number,disk_number,name,path,redundancy from v$asm_disk;

GROUP_NUMBER DISK_NUMBER NAME                           PATH                           REDUNDANCY
------------ ----------- ------------------------------ ------------------------------ --------------
           0           1                                /dev/raw/raw1                  UNKNOWN
           0           5                                /dev/raw/raw2                  UNKNOWN
           1           1 DATADG_0001                    /dev/raw/raw4                  UNKNOWN
           2           0 YBDG_0000                      /dev/raw/raw5                  UNKNOWN
           2           1 YBDG_0001                      /dev/raw/raw6                  UNKNOWN
           1           0 DATADG_0000                    /dev/raw/raw3                  UNKNOWN

6 rows selected.

查询磁盘组相关信息,可以看到ASM磁盘组的块大小为4096 byte,也就是4K,AU大小为16777216 byte,也就是16M

SQL> select group_number,name,block_size,allocation_unit_size from v$asm_diskgroup;

GROUP_NUMBER NAME                           BLOCK_SIZE ALLOCATION_UNIT_SIZE
------------ ------------------------------ ---------- --------------------
           1 DATADG                               4096             16777216
           2 YBDG                                 4096             16777216

磁盘组1为DATADG用来存储数据库相关文件,它包含两块磁盘/dev/raw/raw3与/dev/raw/raw4,磁盘头存储在AU0的第一个块,即block 0

[oracle@jyrac3 lib]$ kfed read /dev/raw/raw3 aun=0 blkn=0
kfbh.endian:                          1 ; 0x000: 0x01   --01即使1 表示的是Little Endian 相反,0的话即使表示BIG endian
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD --表示块类型为磁盘头
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: T=0 NUMB=0x0    --表示ASM块号,0表示ASM磁盘头块
kfbh.block.obj:              2147483648 ; 0x008: TYPE=0x8 NUMB=0x0
kfbh.check:                  2110140068 ; 0x00c: 0x7dc62ea4
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:         ORCLDISK ; 0x000: length=8    --ASMLIB磁盘是ORCLDISK+磁盘名,非ASMLIB磁盘是ORCLDISK
kfdhdb.driver.reserved[0]:            0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]:            0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                168820736 ; 0x020: 0x0a100000
kfdhdb.dsknum:                        0 ; 0x024: 0x0000        --ASM磁盘编号
kfdhdb.grptyp:                        2 ; 0x026: KFDGTP_NORMAL --磁盘组冗余方式为正常冗余
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER --磁盘header 状态  3是可用状态
kfdhdb.dskname:             DATADG_0000 ; 0x028: length=11     --ASM磁盘名
kfdhdb.grpname:                  DATADG ; 0x048: length=6      --ASM磁盘组名
kfdhdb.fgname:              DATADG_0000 ; 0x068: length=11     --ASM故障组名
kfdhdb.capname:                         ; 0x088: length=0
kfdhdb.crestmp.hi:             33042513 ; 0x0a8: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.crestmp.lo:            431214592 ; 0x0ac: USEC=0x0 MSEC=0xf4 SECS=0x1b MINS=0x6
kfdhdb.mntstmp.hi:             33042541 ; 0x0b0: HOUR=0xd DAYS=0x3 MNTH=0xc YEAR=0x7e0
kfdhdb.mntstmp.lo:           2841438208 ; 0x0b4: USEC=0x0 MSEC=0x33a SECS=0x15 MINS=0x2a
kfdhdb.secsize:                     512 ; 0x0b8: 0x0200
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000      --ASM元数据块大小,单位是byte,大小为4K
kfdhdb.ausize:                 16777216 ; 0x0bc: 0x01000000  --au单位大小,单位是byte,大小为16M
kfdhdb.mfact:                    454272 ; 0x0c0: 0x0006ee80
kfdhdb.dsksize:                     320 ; 0x0c4: 0x00000140  --该disk的大小,单位是au,由于au是16m,所以大小为5G
kfdhdb.pmcnt:                         2 ; 0x0c8: 0x00000002
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001  --指针指向ASM的空闲空间表,1代表本AU中的ASM块1
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002  --指针指向ASM的分配表,2代表本AU中的ASM块2
kfdhdb.f1b1locn:                      2 ; 0x0d4: 0x00000002  --指针指向ASM的文件目录,2代表本ASM磁盘的AU2
kfdhdb.redomirrors[0]:                0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]:                0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]:                0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]:                0 ; 0x0de: 0x0000
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000 --最小的数据库兼容版本,0x0a100000=10.1
kfdhdb.grpstmp.hi:             33042513 ; 0x0e4: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.grpstmp.lo:            428889088 ; 0x0e8: USEC=0x0 MSEC=0x15 SECS=0x19 MINS=0x6
kfdhdb.ub4spare[0]:                   0 ; 0x0ec: 0x00000000
kfdhdb.ub4spare[1]:                   0 ; 0x0f0: 0x00000000
kfdhdb.ub4spare[2]:                   0 ; 0x0f4: 0x00000000
kfdhdb.ub4spare[3]:                   0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[4]:                   0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[5]:                   0 ; 0x100: 0x00000000
kfdhdb.ub4spare[6]:                   0 ; 0x104: 0x00000000
kfdhdb.ub4spare[7]:                   0 ; 0x108: 0x00000000
kfdhdb.ub4spare[8]:                   0 ; 0x10c: 0x00000000
kfdhdb.ub4spare[9]:                   0 ; 0x110: 0x00000000
kfdhdb.ub4spare[10]:                  0 ; 0x114: 0x00000000
kfdhdb.ub4spare[11]:                  0 ; 0x118: 0x00000000
kfdhdb.ub4spare[12]:                  0 ; 0x11c: 0x00000000
kfdhdb.ub4spare[13]:                  0 ; 0x120: 0x00000000
kfdhdb.ub4spare[14]:                  0 ; 0x124: 0x00000000
kfdhdb.ub4spare[15]:                  0 ; 0x128: 0x00000000
kfdhdb.ub4spare[16]:                  0 ; 0x12c: 0x00000000
kfdhdb.ub4spare[17]:                  0 ; 0x130: 0x00000000
kfdhdb.ub4spare[18]:                  0 ; 0x134: 0x00000000
kfdhdb.ub4spare[19]:                  0 ; 0x138: 0x00000000
kfdhdb.ub4spare[20]:                  0 ; 0x13c: 0x00000000
kfdhdb.ub4spare[21]:                  0 ; 0x140: 0x00000000
kfdhdb.ub4spare[22]:                  0 ; 0x144: 0x00000000
kfdhdb.ub4spare[23]:                  0 ; 0x148: 0x00000000
kfdhdb.ub4spare[24]:                  0 ; 0x14c: 0x00000000
kfdhdb.ub4spare[25]:                  0 ; 0x150: 0x00000000
kfdhdb.ub4spare[26]:                  0 ; 0x154: 0x00000000
kfdhdb.ub4spare[27]:                  0 ; 0x158: 0x00000000
kfdhdb.ub4spare[28]:                  0 ; 0x15c: 0x00000000
kfdhdb.ub4spare[29]:                  0 ; 0x160: 0x00000000
kfdhdb.ub4spare[30]:                  0 ; 0x164: 0x00000000
kfdhdb.ub4spare[31]:                  0 ; 0x168: 0x00000000
kfdhdb.ub4spare[32]:                  0 ; 0x16c: 0x00000000
kfdhdb.ub4spare[33]:                  0 ; 0x170: 0x00000000
kfdhdb.ub4spare[34]:                  0 ; 0x174: 0x00000000
kfdhdb.ub4spare[35]:                  0 ; 0x178: 0x00000000
kfdhdb.ub4spare[36]:                  0 ; 0x17c: 0x00000000
kfdhdb.ub4spare[37]:                  0 ; 0x180: 0x00000000
kfdhdb.ub4spare[38]:                  0 ; 0x184: 0x00000000
kfdhdb.ub4spare[39]:                  0 ; 0x188: 0x00000000
kfdhdb.ub4spare[40]:                  0 ; 0x18c: 0x00000000
kfdhdb.ub4spare[41]:                  0 ; 0x190: 0x00000000
kfdhdb.ub4spare[42]:                  0 ; 0x194: 0x00000000
kfdhdb.ub4spare[43]:                  0 ; 0x198: 0x00000000
kfdhdb.ub4spare[44]:                  0 ; 0x19c: 0x00000000
kfdhdb.ub4spare[45]:                  0 ; 0x1a0: 0x00000000
kfdhdb.ub4spare[46]:                  0 ; 0x1a4: 0x00000000
kfdhdb.ub4spare[47]:                  0 ; 0x1a8: 0x00000000
kfdhdb.ub4spare[48]:                  0 ; 0x1ac: 0x00000000
kfdhdb.ub4spare[49]:                  0 ; 0x1b0: 0x00000000
kfdhdb.ub4spare[50]:                  0 ; 0x1b4: 0x00000000
kfdhdb.ub4spare[51]:                  0 ; 0x1b8: 0x00000000
kfdhdb.ub4spare[52]:                  0 ; 0x1bc: 0x00000000
kfdhdb.ub4spare[53]:                  0 ; 0x1c0: 0x00000000
kfdhdb.ub4spare[54]:                  0 ; 0x1c4: 0x00000000
kfdhdb.ub4spare[55]:                  0 ; 0x1c8: 0x00000000
kfdhdb.ub4spare[56]:                  0 ; 0x1cc: 0x00000000
kfdhdb.ub4spare[57]:                  0 ; 0x1d0: 0x00000000
kfdhdb.acdb.aba.seq:                  0 ; 0x1d4: 0x00000000
kfdhdb.acdb.aba.blk:                  0 ; 0x1d8: 0x00000000
kfdhdb.acdb.ents:                     0 ; 0x1dc: 0x0000
kfdhdb.acdb.ub2spare:                 0 ; 0x1de: 0x0000

上述kfed命令的输出结果显示这个asm块有两种类型的数据 以kfbh为前缀的块头信息和以kfdhdb为前缀的ASM磁盘头信息。实际上,每个ASM元数据块都会有块头信息和与块类型相匹配的一些相关数据。

disk header中重要的ASM元数据
kfbh.endian–系统字序,0表示大字序,1表示小字序
kfbh.type–ASM块类型,kfbtyp_diskhead表示这是一个ASM磁盘头类型块
kfbh.block.blk–ASM块号,0表示ASM磁盘头块的块编号

disk header中重要的ASM磁盘头数据
kfdhdb.driver.provstr–ASMLIB磁盘是ORCLDISK+磁盘名,非ASMLIB磁盘是ORCLDISK
kfdhdb.dsknum–ASM磁盘编号
kfdhdb.grptyp–磁盘冗余级别,KFDGTP_EXTERNAL代表external级别,KFDGTP_NORMAL代表normal级别,KFDGTP_HIGH代表high级别
kfdhdb.hdrsts–ASM磁盘头状态。v$ASM_DISK.HEADER_STATUS视图内包含的所有可能的状态
kfdhdb.dskname–ASM磁盘名
kfdhdb.grpname–ASM磁盘组名
kfdhdb.fgname –ASM故障组名
kfdhdb.crestmp.hi–磁盘添加到磁盘组的时间指示年,月,日,小时
kfdhdb.crestmp.lo–磁盘添加到磁盘组的时间指示分,秒,毫秒,微秒
kfdhdb.mntstmp.hi–磁盘最近一次被mount的时间指示年,月,日,小时
kfdhdb.mntstmp.lo–磁盘最近一次被mount的时间指示分,秒,毫秒,微秒
kfdhdb.secsize–磁盘的扇区大小(bytes)
kfdhdb.blksize–ASM元数据块的大小(bytes)
kfdhdb.ausize–Allocation unit分配单元大小(byte),默认的AU大小为1MB,我这里的AU为16MB
kfdhdb.dsksize–磁盘大小(以au为单位)。本例中的磁盘大小为AU*dsksize=16M*320=5GB
kfdhdb.fstlocn–指针指向ASM的空闲空间表,1代表本AU中的ASM块1
kfdhdb.altlocn–指针指向ASM的分配表,2代表本AU中的ASM块2
kfdhdb.f1b1locn–指针指向ASM的文件目录,2代表本ASM磁盘的AU2
kfdhdb.dbcompat–最小的数据库兼容版本,0x0a100000=10.1
kfdhdb.grpstmp.hi–指针指向ASM磁盘组创建的时间指示年,月,日,小时
kfdhdb.grpstmp.lo–指针指向ASM磁盘组创建的时间指示分,秒,毫秒,微秒

对于11G还增加了以下内容
kfdhdb.vfstart– Clusterware voting磁盘AU分配单元的开始AU编号。如果为0,表示磁盘不包含 voting磁盘数据。本特性只限于11.2或更高版本
kfdhdb.vfend — Clusterware voting磁盘AU分配单元的结束AU编号。如果为0,表示磁盘不包含 voting磁盘数据。本特性只限于11.2或更高版本
kfdhdb.spfile–ASM spfile参数文件的AU号。本特性限于11.2或更高版本
kfdhdb.spfflg–ASM spfile参数文件标识。如果这个值是1,ASM spfile参数文件则位于本磁盘的kfdhdb.spfile参数的AU。本特性限于11.2或更高版本

[grid@jyrac1 ~]$ kfed read /dev/raw/raw10 aun=0 blkn=0
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: blk=0
kfbh.block.obj:              2147483651 ; 0x008: disk=3
kfbh.check:                  3693686874 ; 0x00c: 0xdc29305a
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:         ORCLDISK ; 0x000: length=8
kfdhdb.driver.reserved[0]:            0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]:            0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                186646528 ; 0x020: 0x0b200000
kfdhdb.dsknum:                        3 ; 0x024: 0x0003
kfdhdb.grptyp:                        2 ; 0x026: KFDGTP_NORMAL
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname:             DATADG_0000 ; 0x028: length=11
kfdhdb.grpname:                  DATADG ; 0x048: length=6
kfdhdb.fgname:              DATADG_0000 ; 0x068: length=11
kfdhdb.capname:                         ; 0x088: length=0
kfdhdb.crestmp.hi:             33042831 ; 0x0a8: HOUR=0xf DAYS=0xc MNTH=0xc YEAR=0x7e0
kfdhdb.crestmp.lo:           2456905728 ; 0x0ac: USEC=0x0 MSEC=0x5a SECS=0x27 MINS=0x24
kfdhdb.mntstmp.hi:             33042897 ; 0x0b0: HOUR=0x11 DAYS=0xe MNTH=0xc YEAR=0x7e0
kfdhdb.mntstmp.lo:            144833536 ; 0x0b4: USEC=0x0 MSEC=0x7f SECS=0xa MINS=0x2
kfdhdb.secsize:                     512 ; 0x0b8: 0x0200
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000
kfdhdb.ausize:                  1048576 ; 0x0bc: 0x00100000
kfdhdb.mfact:                    113792 ; 0x0c0: 0x0001bc80
kfdhdb.dsksize:                    5120 ; 0x0c4: 0x00001400
kfdhdb.pmcnt:                         2 ; 0x0c8: 0x00000002
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002
kfdhdb.f1b1locn:                      0 ; 0x0d4: 0x00000000
kfdhdb.redomirrors[0]:                0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]:                0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]:                0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]:                0 ; 0x0de: 0x0000
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000
kfdhdb.grpstmp.hi:             33042831 ; 0x0e4: HOUR=0xf DAYS=0xc MNTH=0xc YEAR=0x7e0
kfdhdb.grpstmp.lo:           2456264704 ; 0x0e8: USEC=0x0 MSEC=0x1e8 SECS=0x26 MINS=0x24
kfdhdb.vfstart:                       0 ; 0x0ec: 0x00000000
kfdhdb.vfend:                         0 ; 0x0f0: 0x00000000
kfdhdb.spfile:                        0 ; 0x0f4: 0x00000000
kfdhdb.spfflg:                        0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[0]:                   0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[1]:                   0 ; 0x100: 0x00000000
kfdhdb.ub4spare[2]:                   0 ; 0x104: 0x00000000
kfdhdb.ub4spare[3]:                   0 ; 0x108: 0x00000000
kfdhdb.ub4spare[4]:                   0 ; 0x10c: 0x00000000
kfdhdb.ub4spare[5]:                   0 ; 0x110: 0x00000000
kfdhdb.ub4spare[6]:                   0 ; 0x114: 0x00000000
kfdhdb.ub4spare[7]:                   0 ; 0x118: 0x00000000
kfdhdb.ub4spare[8]:                   0 ; 0x11c: 0x00000000
kfdhdb.ub4spare[9]:                   0 ; 0x120: 0x00000000
kfdhdb.ub4spare[10]:                  0 ; 0x124: 0x00000000
kfdhdb.ub4spare[11]:                  0 ; 0x128: 0x00000000
kfdhdb.ub4spare[12]:                  0 ; 0x12c: 0x00000000
kfdhdb.ub4spare[13]:                  0 ; 0x130: 0x00000000
kfdhdb.ub4spare[14]:                  0 ; 0x134: 0x00000000
kfdhdb.ub4spare[15]:                  0 ; 0x138: 0x00000000
kfdhdb.ub4spare[16]:                  0 ; 0x13c: 0x00000000
kfdhdb.ub4spare[17]:                  0 ; 0x140: 0x00000000
kfdhdb.ub4spare[18]:                  0 ; 0x144: 0x00000000
kfdhdb.ub4spare[19]:                  0 ; 0x148: 0x00000000
kfdhdb.ub4spare[20]:                  0 ; 0x14c: 0x00000000
kfdhdb.ub4spare[21]:                  0 ; 0x150: 0x00000000
kfdhdb.ub4spare[22]:                  0 ; 0x154: 0x00000000
kfdhdb.ub4spare[23]:                  0 ; 0x158: 0x00000000
kfdhdb.ub4spare[24]:                  0 ; 0x15c: 0x00000000
kfdhdb.ub4spare[25]:                  0 ; 0x160: 0x00000000
kfdhdb.ub4spare[26]:                  0 ; 0x164: 0x00000000
kfdhdb.ub4spare[27]:                  0 ; 0x168: 0x00000000
kfdhdb.ub4spare[28]:                  0 ; 0x16c: 0x00000000
kfdhdb.ub4spare[29]:                  0 ; 0x170: 0x00000000
kfdhdb.ub4spare[30]:                  0 ; 0x174: 0x00000000
kfdhdb.ub4spare[31]:                  0 ; 0x178: 0x00000000
kfdhdb.ub4spare[32]:                  0 ; 0x17c: 0x00000000
kfdhdb.ub4spare[33]:                  0 ; 0x180: 0x00000000
kfdhdb.ub4spare[34]:                  0 ; 0x184: 0x00000000
kfdhdb.ub4spare[35]:                  0 ; 0x188: 0x00000000
kfdhdb.ub4spare[36]:                  0 ; 0x18c: 0x00000000
kfdhdb.ub4spare[37]:                  0 ; 0x190: 0x00000000
kfdhdb.ub4spare[38]:                  0 ; 0x194: 0x00000000
kfdhdb.ub4spare[39]:                  0 ; 0x198: 0x00000000
kfdhdb.ub4spare[40]:                  0 ; 0x19c: 0x00000000
kfdhdb.ub4spare[41]:                  0 ; 0x1a0: 0x00000000
kfdhdb.ub4spare[42]:                  0 ; 0x1a4: 0x00000000
kfdhdb.ub4spare[43]:                  0 ; 0x1a8: 0x00000000
kfdhdb.ub4spare[44]:                  0 ; 0x1ac: 0x00000000
kfdhdb.ub4spare[45]:                  0 ; 0x1b0: 0x00000000
kfdhdb.ub4spare[46]:                  0 ; 0x1b4: 0x00000000
kfdhdb.ub4spare[47]:                  0 ; 0x1b8: 0x00000000
kfdhdb.ub4spare[48]:                  0 ; 0x1bc: 0x00000000
kfdhdb.ub4spare[49]:                  0 ; 0x1c0: 0x00000000
kfdhdb.ub4spare[50]:                  0 ; 0x1c4: 0x00000000
kfdhdb.ub4spare[51]:                  0 ; 0x1c8: 0x00000000
kfdhdb.ub4spare[52]:                  0 ; 0x1cc: 0x00000000
kfdhdb.ub4spare[53]:                  0 ; 0x1d0: 0x00000000
kfdhdb.acdb.aba.seq:                  0 ; 0x1d4: 0x00000000
kfdhdb.acdb.aba.blk:                  0 ; 0x1d8: 0x00000000
kfdhdb.acdb.ents:                     0 ; 0x1dc: 0x0000
kfdhdb.acdb.ub2spare:                 0 ; 0x1de: 0x0000

ASM disk header的备份
ASM从10.2.0.5版本开始,磁盘头块的信息会自动备份到AU1的倒数第二个ASM元数据块中。知道AU的块大小和ASM元数据块的大小后,就能找到倒数第二个块的块编号。通过kfed工具可以从块头中读取到这些信息,并计算出AU1的倒数第二个块的块编号。

可以执行以下方法来进行计算第二个AU的倒数据第二个块的块编号

ausize=`kfed read /dev/disk | grep ausize | tr -s ' ' | cut -d' ' -f2`
blksize=`kfed read /dev/disk| grep blksize | tr -s ' ' | cut -d' ' -f2`
let n=$ausize/$blksize-2
echo $n

(ausize/blsize)-2

可以执行以下方法来进行计算第二个AU的倒数据第二个块所对应的整体块编号

(ausize/blsize)*2-2

例如在10.2.0.5计算第二个AU的倒数据第二个块的块编号的操作如下:

[oracle@jyrac3 ~]$ ausize=`kfed read /dev/raw/raw3 | grep ausize | tr -s ' ' | cut -d' ' -f2`
[oracle@jyrac3 ~]$ blksize=`kfed read /dev/raw/raw3 | grep blksize | tr -s ' ' | cut -d' ' -f2`
[oracle@jyrac3 ~]$ let n=$ausize/$blksize-2
[oracle@jyrac3 ~]$ echo $n
4094

SQL> select group_number,name,block_size,allocation_unit_size from v$asm_diskgroup;

GROUP_NUMBER NAME                           BLOCK_SIZE ALLOCATION_UNIT_SIZE
------------ ------------------------------ ---------- --------------------
           1 DATADG                               4096             16777216
           2 YBDG                                 4096             16777216

SQL> select 16777216/4096-2 from dual;

16777216/4096-2
---------------
           4094

例如在10.2.0.5进行计算第二个AU的倒数据第二个块所对应的整体块编号

SQL> select (16777216/4096)*2-2 from dual; 

(16777216/4096)*2-2
-------------------
               8190

其实计算第二个AU的倒数据第二个块所对应的整体块编号还可以跟踪kfed repair命令来查看它所读取的块号

[oracle@jyrac3 ~]$ strace -o trace_raw3 kfed repair /dev/raw/raw3 ausz=16777216
[oracle@jyrac3 ~]$ cat trace_raw3 
....省略....
open("/dev/raw/raw3", O_RDWR|O_LARGEFILE) = 5
_llseek(5, 33546240, [33546240], SEEK_SET) = 0
read(5, "\1\202\1\1\0\0\0\0\0\0\0\200\244.\306}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
_llseek(5, 0, [0], SEEK_SET)            = 0
read(5, "\1\202\1\1\0\0\0\0\0\0\0\200\244.\306}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
_llseek(5, 0, [0], SEEK_SET)            = 0
write(5, "\1\202\1\1\0\0\0\0\0\0\0\200\244.\306}\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096) = 4096
close(5)                                = 0
munmap(0x476000, 143360)                = 0
munmap(0x2bd000, 143360)                = 0
exit_group(0)                           = ?

从上面的4096可知每次读取4096 byte也就是4K,而从_llseek(5, 33546240, [33546240], SEEK_SET) = 0可以计算出来所在的块号=33546240/4096=8190,8190也就是磁盘头备份信息所对应的整体块号
下面查看10.2.0.5的磁盘头备份信息

[oracle@jyrac3 ~]$ kfed read /dev/raw/raw3  aun=1 blkn=4094 aus=16777216
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj:              2147483648 ; 0x008: TYPE=0x8 NUMB=0x0
kfbh.check:                  2110140068 ; 0x00c: 0x7dc62ea4
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:         ORCLDISK ; 0x000: length=8
kfdhdb.driver.reserved[0]:            0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]:            0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                168820736 ; 0x020: 0x0a100000
kfdhdb.dsknum:                        0 ; 0x024: 0x0000
kfdhdb.grptyp:                        2 ; 0x026: KFDGTP_NORMAL
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname:             DATADG_0000 ; 0x028: length=11
kfdhdb.grpname:                  DATADG ; 0x048: length=6
kfdhdb.fgname:              DATADG_0000 ; 0x068: length=11
kfdhdb.capname:                         ; 0x088: length=0
kfdhdb.crestmp.hi:             33042513 ; 0x0a8: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.crestmp.lo:            431214592 ; 0x0ac: USEC=0x0 MSEC=0xf4 SECS=0x1b MINS=0x6
kfdhdb.mntstmp.hi:             33042541 ; 0x0b0: HOUR=0xd DAYS=0x3 MNTH=0xc YEAR=0x7e0
kfdhdb.mntstmp.lo:           2841438208 ; 0x0b4: USEC=0x0 MSEC=0x33a SECS=0x15 MINS=0x2a
kfdhdb.secsize:                     512 ; 0x0b8: 0x0200
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000
kfdhdb.ausize:                 16777216 ; 0x0bc: 0x01000000
kfdhdb.mfact:                    454272 ; 0x0c0: 0x0006ee80
kfdhdb.dsksize:                     320 ; 0x0c4: 0x00000140
kfdhdb.pmcnt:                         2 ; 0x0c8: 0x00000002
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002
kfdhdb.f1b1locn:                      2 ; 0x0d4: 0x00000002
kfdhdb.redomirrors[0]:                0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]:                0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]:                0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]:                0 ; 0x0de: 0x0000
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000
kfdhdb.grpstmp.hi:             33042513 ; 0x0e4: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.grpstmp.lo:            428889088 ; 0x0e8: USEC=0x0 MSEC=0x15 SECS=0x19 MINS=0x6
kfdhdb.ub4spare[0]:                   0 ; 0x0ec: 0x00000000
kfdhdb.ub4spare[1]:                   0 ; 0x0f0: 0x00000000
kfdhdb.ub4spare[2]:                   0 ; 0x0f4: 0x00000000
kfdhdb.ub4spare[3]:                   0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[4]:                   0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[5]:                   0 ; 0x100: 0x00000000
kfdhdb.ub4spare[6]:                   0 ; 0x104: 0x00000000
kfdhdb.ub4spare[7]:                   0 ; 0x108: 0x00000000
kfdhdb.ub4spare[8]:                   0 ; 0x10c: 0x00000000
kfdhdb.ub4spare[9]:                   0 ; 0x110: 0x00000000
kfdhdb.ub4spare[10]:                  0 ; 0x114: 0x00000000
kfdhdb.ub4spare[11]:                  0 ; 0x118: 0x00000000
kfdhdb.ub4spare[12]:                  0 ; 0x11c: 0x00000000
kfdhdb.ub4spare[13]:                  0 ; 0x120: 0x00000000
kfdhdb.ub4spare[14]:                  0 ; 0x124: 0x00000000
kfdhdb.ub4spare[15]:                  0 ; 0x128: 0x00000000
kfdhdb.ub4spare[16]:                  0 ; 0x12c: 0x00000000
kfdhdb.ub4spare[17]:                  0 ; 0x130: 0x00000000
kfdhdb.ub4spare[18]:                  0 ; 0x134: 0x00000000
kfdhdb.ub4spare[19]:                  0 ; 0x138: 0x00000000
kfdhdb.ub4spare[20]:                  0 ; 0x13c: 0x00000000
kfdhdb.ub4spare[21]:                  0 ; 0x140: 0x00000000
kfdhdb.ub4spare[22]:                  0 ; 0x144: 0x00000000
kfdhdb.ub4spare[23]:                  0 ; 0x148: 0x00000000
kfdhdb.ub4spare[24]:                  0 ; 0x14c: 0x00000000
kfdhdb.ub4spare[25]:                  0 ; 0x150: 0x00000000
kfdhdb.ub4spare[26]:                  0 ; 0x154: 0x00000000
kfdhdb.ub4spare[27]:                  0 ; 0x158: 0x00000000
kfdhdb.ub4spare[28]:                  0 ; 0x15c: 0x00000000
kfdhdb.ub4spare[29]:                  0 ; 0x160: 0x00000000
kfdhdb.ub4spare[30]:                  0 ; 0x164: 0x00000000
kfdhdb.ub4spare[31]:                  0 ; 0x168: 0x00000000
kfdhdb.ub4spare[32]:                  0 ; 0x16c: 0x00000000
kfdhdb.ub4spare[33]:                  0 ; 0x170: 0x00000000
kfdhdb.ub4spare[34]:                  0 ; 0x174: 0x00000000
kfdhdb.ub4spare[35]:                  0 ; 0x178: 0x00000000
kfdhdb.ub4spare[36]:                  0 ; 0x17c: 0x00000000
kfdhdb.ub4spare[37]:                  0 ; 0x180: 0x00000000
kfdhdb.ub4spare[38]:                  0 ; 0x184: 0x00000000
kfdhdb.ub4spare[39]:                  0 ; 0x188: 0x00000000
kfdhdb.ub4spare[40]:                  0 ; 0x18c: 0x00000000
kfdhdb.ub4spare[41]:                  0 ; 0x190: 0x00000000
kfdhdb.ub4spare[42]:                  0 ; 0x194: 0x00000000
kfdhdb.ub4spare[43]:                  0 ; 0x198: 0x00000000
kfdhdb.ub4spare[44]:                  0 ; 0x19c: 0x00000000
kfdhdb.ub4spare[45]:                  0 ; 0x1a0: 0x00000000
kfdhdb.ub4spare[46]:                  0 ; 0x1a4: 0x00000000
kfdhdb.ub4spare[47]:                  0 ; 0x1a8: 0x00000000
kfdhdb.ub4spare[48]:                  0 ; 0x1ac: 0x00000000
kfdhdb.ub4spare[49]:                  0 ; 0x1b0: 0x00000000
kfdhdb.ub4spare[50]:                  0 ; 0x1b4: 0x00000000
kfdhdb.ub4spare[51]:                  0 ; 0x1b8: 0x00000000
kfdhdb.ub4spare[52]:                  0 ; 0x1bc: 0x00000000
kfdhdb.ub4spare[53]:                  0 ; 0x1c0: 0x00000000
kfdhdb.ub4spare[54]:                  0 ; 0x1c4: 0x00000000
kfdhdb.ub4spare[55]:                  0 ; 0x1c8: 0x00000000
kfdhdb.ub4spare[56]:                  0 ; 0x1cc: 0x00000000
kfdhdb.ub4spare[57]:                  0 ; 0x1d0: 0x00000000
kfdhdb.acdb.aba.seq:                  0 ; 0x1d4: 0x00000000
kfdhdb.acdb.aba.blk:                  0 ; 0x1d8: 0x00000000
kfdhdb.acdb.ents:                     0 ; 0x1dc: 0x0000
kfdhdb.acdb.ub2spare:                 0 ; 0x1de: 0x0000

能够看到与AU0的元数据块0相同的内容。当磁盘头被破坏或者丢失时,这个备份将是非常有用的。只需要运行kfed repair [磁盘名]命令即可修复,如果AU大小不是默认的1MB,还需要指定AU大小的具体值。 所上面的命令指定了aus参数

使用第二个AU的倒数据第二个块所对应的整体块编号来查看备份的磁盘头信息

[oracle@jyrac3 ~]$ kfed read /dev/raw/raw3  blkn=8190
kfbh.endian:                          1 ; 0x000: 0x01
kfbh.hard:                          130 ; 0x001: 0x82
kfbh.type:                            1 ; 0x002: KFBTYP_DISKHEAD
kfbh.datfmt:                          1 ; 0x003: 0x01
kfbh.block.blk:                       0 ; 0x004: T=0 NUMB=0x0
kfbh.block.obj:              2147483648 ; 0x008: TYPE=0x8 NUMB=0x0
kfbh.check:                  2110140068 ; 0x00c: 0x7dc62ea4
kfbh.fcn.base:                        0 ; 0x010: 0x00000000
kfbh.fcn.wrap:                        0 ; 0x014: 0x00000000
kfbh.spare1:                          0 ; 0x018: 0x00000000
kfbh.spare2:                          0 ; 0x01c: 0x00000000
kfdhdb.driver.provstr:         ORCLDISK ; 0x000: length=8
kfdhdb.driver.reserved[0]:            0 ; 0x008: 0x00000000
kfdhdb.driver.reserved[1]:            0 ; 0x00c: 0x00000000
kfdhdb.driver.reserved[2]:            0 ; 0x010: 0x00000000
kfdhdb.driver.reserved[3]:            0 ; 0x014: 0x00000000
kfdhdb.driver.reserved[4]:            0 ; 0x018: 0x00000000
kfdhdb.driver.reserved[5]:            0 ; 0x01c: 0x00000000
kfdhdb.compat:                168820736 ; 0x020: 0x0a100000
kfdhdb.dsknum:                        0 ; 0x024: 0x0000
kfdhdb.grptyp:                        2 ; 0x026: KFDGTP_NORMAL
kfdhdb.hdrsts:                        3 ; 0x027: KFDHDR_MEMBER
kfdhdb.dskname:             DATADG_0000 ; 0x028: length=11
kfdhdb.grpname:                  DATADG ; 0x048: length=6
kfdhdb.fgname:              DATADG_0000 ; 0x068: length=11
kfdhdb.capname:                         ; 0x088: length=0
kfdhdb.crestmp.hi:             33042513 ; 0x0a8: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.crestmp.lo:            431214592 ; 0x0ac: USEC=0x0 MSEC=0xf4 SECS=0x1b MINS=0x6
kfdhdb.mntstmp.hi:             33042541 ; 0x0b0: HOUR=0xd DAYS=0x3 MNTH=0xc YEAR=0x7e0
kfdhdb.mntstmp.lo:           2841438208 ; 0x0b4: USEC=0x0 MSEC=0x33a SECS=0x15 MINS=0x2a
kfdhdb.secsize:                     512 ; 0x0b8: 0x0200
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000
kfdhdb.ausize:                 16777216 ; 0x0bc: 0x01000000
kfdhdb.mfact:                    454272 ; 0x0c0: 0x0006ee80
kfdhdb.dsksize:                     320 ; 0x0c4: 0x00000140
kfdhdb.pmcnt:                         2 ; 0x0c8: 0x00000002
kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002
kfdhdb.f1b1locn:                      2 ; 0x0d4: 0x00000002
kfdhdb.redomirrors[0]:                0 ; 0x0d8: 0x0000
kfdhdb.redomirrors[1]:                0 ; 0x0da: 0x0000
kfdhdb.redomirrors[2]:                0 ; 0x0dc: 0x0000
kfdhdb.redomirrors[3]:                0 ; 0x0de: 0x0000
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000
kfdhdb.grpstmp.hi:             33042513 ; 0x0e4: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0
kfdhdb.grpstmp.lo:            428889088 ; 0x0e8: USEC=0x0 MSEC=0x15 SECS=0x19 MINS=0x6
kfdhdb.ub4spare[0]:                   0 ; 0x0ec: 0x00000000
kfdhdb.ub4spare[1]:                   0 ; 0x0f0: 0x00000000
kfdhdb.ub4spare[2]:                   0 ; 0x0f4: 0x00000000
kfdhdb.ub4spare[3]:                   0 ; 0x0f8: 0x00000000
kfdhdb.ub4spare[4]:                   0 ; 0x0fc: 0x00000000
kfdhdb.ub4spare[5]:                   0 ; 0x100: 0x00000000
kfdhdb.ub4spare[6]:                   0 ; 0x104: 0x00000000
kfdhdb.ub4spare[7]:                   0 ; 0x108: 0x00000000
kfdhdb.ub4spare[8]:                   0 ; 0x10c: 0x00000000
kfdhdb.ub4spare[9]:                   0 ; 0x110: 0x00000000
kfdhdb.ub4spare[10]:                  0 ; 0x114: 0x00000000
kfdhdb.ub4spare[11]:                  0 ; 0x118: 0x00000000
kfdhdb.ub4spare[12]:                  0 ; 0x11c: 0x00000000
kfdhdb.ub4spare[13]:                  0 ; 0x120: 0x00000000
kfdhdb.ub4spare[14]:                  0 ; 0x124: 0x00000000
kfdhdb.ub4spare[15]:                  0 ; 0x128: 0x00000000
kfdhdb.ub4spare[16]:                  0 ; 0x12c: 0x00000000
kfdhdb.ub4spare[17]:                  0 ; 0x130: 0x00000000
kfdhdb.ub4spare[18]:                  0 ; 0x134: 0x00000000
kfdhdb.ub4spare[19]:                  0 ; 0x138: 0x00000000
kfdhdb.ub4spare[20]:                  0 ; 0x13c: 0x00000000
kfdhdb.ub4spare[21]:                  0 ; 0x140: 0x00000000
kfdhdb.ub4spare[22]:                  0 ; 0x144: 0x00000000
kfdhdb.ub4spare[23]:                  0 ; 0x148: 0x00000000
kfdhdb.ub4spare[24]:                  0 ; 0x14c: 0x00000000
kfdhdb.ub4spare[25]:                  0 ; 0x150: 0x00000000
kfdhdb.ub4spare[26]:                  0 ; 0x154: 0x00000000
kfdhdb.ub4spare[27]:                  0 ; 0x158: 0x00000000
kfdhdb.ub4spare[28]:                  0 ; 0x15c: 0x00000000
kfdhdb.ub4spare[29]:                  0 ; 0x160: 0x00000000
kfdhdb.ub4spare[30]:                  0 ; 0x164: 0x00000000
kfdhdb.ub4spare[31]:                  0 ; 0x168: 0x00000000
kfdhdb.ub4spare[32]:                  0 ; 0x16c: 0x00000000
kfdhdb.ub4spare[33]:                  0 ; 0x170: 0x00000000
kfdhdb.ub4spare[34]:                  0 ; 0x174: 0x00000000
kfdhdb.ub4spare[35]:                  0 ; 0x178: 0x00000000
kfdhdb.ub4spare[36]:                  0 ; 0x17c: 0x00000000
kfdhdb.ub4spare[37]:                  0 ; 0x180: 0x00000000
kfdhdb.ub4spare[38]:                  0 ; 0x184: 0x00000000
kfdhdb.ub4spare[39]:                  0 ; 0x188: 0x00000000
kfdhdb.ub4spare[40]:                  0 ; 0x18c: 0x00000000
kfdhdb.ub4spare[41]:                  0 ; 0x190: 0x00000000
kfdhdb.ub4spare[42]:                  0 ; 0x194: 0x00000000
kfdhdb.ub4spare[43]:                  0 ; 0x198: 0x00000000
kfdhdb.ub4spare[44]:                  0 ; 0x19c: 0x00000000
kfdhdb.ub4spare[45]:                  0 ; 0x1a0: 0x00000000
kfdhdb.ub4spare[46]:                  0 ; 0x1a4: 0x00000000
kfdhdb.ub4spare[47]:                  0 ; 0x1a8: 0x00000000
kfdhdb.ub4spare[48]:                  0 ; 0x1ac: 0x00000000
kfdhdb.ub4spare[49]:                  0 ; 0x1b0: 0x00000000
kfdhdb.ub4spare[50]:                  0 ; 0x1b4: 0x00000000
kfdhdb.ub4spare[51]:                  0 ; 0x1b8: 0x00000000
kfdhdb.ub4spare[52]:                  0 ; 0x1bc: 0x00000000
kfdhdb.ub4spare[53]:                  0 ; 0x1c0: 0x00000000
kfdhdb.ub4spare[54]:                  0 ; 0x1c4: 0x00000000
kfdhdb.ub4spare[55]:                  0 ; 0x1c8: 0x00000000
kfdhdb.ub4spare[56]:                  0 ; 0x1cc: 0x00000000
kfdhdb.ub4spare[57]:                  0 ; 0x1d0: 0x00000000
kfdhdb.acdb.aba.seq:                  0 ; 0x1d4: 0x00000000
kfdhdb.acdb.aba.blk:                  0 ; 0x1d8: 0x00000000
kfdhdb.acdb.ents:                     0 ; 0x1dc: 0x0000
kfdhdb.acdb.ub2spare:                 0 ; 0x1de: 0x0000

能够看到与AU0的元数据块0相同的内容。

例如在11g计算第二个AU的倒数据第二个块的块编号的操作如下:

[grid@jyrac1 ~]$ ausize=`kfed read /dev/raw/raw10 | grep ausize | tr -s ' ' | cut -d' ' -f2`
[grid@jyrac1 ~]$ blksize=`kfed read /dev/raw/raw10 | grep blksize | tr -s ' ' | cut -d' ' -f2`
[grid@jyrac1 ~]$ let n=$ausize/$blksize-2
[grid@jyrac1 ~]$ echo $n
254

SQL> set long 400
SQL> set linesize 400
SQL> col name for a30
SQL> col path for a30
SQL> select group_number,disk_number,name,path,redundancy from v$asm_disk;

GROUP_NUMBER DISK_NUMBER NAME                           PATH                           REDUNDANCY
------------ ----------- ------------------------------ ------------------------------ --------------
           3           0 DATADG_0001                    /dev/raw/raw11                 UNKNOWN
           4           0 DATA_NRML_0000                 /dev/raw/raw5                  UNKNOWN
           3           3 DATADG_0000                    /dev/raw/raw10                 UNKNOWN
           1           1 ARCHDG_0001                    /dev/raw/raw9                  UNKNOWN
           4           3 DATA_NRML_0003                 /dev/raw/raw12                 UNKNOWN
           4           2 DATA_NRML_0002                 /dev/raw/raw7                  UNKNOWN
           2           1 CRSDG_0001                     /dev/raw/raw8                  UNKNOWN
           4           1 DATA_NRML_0001                 /dev/raw/raw6                  UNKNOWN
           1           0 ARCHDG_0000                    /dev/raw/raw2                  UNKNOWN
           3           1 DATADG_0003                    /dev/raw/raw4                  UNKNOWN
           4           4 DATA_NRML_0004                 /dev/raw/raw13                 UNKNOWN
           3           2 DATADG_0002                    /dev/raw/raw3                  UNKNOWN
           2           0 CRSDG_0000                     /dev/raw/raw1                  UNKNOWN
           4           5 DATA_NRML_0005                 /dev/raw/raw14                 UNKNOWN

14 rows selected.

SQL> select group_number,name,block_size,allocation_unit_size from v$asm_diskgroup;

GROUP_NUMBER NAME                           BLOCK_SIZE ALLOCATION_UNIT_SIZE
------------ ------------------------------ ---------- --------------------
           1 ARCHDG                               4096              1048576
           2 CRSDG                                4096              1048576
           3 DATADG                               4096              1048576
           4 DATA_NRML                            4096              1048576

SQL> select 1048576/4096-2 from dual;

1048576/4096-2
--------------
           254

例如在11g进行计算第二个AU的倒数据第二个块所对应的整体块编号

SQL> select (1048576/4096)*2-2 from dual;

(1048576/4096)*2-2
------------------
               510

对于默认的磁盘组,AU Size=1M ,每个AU中可以存储256个块,块号为0-255 。第1个AU存储256个块,第2个AU最后1个块号为255,倒数第2个块号是254,也就是整体的第510个块(从第1个AU的第1个块往后算起)。

使用bbed查看asm disk header
首先使用dd命令将disk header导出

[oracle@jyrac3 lib]$ dd if=/dev/raw/raw3 bs=4096 count=1 of=/u01/app/oracle/raw3_asm_header
1+0 records in
1+0 records out
4096 bytes (4.1 kB) copied, 0.0181451 seconds, 226 kB/s

使用bbed进行查看

[oracle@jyrac3 bin]$ ./bbed
Password: 

BBED: Release 2.0.0.0.0 - Limited Production on Tue Dec 20 20:50:58 2016

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

************* !!! For Oracle Internal Use only !!! ***************

BBED> set filename '/u01/app/oracle/raw3_asm_header'
        FILENAME        /u01/app/oracle/raw3_asm_header
BBED> show all
        FILE#           0
        BLOCK#          1  --这里显示的是file:0,block 1
        OFFSET          0
        DBA             0x00000000 (0 0,1)
        FILENAME        /u01/app/oracle/raw3_asm_header
        BIFILE          bifile.bbd
        LISTFILE       
        BLOCKSIZE       512
        MODE            Browse
        EDIT            Unrecoverable
        IBASE           Dec
        OBASE           Dec
        WIDTH           80
        COUNT           512
        LOGFILE         log.bbd
        SPOOL           No
BBED> map /v   --查看block1里的详细信息
 File: /u01/app/oracle/raw3_asm_header (0)
 Block: 1                                     Dba:0x00000000
------------------------------------------------------------
 Undo Segment Header

 struct kcbh, 20 bytes                      @0  --kcbh 的结构占用了20个bytes,@表示该信息在block里的偏移量,即offset值     
    ub1 type_kcbh                           @0       
    ub1 frmt_kcbh                           @1       
    ub1 spare1_kcbh                         @2       
    ub1 spare2_kcbh                         @3       
    ub4 rdba_kcbh                           @4       
    ub4 bas_kcbh                            @8       
    ub2 wrp_kcbh                            @12      
    ub1 seq_kcbh                            @14      
    ub1 flg_kcbh                            @15      
    ub2 chkval_kcbh                         @16      
    ub2 spare3_kcbh                         @18      

 struct ktect, 44 bytes                     @20      
    ub4 ktectspare                          @20      
    word ktecttsn                           @24      
    ub4 ktectobj                            @28      
    ub4 ktectnex                            @32      
    ub2 ktecttbe                            @36      
    ub4 ktectcex                            @40      
    ub4 ktectces                            @44      
    ub4 ktectcbk                            @48      
    struct ktectxid, 8 bytes                @52      
    ub1 ktectlck                            @60      

 struct ktetb[1], 8 bytes                   @64      
    ub4 ktetbdba                            @64      
    ub4 ktetbnbk                            @68      

 struct ktuxc, 104 bytes                    @18776   
    struct ktuxcscn, 8 bytes                @18776   
    struct ktuxcuba, 8 bytes                @18784   
    sb2 ktuxcflg                            @18792   
    ub2 ktuxcseq                            @18794   
    sb2 ktuxcnfb                            @18796   
    ub4 ktuxcinc                            @18800   
    sb2 ktuxcchd                            @18804   
    sb2 ktuxcctl                            @18806   
    ub2 ktuxcmgc                            @18808   
    ub4 ktuxcopt                            @18816   
    struct ktuxcfbp[5], 60 bytes            @18820   

 struct ktuxe[255], 10200 bytes             @18880   
    ub4 ktuxexid                            @18880   
    ub4 ktuxebrb                            @18884   
    struct ktuxescn, 8 bytes                @18888   
    sb4 ktuxesta                            @18896   
    ub1 ktuxecfl                            @18897   
    sb2 ktuxeuel                            @18898   

 ub4 tailchk                                @508     
BBED> p kcbh                 --查看kcbh 结构里的具体值
struct kcbh, 20 bytes                       @0       
   ub1 type_kcbh                            @0        0x01
   ub1 frmt_kcbh                            @1        0x82
   ub1 spare1_kcbh                          @2        0x01
   ub1 spare2_kcbh                          @3        0x01
   ub4 rdba_kcbh                            @4        0x00000000
   ub4 bas_kcbh                             @8        0x80000000
   ub2 wrp_kcbh                             @12       0x2ea4
   ub1 seq_kcbh                             @14       0xc6
   ub1 flg_kcbh                             @15       0x7d (KCBHFNEW, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x0000
   ub2 spare3_kcbh                          @18       0x0000
BBED> d /v count 4096              --dump 这个block,查看具体内容
 File: /u01/app/oracle/raw3_asm_header (0)
 Block: 1       Offsets:    0 to  511  Dba:0x00000000
-------------------------------------------------------
 01820101 00000000 00000080 a42ec67d l ...............}
 00000000 00000000 00000000 00000000 l ................
 4f52434c 4449534b 00000000 00000000 l ORCLDISK........
 00000000 00000000 00000000 00000000 l ................
 0000100a 00000203 44415441 44475f30 l ........DATADG_0
 30303000 00000000 00000000 00000000 l 000.............
 00000000 00000000 44415441 44470000 l ........DATADG..
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 44415441 44475f30 l ........DATADG_0
 30303000 00000000 00000000 00000000 l 000.............
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 5130f801 00d0b319 l ........Q0......
 6d30f801 00e85ca9 00020010 00000001 l m0....\.........
 80ee0600 40010000 02000000 01000000 l ....@...........
 02000000 02000000 00000000 00000000 l ................
 0000100a 5130f801 00549019 00000000 l ....Q0...T......
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................
 00000000 00000000 00000000 00000000 l ................

 <16 bytes per line>

BBED> 

这里每行16个字节,即每块4个字节,如:01820101,这块就由01,82,01和01这4个字节组成。
1)第1个byte 01–这里是对应的kfbh.endian 01即使1 表示的是Little Endian 相反,0的话即使表示BIGendian
2)第2个byte 82–这里对应kfbh.hard
3)第3个byte 01–这里对应kfbh.type
4)第4个byte 01–这里对应的是kfbh_datfmt
5)第5~8个byte 00 00 0000—这里对应的是kfbh.block.blk
6)第9~12个byte00 08 0008—这里对应的是kfbh.block.obj
7)第13~16个byte a42ec67d—这里对应的是kfbh.check(0x7dc62ea4) 因为操作系统是Little Endian的原因显示的内容与kfed读取到的是相反的
8)第17~20个byte00000000 —这里对应的是kfbh.fcn.base
9)第21~23个byte 00000000—这里对应的是kfbh.fcn.wrap
10)第24~27个byte 00000000 —这里对应的是kfbh.spare1
11)第28~32个byte 00000000 —这里对应的是kfbh.spare2
12)第33~40个byte 4f52434c 4449534b—这里对应的是kfdhdb.driver.provstr –从上面的dump信息可以看出具体的值
13)第41~64个byte 00 00 00 00 —这里对应的是kfdhdb.driver.reserved[0] ~~kfdhdb.driver.reserved[5]
14)第65~68个byte 0000100a —这里对应的是kfdhdb.compat即使我们的oracle版本号
15)第69~70个byte 0000 —这里对应的是kfdhdb.dsknum 即使disk numer 取值范围 0~65335
16)第71个byte 02 —这里对应的是kfdhdb.grptyp 即磁盘组的冗余方式 02 表示normal冗余
下面对该值的属性做一下补充:
KFDGTP_INVALID((kfdgtp)0)– Illegal value
KFDGTP_EXTERNAL ((kfdgtp)1)– External redundancy
KFDGTP_NORMAL ((kfdgtp)2)– Normal redundancy
KFDGTP_HIGH ((kfdgtp)3)– High redundancy

17)第72个byte 03 —这里对应是kfdhdb.hdrsts即disk group的状态 03表示正常(这里非常重要)
下面对改值的熟悉做一下补充:
KFDHDR_INVALID((kfdhdr)0)–Illegal value
KFDHDR_UNKNOWN((kfdhdr)1) –Disk header block unreadable
KFDHDR_CANDIDATE((kfdhdr)2) –No OSM or OS disk header found
KFDHDR_MEMBER ((kfdhdr)3) –Normal member of the group —03 正常状态
KFDHDR_FORMER ((kfdhdr)4) –Disk dropped cleanly from group
KFDHDR_CONFLICT ((kfdhdr)5) –Header conflicts
KFDHDR_INCOMPAT ((kfdhdr)6) –Written by incompatible software
KFDHDR_PROVISIONED ((kfdhdr)7) –Disk was preparedbeforehand
18)第73~104个byte44415441 44475f30 到00000000 32个byte —这里对应的是kfdhdb.dskname 即磁盘名称 我们这里的DATADG_0000
19) 第105~~136个byte 44415441 44470000 到00000000 32个byte —这里对应的是kfdhdb.grpname 即是磁盘组名称 DATADG
20)第137~ 168个byte 也是44415441 44475f301开始 32个byte —这里对应的是kfdhdb.fgname即failgroup name DATADG_0000
21)第169~200 个byte一共32个byte —这里对应的是kfdhdb.capname 即是Capacitygroup name当然我这里没有使用
22)第201~204个byte 5130f801 一共4个byte —这里对应的是kfdhdb.crestmp.hi 即Creation timestamp high

SQL> select to_number('01f83051','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('01F83051','XXXXXXXX
------------------------------
                      33042513

kfdhdb.crestmp.hi:             33042513 ; 0x0a8: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0


SQL> select to_number('7e0','xxxxxxxxxxxxxx') year,to_number('c','xxxxxxxxxxxxxx') month,to_number('2','xxxxxxxxxxxxxx') day,to_number('11','xxxxxxxxxxxxxx') hour from 

dual;
      YEAR      MONTH        DAY       HOUR
---------- ---------- ---------- ----------
      2016         12          2         17

23)第205~208个byte 00d0b319 一共4个byte —这里对应的是kfdhdb.crestmp.lo 即Creation timestamp low

SQL> select to_number('19b3d000','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('19B3D000','XXXXXXXX
------------------------------
                     431214592

kfdhdb.crestmp.lo:            431214592 ; 0x0ac: USEC=0x0 MSEC=0xf4 SECS=0x1b MINS=0x6
SQL> select to_number('6','xxxxxxxxxxxxxx') min,to_number('1b','xxxxxxxxxxxxxx') sec,to_number('f4','xxxxxxxxxxxxxx') ms,to_number('0','xxxxxxxxxxxxxx') us from dual;
       MIN        SEC         MS         US
---------- ---------- ---------- ----------
         6         27        244          0

与alert_+ASM1.log中的磁盘组创建时间相符

SQL> CREATE DISKGROUP datadg Normal REDUNDANCY  DISK '/dev/raw/raw3' SIZE 5120M ,
'/dev/raw/raw4' SIZE 5120M   

Fri Dec 02 17:06:27 CST 2016

24)第209~212个byte 6d30f801 一共4个byte —这里对应的是kfdhdb.mntstmp.hi

SQL> select to_number('01f8306d','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('01F8306D','XXXXXXXX
------------------------------
                      33042541
kfdhdb.mntstmp.hi:             33042541 ; 0x0b0: HOUR=0xd DAYS=0x3 MNTH=0xc YEAR=0x7e0
SQL> select to_number('7e0','xxxxxxxxxxxxxx') year,to_number('c','xxxxxxxxxxxxxx') month,to_number('3','xxxxxxxxxxxxxx') day,to_number('d','xxxxxxxxxxxxxx') hour from 

dual;
      YEAR      MONTH        DAY       HOUR
---------- ---------- ---------- ----------
      2016         12          3         13

25)第213~216个byte 00e85ca9 一共4个byte —这里对应的是kfdhdb.mntstmp.lo

SQL> select to_number('a95ce800','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('A95CE800','XXXXXXXX
------------------------------
                    2841438208

kfdhdb.mntstmp.lo:           2841438208 ; 0x0b4: USEC=0x0 MSEC=0x33a SECS=0x15 MINS=0x2a
SQL> select to_number('2a','xxxxxxxxxxxxxx') min,to_number('15','xxxxxxxxxxxxxx') sec,to_number('33a','xxxxxxxxxxxxxx') ms,to_number('0','xxxxxxxxxxxxxx') us from 

dual;
       MIN        SEC         MS         US
---------- ---------- ---------- ----------
        42         21        826          0

与alert_+ASM1.log中的磁盘组mount时间相符

Sat Dec 03 13:42:21 CST 2016
NOTE: 
cache mounting group 1/0xB7D9694E (DATADG) succeeded

SUCCESS: diskgroup DATADG was mounted

26)第217~218一共2个byte 0002 —这里对应的是kfdhdb.secsize 即physical sector size of the disk

SQL> select to_number('0200','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('0200','XXXXXXXXXXXX
------------------------------
                           512
 kfdhdb.secsize:                     512 ; 0x0b8: 0x0200

27)第219~220一共2个byte 0010 —这里对应的是fdhdb.blksize即metadata blocksize asm block大小

SQL> select to_number('1000','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('1000','XXXXXXXXXXXX
------------------------------
                          4096
kfdhdb.blksize:                    4096 ; 0x0ba: 0x1000

28)第221~224一共4个byte 00000001 —这里对应的是kfdhdb.ausize即AU 的大小16777216 即是16m

SQL> select to_number('01000000','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('01000000','XXXXXXXX
------------------------------
                      16777216
kfdhdb.ausize:                 16777216 ; 0x0bc: 0x01000000


29)第225~228一共4个byte 80ee0600—这里对应的是kfdhdb.mfact 即Stride between physical addresses of allocation units

SQL> select to_number('0006ee80','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('0006EE80','XXXXXXXX
------------------------------
                        454272

kfdhdb.mfact:                    454272 ; 0x0c0: 0x0006ee80

30)第229~232一共4个byte 40010000 —这里对应的是kfdhdb.dsksize 即0x00000140 转换为10进制后为320,即320个分配units =磁盘大小=320*16=5120M=5G

SQL> select to_number('00000140','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('00000140','XXXXXXXX
------------------------------
                           320
kfdhdb.dsksize:                     320 ; 0x0c4: 0x00000140

31)第233~236一共4个byte 02000000—这里对应的是kfdhdb.pmcnt 这里该值是2即 Number of physically addressed allocation units

SQL> select to_number('00000002','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('00000002','XXXXXXXX
------------------------------
                             2
kfdhdb.pmcnt:                         2 ; 0x0c8: 0x00000002

32)第237~240一共4个byte 01000000 —这里对应的是kfdhdb.fstlocn即First FreeSpace table block number used to find freespace。

SQL> select to_number('00000001','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('00000001','XXXXXXXX
------------------------------
                             1

kfdhdb.fstlocn:                       1 ; 0x0cc: 0x00000001

33)第241~244一共4个byte 02000000 —这里对应的是kfdhdb.altlocn即First Alocation table block numer used to find allocated space

SQL> select to_number('00000002','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('00000002','XXXXXXXX
------------------------------
                             2
kfdhdb.altlocn:                       2 ; 0x0d0: 0x00000002

34)第245~248 一共4个byte 02000000 —这里对应的是kfdhdb.f1b1locn 即File Directory block 1 Allocation Unit number. Beginging for filedirectory

SQL> select to_number('00000002','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('00000002','XXXXXXXX
------------------------------
                             2
kfdhdb.f1b1locn:                      2 ; 0x0d4: 0x00000002

即是第一个file directory 通常这里是2

35)第249~250一共2个byte 0000 —这里对应的是kfdhdb.redomirrors[0]
36)第251~252一共2个byte 0000 —这里对应的是kfdhdb.redomirrors[1]
37)第253~254一共2个byte 0000 —这里对应的是kfdhdb.redomirrors[2]
38)第255~256一共2个byte 0000 —这里对应的是kfdhdb.redomirrors[3]

39)第257~260一共4个byte 0000100a—这里对应的是kfdhdb.dbcompat 转换以为即为我们的数据库版本

SQL> select to_number('0a100000','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('0A100000','XXXXXXXX
------------------------------
                     168820736
kfdhdb.dbcompat:              168820736 ; 0x0e0: 0x0a100000


40)第260~264一共4个byte 5130f801 —这里对应的是kfdhdb.grpstmp.hi

SQL> select to_number('01f83051','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('01F83051','XXXXXXXX
------------------------------
                      33042513

kfdhdb.grpstmp.hi:             33042513 ; 0x0e4: HOUR=0x11 DAYS=0x2 MNTH=0xc YEAR=0x7e0

SQL> select to_number('7e0','xxxxxxxxxxxxxx') year,to_number('c','xxxxxxxxxxxxxx') month,to_number('2','xxxxxxxxxxxxxx') day,to_number('11','xxxxxxxxxxxxxx') hour from 

dual;
      YEAR      MONTH        DAY       HOUR
---------- ---------- ---------- ----------
      2016         12          2         17

41)第265~268 一共4个byte 00549019 —这里对应的是kfdhdb.grpstmp.lo

SQL> select to_number('19905400','xxxxxxxxxxxxxx') from dual;
TO_NUMBER('19905400','XXXXXXXX
------------------------------
                     428889088

kfdhdb.grpstmp.lo:            428889088 ; 0x0e8: USEC=0x0 MSEC=0x15 SECS=0x19 MINS=0x6
SQL> select to_number('6','xxxxxxxxxxxxxx') min,to_number('19','xxxxxxxxxxxxxx') sec,to_number('15','xxxxxxxxxxxxxx') ms,to_number('0','xxxxxxxxxxxxxx') us from dual;
       MIN        SEC         MS         US
---------- ---------- ---------- ----------
         6         25         21          0

using dbms_file_transfer transportable tablespace between asm

这里介绍当原数据库与目标数据库使用ASM存储数据文件时如何传输表空间。这里将介绍如何使用标准工具比如DataPump与dbms_file_transfer软件包来完成表空间的传输。

下面的例子中将表空间test从一个RAC数据库的ASM磁盘组传输到另一个RAC数据禀报ASM磁盘组
1.在原数据库上创建或使用一个已经存在的表空间

SQL> show parameter db_create_file_dest

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      +DATADG

SQL> create tablespace test;

Tablespace created.


SQL> col name for a15
SQL> col file_name for a50
SQL> select b.name,a.name as file_name from v$datafile a ,v$tablespace b where  a.ts#=b.ts# and b.name='TEST';

NAME            FILE_NAME
--------------- --------------------------------------------------
TEST            +DATADG/test/datafile/test.269.930512093

2.创建用户test与测试表emp

SQL> create user test identified by "test" default tablespace test temporary tablespace  temp;

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

SQL> conn test/test
Connected.
SQL> create table emp as select * from scott.emp;

Table created.

SQL> select count(*) from test.emp;

  COUNT(*)
----------
        14

3.检查确保表空间是自包含也就是检查表空间的对象不依赖于其它表空间的对象而独立存在

SQL> conn / as sysdba
Connected.
SQL> execute dbms_tts.transport_set_check('test',true);

PL/SQL procedure successfully completed.

4.查询transport_set_violations视图,来查看是否有违反依赖的对象存在

SQL> select * from transport_set_violations;

no rows selected

5.在原数据库服务器上编辑tnsnames.ora文件来创建一个新的服务名来指向目标数据库

[oracle@jyrac3 admin]$ vi tnsnames.ora
JYRAC =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 10.13.10.153)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = jyrac)
    )
  )

6.在原数据库服务器上使用system用户来创建dblink来链接到目标数据库。这是因为使用 dbms_file_transfer来在两个数据库之间移动元数据所需要

SQL> conn system/system
Connected.
SQL> create database link JYRAC connect to system identified by system using 'JYRAC';

Database link created.

SQL> select count(*) from dba_tables@JYRAC;

  COUNT(*)
----------
      2138

7.在原数据库上创建目录对象tts_dump,tts_dump_log,tts_datafile来存储 dumpfile,logfile,datafile

[root@jyrac3 /]# mkdir tts
[root@jyrac3 /]# chown oracle:oinstall tts
[root@jyrac3 /]# chmod 777 tts

SQL> create directory tts_dump as '+datadg/';

Directory created.

SQL> create directory tts_dump_log as '/tts';

Directory created.


SQL> create directory tts_datafile as '+datadg/test/datafile/';

Directory created.

将给要执行导出元数据的用户system授予对上面所创建的三个目录读写权限

SQL> grant read,write on directory tts_dump to system;

Grant succeeded.

SQL> grant read,write on directory tts_dump_log to system;

Grant succeeded.

SQL> grant read,write on directory tts_datafile to system;

Grant succeeded.

8.在目标数据库重复步骤7的操作

[root@jyrac1 /]# mkdir tts
[root@jyrac1 /]# chown oracle:oinstall tts
[root@jyrac1 /]# chmod 777 tts

SQL> create directory tts_dump as '+datadg/';

Directory created.

SQL> create directory tts_dump_log as '/tts';

Directory created.

SQL> create directory tts_datafile as '+datadg/jyrac/datafile/';

Directory created.

SQL> grant read,write on directory tts_dump to system;

Grant succeeded.

SQL> grant read,write on directory tts_dump_log to system;

Grant succeeded.

SQL> grant read,write on directory tts_datafile to system;

Grant succeeded.

9.使用原数据库要被传输的表空间test设置为只读模式

SQL> alter tablespace test read only;

Tablespace altered.

10.检查原数据库被传输表空间test的状态是否为只读模式

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';

TABLESPACE_NAME                STATUS
------------------------------ ---------
TEST                           READ ONLY

11.导出元数据

[oracle@jyrac3 /]$ expdp system/system directory=tts_dump dumpfile=tts.dmp  logfile=tts_dump_log:tts.log transport_tablespaces=test transport_full_check=y

Export: Release 10.2.0.5.0 - Production on Tuesday, 13 December, 2016 20:17:10

Copyright (c) 2003, 2007, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/******** directory=tts_dump  dumpfile=tts.dmp logfile=tts_dump_log:tts.log transport_tablespaces=test  transport_full_check=y
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Master table "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 is:
  +DATADG/tts.dmp
Job "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" successfully completed at 20:21:52

12.使用dbms_file_transfer将导出的元数据dump文件发送到目标数据库服务器

SQL> conn system/system
Connected.

SQL> begin
  2   dbms_file_transfer.put_file(
  3       source_directory_object=>'TTS_DUMP',
  4       source_file_name=>'tts.dmp',
  5       destination_directory_object=>'TTS_DUMP',
  6       destination_file_name=>'tts.dmp',
  7       destination_database=>'JYRAC');
  8  end;
  9  /

PL/SQL procedure successfully completed.

13.查看表空间test的数据文件名

SQL> select file_name from dba_data_files  where tablespace_name='TEST';

FILE_NAME
--------------------------------------------------
+DATADG/test/datafile/test.269.930512093

14.使用dbms_file_transfer来传输表空间test的数据文件

SQL> begin
  2   dbms_file_transfer.put_file(
  3       source_directory_object=>'TTS_DATAFILE',
  4       source_file_name=>'test.269.930512093',
  5       destination_directory_object=>'TTS_DATAFILE',
  6       destination_file_name=>'test01.dbf',
  7       destination_database=>'JYRAC');
  8  end;
  9  /

PL/SQL procedure successfully completed.

ASMCMD [+DATADG/jyrac/datafile] > ls -l
Type      Redund  Striped  Time             Sys  Name
DATAFILE  MIRROR  COARSE   DEC 12 16:00:00  Y    EXAMPLE.260.930413057
DATAFILE  MIRROR  COARSE   DEC 13 20:00:00  Y    FILE_TRANSFER.270.930515465
DATAFILE  MIRROR  COARSE   DEC 13 13:00:00  Y    SYSAUX.258.930413055
DATAFILE  MIRROR  COARSE   DEC 13 11:00:00  Y    SYSTEM.259.930413057
DATAFILE  MIRROR  COARSE   DEC 12 16:00:00  Y    UNDOTBS1.262.930413057
DATAFILE  MIRROR  COARSE   DEC 12 16:00:00  Y    UNDOTBS2.261.930413057
DATAFILE  MIRROR  COARSE   DEC 13 10:00:00  Y    USERS.263.930413057
                                            N    test01.dbf =>  +DATADG/JYRAC/DATAFILE/FILE_TRANSFER.270.930515465

15.在目标数据库服务器上使用datapump导入数据文件元数据

SQL> create user test identified by "test";

User created.

SQL> grant dba,connect,resource to test;

Grant succeeded.

[oracle@jyrac1 dbs]$ impdp system/system directory=tts_dump dumpfile=tts.dmp  logfile=tts_dump_log:tts.log transport_datafiles='+DATADG/jyrac/datafile/test01.dbf'  keep_master=y

Import: Release 11.2.0.4.0 - Production on Tue Dec 13 20:45:11 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit  Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_02" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_02":  system/******** directory=tts_dump  dumpfile=tts.dmp logfile=tts_dump_log:tts.log transport_datafiles= +DATADG/jyrac/datafile/test01.dbf keep_master=y
Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
Processing object type TRANSPORTABLE_EXPORT/TABLE
Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
Job "SYSTEM"."SYS_IMPORT_TRANSPORTABLE_02" successfully completed at Tue Dec 13 20:45:17  2016 elapsed 0 00:00:05

16.将原数据库中的表空间test设置为读写模式

SQL> alter tablespace test read write;

Tablespace altered.

SQL> select tablespace_name,status from dba_tablespaces where tablespace_name='TEST';

TABLESPACE_NAME                STATUS
------------------------------ ---------
TEST                           ONLINE

17.在目标数据库中验证表空间数据文件是否成功附加

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
+DATADG/jyrac/datafile/system.259.930413057
+DATADG/jyrac/datafile/sysaux.258.930413055
+DATADG/jyrac/datafile/undotbs1.262.930413057
+DATADG/jyrac/datafile/users.263.930413057
+DATADG/jyrac/datafile/example.260.930413057
+DATADG/jyrac/datafile/undotbs2.261.930413057
+DATADG/jyrac/datafile/test01.dbf

18.验证表emp中的数据是否存在

SQL> select count(*) from test.emp;

  COUNT(*)
----------
        14

可以看到通过传输表空间后表emp中的数据与原数据库中一致。

Using FTP Transferring Non-ASM Datafiles to ASM diskgroup

可以使用XML DB中的虚拟目录功能来将Non-ASM数据文件传输到ASM磁盘组,可以通过XML DB协议比如 FTP,HTTP与API来维护ASM文件与目录。使用这种方法,ASM虚拟目录作为/sys/asm被mount。目录是虚 拟的,使用XML DB ASM目录与文件不能物理存储。然而对ASM虚拟目录ASM组件可以执行任何操作。为了使用了这种方法来传输文件,最重要的就是安装与配置XML DB。

ASM虚拟目录缺省情况下是在安装XML DB时创建。如果使用ASM的数据库没有配置,那么这个目录将是 空间并且不允许操作。如果ASM被配置,ASM虚拟目录,/sys/asm,会被mounted。ASM目录对于每个被 mount的磁盘组都有一个子目录。每个磁盘组目录对于每个数据库名包含一个子目录。另外,还可能 包含管理员所创建的其它文件以及与目标相关的别名。

下面的例子使用ftp方式来传输文件
1.以root用户来检查ftp服务是否启用

[root@jyrac1 ~]# netstat -a | grep ftp
tcp        0      0 *:ftp                       *:*                         LISTEN

2.对XML DB配置FTP与HTTP端口

[oracle@jyrac1 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec 13 11:14:48 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options

SQL> execute dbms_xdb.sethttpport(8080);

PL/SQL procedure successfully completed.

SQL> execute dbms_xdb.setftpport(2100);

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.


SQL> select dbms_xdb.getftpport() from dual;

DBMS_XDB.GETFTPPORT()
---------------------
                 2100

SQL> select dbms_xdb.gethttpport() from dual;

DBMS_XDB.GETHTTPPORT()
----------------------
                  8080

3.检查XML DB的dispatchers的配置如果没有设置就需要设置
对于单实例设置如下:

alter system set dispatchers = (PROTOCOL=TCP) (SERVICE=XDB)" scope=both

对于RAC实例,执行以下命令:

SQL> alter system set dispatchers ='(PROTOCOL=TCP) (SERVICE=jyrac1XDB)' scope=both  sid='jyrac1';

System altered.

SQL> alter system set dispatchers ='(PROTOCOL=TCP) (SERVICE=jyrac2XDB)' scope=both  sid='jyrac2';

System altered.

4.如果缺省监听没有使用的话,需要设置local_listener参数,例如可能需要将端口设置为1521。如需要重启监听

[grid@jyrac1 ~]$ srvctl stop listener -n jyrac1
[grid@jyrac1 ~]$ srvctl stop listener -n jyrac2
[grid@jyrac1 ~]$ srvctl start listener -n jyrac1
[grid@jyrac1 ~]$ srvctl start listener -n jyrac2

5.验证监听是否已经注册了FTP和HTTP

[grid@jyrac1 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-DEC-2016 11:39:25

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                13-DEC-2016 11:39:15
Uptime                    0 days 0 hr. 0 min. 9 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/product/11.2.0/crs/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/jyrac1/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.153)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac1)(PORT=2100))(Presentation=FTP) (Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac1)(PORT=8080))(Presentation=HTTP) (Session=RAW))
Services Summary...
Service "jyrac" has 1 instance(s).
  Instance "jyrac1", status READY, has 4 handler(s) for this service...
Service "jyrac1XDB" has 1 instance(s).
  Instance "jyrac1", status READY, has 1 handler(s) for this service...
Service "jyracXDB" has 1 instance(s).
  Instance "jyrac1", status READY, has 0 handler(s) for this service...
The command completed successfully

[grid@jyrac2 ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 13-DEC-2016 11:39:43

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.4.0 - Production
Start Date                13-DEC-2016 11:39:22
Uptime                    0 days 0 hr. 0 min. 21 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/product/11.2.0/crs/network/admin/listener.ora
Listener Log File         /u01/app/grid/diag/tnslsnr/jyrac2/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.138.130.154)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac2)(PORT=2100))(Presentation=FTP) (Session=RAW))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac2)(PORT=8080))(Presentation=HTTP) (Session=RAW))
Services Summary...
Service "jyrac" has 1 instance(s).
  Instance "jyrac2", status READY, has 4 handler(s) for this service...
Service "jyrac2XDB" has 1 instance(s).
  Instance "jyrac2", status READY, has 1 handler(s) for this service...
Service "jyracXDB" has 1 instance(s).
  Instance "jyrac2", status READY, has 0 handler(s) for this service...
The command completed successfully

在两个节点输出的监听信息可以看到以下信息,说明监听已经注册了FTP与HTTP

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac2)(PORT=8080))(Presentation=HTTP) (Session=RAW))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=jyrac2)(PORT=2100))(Presentation=FTP) (Session=RAW))

6.验证数据库中是否存在无效的XML DB相关的软件包

SQL> select count(*)from dba_objects where owner='XDB' and status='INVALID';

  COUNT(*)
----------
         0

7.验证dba_registry中的XML DB状态

SQL> col comp_id for a15
SQL> col version for a15
SQL> col comp_name for a30
SQL> col status for a15
SQL> select comp_name, status, version from dba_registry where comp_name = 'Oracle XML  Database';

COMP_NAME                      STATUS          VERSION
------------------------------ --------------- ---------------
Oracle XML Database            VALID           11.2.0.4.0

8.登录XML DB ftp

[oracle@jyrac1 ~]$ ftp jyrac1 2100
Connected to jyrac1.
220- jyrac1
Unauthorised use of this FTP server is prohibited and may be subject to civil and  criminal prosecution.
220 jyrac1 FTP Server (Oracle XML DB/Oracle Database) ready.
530  Please login with USER and PASS.
530  Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (jyrac1:oracle): system
331 pass required for SYSTEM
Password:
230 SYSTEM logged in
Remote system type is Unix.

9.使用XML DB FTP来传输文件,该命令与标准的FTP命令相同

ftp> cd /sys/asm
250 CWD Command successful

ftp> cd datadg/jyrac/datafile
250 CWD Command successful
ftp> ls -lrt
227 Entering Passive Mode (127,0,0,1,84,36)
150 ASCII Data Connection
-rw-r--r--   1 SYS      oracle  1121984512 DEC 13 03:44 SYSAUX.258.930413055
-rw-r--r--   1 SYS      oracle  796925952 DEC 13 03:44 SYSTEM.259.930413057
-rw-r--r--   1 SYS      oracle  363077632 DEC 13 03:44 EXAMPLE.260.930413057
-rw-r--r--   1 SYS      oracle  157294592 DEC 13 03:44 UNDOTBS2.261.930413057
-rw-r--r--   1 SYS      oracle  104865792 DEC 13 03:44 UNDOTBS1.262.930413057
-rw-r--r--   1 SYS      oracle   5251072 DEC 13 03:44 USERS.263.930413057
226 ASCII Transfer Complete

ftp> bin
200  Type set to I.
ftp> get SYSTEM.259.930413057
local: SYSTEM.259.930413057 remote: SYSTEM.259.930413057
227 Entering Passive Mode (127,0,0,1,71,155)
150 BIN Data Connection
226 BIN Transfer Complete
796925952 bytes received in 46 seconds (1.7e+04 Kbytes/s)

验证传输的文件

[root@jyrac1 sys]# find / -name SYSTEM.259.930413057
/home/oracle/SYSTEM.259.930413057
[root@jyrac1 sys]# cd /home/oracle/
[root@jyrac1 oracle]# ls -lrt
total 779012
-rw-r--r-- 1 oracle oinstall 796925952 Dec 13 11:46 SYSTEM.259.930413057

使用dbms_file_transfer转换ASM文件

dbms_file_transfer是一个存储过程它是在Oracle 9i中引入的,这个包提供了在两个目录(在相同主 机或数据库)之间复制文件的方法。从Oracle 10gr1,ASM使用这个工具在ASM磁盘组之间复制文件, 并且它是实例化ASM DataGuard数据库的主要工具。在Oracle 10gr2中,dbms_file_transfer被增强 来支持ASM与non-ASM文件的组合传输。

dbms_file_trasnfer包能让DBA在两个目录之间复制文件。这个过程被用来在ASM磁盘组之间移动或复 制文件。对于以下情况可以使用这个过程来复制文件:
.从一个ASM磁盘组复制文件到另一个ASM磁盘组
.从一个ASM磁盘组复制文件到外部存储介质,比如操作系统级别的文件系统
.从操作系统级别的文件系统复制文件到ASM磁盘组
.从操作系统级别的文件系统复制文件到另一个目录或裸设备

下面的例子将演示如何使用dbms_file_transfer来将文件从一个目录移动到另一个目录:
1.识别要从一个目录移动或复制到另一个目录的数据文件

SQL> select file_name from dba_data_files;

FILE_NAME
------------------------------------------------------------
+DATADG/jyrac/datafile/users.263.930413057
+DATADG/jyrac/datafile/undotbs1.262.930413057
+DATADG/jyrac/datafile/sysaux.258.930413055
+DATADG/jyrac/datafile/system.259.930413057
+DATADG/jyrac/datafile/example.260.930413057
+DATADG/jyrac/datafile/undotbs2.261.930413057

2.识别要存储复制文件的目录(ASM或non-ASM),在这里文件被复制到操作系统文件系统中。

3.将数据文件脱机:

SQL> alter database datafile '+DATADG/jyrac/datafile/users.263.930413057' offline;

Database altered.

4.对原文件目录与目标目录使用以下操作来创建directory_name并将文件复制到新目录

SQL> alter database datafile '+DATADG/jyrac/datafile/users.263.930413057' offline;

Database altered.

SQL> create directory asmsrc as '+DATADG/jyrac/datafile/';

Directory created.

SQL> create directory osdest as '/rman_backup/transfer/';

Directory created.

SQL> begin
  2   dbms_file_transfer.copy_file ('ASMSRC','users.263.930413057','OSDEST','users01.dbf');
  3  end;
  4  /

PL/SQL procedure successfully completed.

5.将数据文件联机

SQL>  recover datafile '+DATADG/jyrac/datafile/users.263.930413057';
ORA-00279: change 3079902 generated at 12/12/2016 16:07:01 needed for thread 1
ORA-00289: suggestion : +ARCHDG/jyrac/1_1_930413221.dbf
ORA-00280: change 3079902 for thread 1 is in sequence #1


Specify log: {=suggested | filename | AUTO | CANCEL}
AUTO
ORA-00279: change 3105677 generated at 12/13/2016 07:00:07 needed for thread 1
ORA-00289: suggestion : +ARCHDG/jyrac/1_2_930413221.dbf
ORA-00280: change 3105677 for thread 1 is in sequence #2


Log applied.
Media recovery complete.
SQL> alter database datafile '+DATADG/jyrac/datafile/users.263.930413057' online;

Database altered.

6.验证复制文件

[oracle@jyrac1 transfer]$ ls -lrt
total 5140
-rw-r----- 1 oracle asmadmin 5251072 Dec 13 10:35 users01.dbf

在11g就可以使用列简单的cp命令进行文件复制,不需要使用这种方法。

ASMCMD执行ASM元数据备份与还原

备份你的磁盘组通常来说是不需要的,因为可以简单的重建它并且还原它的内容。用户创建或定义大 量用户模板,别名与目录并且磁盘组需要重新建,你需要手动重新创建这些ASM用户对象。这了完成 这个任务,Oracle 11g引入了新的工具来备份ASM对象的元数据。新的工具, ASM Metadata Backup adn Restore(AMBR),它是ASMCMD的一个子组件。AMBR提供了使用完全相同模板,属性与别名目录结 构来重新创建之前创建过的ASM磁盘组,因此保护磁盘组结构。AMBR有两种模式:备份与还原。

备份模式
使用备份模式,关于ASM磁盘,磁盘组与故障磁盘组配置,模板,属性与别名目录结构等信息会被收 集。这此虎将被转换成SQL命令并以存储在用户定义的元数据备份(MDB)文件中,在执行磁盘组还原时供md_restore命令使用。这个文件包含还原操作可以重建与还原整个磁盘组的所需要的元数据信息 。下面是备份元数据的语法:

[grid@jyrac1 ~]$ asmcmd help md_backup
        md_backup

        The md_backup command creates a backup file containing metadata
        for one or more disk groups.
        Volume and Oracle Automatic Storage Management Cluster File System
        (Oracle ACFS) file system information is not backed up.

        md_backup backup_file [-G diskgroup [,diskgroup,...]]

        The options for the md_backup command are described below.

        backup_file     - Specifies the backup file in which you want to
                          store the metadata.
        -G diskgroup    - Specifies the disk group name of the disk group
                          that must be backed up

        By default all the mounted disk groups are included in the backup file,
        which is saved in the current working directory.

        The first example shows the use of the backup command when you run it
        without the disk group option. This example backs up all of the mounted
        disk groups and creates the backup image in the current working
        directory. The second example creates a backup of disk group DATA and
        FRA. The backup that this example creates is saved in the
        /tmp/dgbackup20090716 file.

        ASMCMD [+] > md_backup /tmp/dgbackup20090716
        ASMCMD [+] > md_backup /tmp/dgbackup20090716 -G DATA,FRA
        Disk group metadata to be backed up: DATA
        Disk group metadata to be backed up: FRA
        Current alias directory path: ASM/ASMPARAMETERFILE
        Current alias directory path: ORCL/DATAFILE
        Current alias directory path: ORCL/TEMPFILE
        Current alias directory path: ORCL/CONTROLFILE
        Current alias directory path: ORCL/PARAMETERFILE
        Current alias directory path: ASM
        Current alias directory path: ORCL/ONLINELOG
        Current alias directory path: ORCL
        Current alias directory path: ORCL/CONTROLFILE
        Current alias directory path: ORCL/ARCHIVELOG/2009_07_13
        Current alias directory path: ORCL/BACKUPSET/2009_07_14
        Current alias directory path: ORCL/ARCHIVELOG/2009_07_14
        Current alias directory path: ORCL
        Current alias directory path: ORCL/DATAFILE
        Current alias directory path: ORCL/ARCHIVELOG
        Current alias directory path: ORCL/BACKUPSET
        Current alias directory path: ORCL/ONLINELOG

md_backup命令在每次执行时都会创建一个备份文件。用户可以控制创建的脚本存储目录以及需要备 份的磁盘组列表。缺省情况下,MDB文件存储在当前执行命令的目录中并且生成名叫 ambr_backup_intermediate_file。

MDB文件,缺省情况下,它有用来创建所有mount磁盘组的元数据。因为MDB文件是一个文本文件,如 果只需要还原特定的ASM对象而不是整个磁盘组,用户可以手动编辑存储的这些信息。然而,当编辑文 件时需要注意,在编辑之前总是要对MDB文件创建一个备份。在编辑出现的错误会造成还原操作的失 败。注意md_restore命令在处理之前对输入文件不执行任何语法或语义检查。

下面的列表重复查看MDB文件中的每个段。每一部分通过唯一标签/section ID来进行标识。还原模式 将使用这个标签来定位备份文件中的section。如果对于期待的标签没有找到精确的匹配,md_backup 命令会继续搜索下一个有效的标签。编辑错误可能会造成section被跳过。对于备份模式,md_backup 命令将连接到ASM实例来收集以下信息:
1.磁盘组信息(对于每个将要备份的磁盘):它是文件中的第一个部分并且包含了创建磁盘组的SQL语句
1.1磁盘组名
1.2冗余类型
1.3ASM与DB的兼容性
1.4AU大小

2.磁盘信息(对于要备份的磁盘组所包含的每个磁盘)
2.1磁盘组名
2.2磁盘标签(name),如果用户指定
2.3磁盘路径
2.4操作系统大小与磁盘的ASM大小
2.5故障磁盘组,如果用户指定

3.别名目录信息(对于每个用户创建目录)
3.1磁盘组名
3.2不使用磁盘组名的别名条目的完整路径

4.属性目录

5.模板目录信息。对于每个磁盘组模式有一个条目。
5.1基于系统模板的改变来编辑缺省/系统模板
5.2创建用户定义模式
对于每个模板,构建以下信息:
5.2.1磁盘组名
5.2.2模板名
5.2.3冗余
5.2.4条带
5.2.5系统

还原模式
AMBR还原模式最基本的任务就是将元数据还原到磁盘组中,这是通过执行ASMCMD的子命令md_restore 来完成的。它假设对于磁盘组的数据库文件有一份良好的备份存在。在成功还原磁盘组之后需要通过 RMAN来还原数据库备份。

还原模式可以重新创建磁盘组(基于MDB文件中的设置列表)或使用任何请求的修改来还原磁盘组到现有磁盘组中,比如改变磁盘组名。

md_restore命令重建所有用户定义模板与改变。

[grid@jyrac1 ~]$ asmcmd help md_restore
        md_restore

        This command restores a disk group metadata backup.

        md_restore backup_file [--silent][--full|--nodg|--newdg -o  'old_diskgroup:new_diskgroup [,...]'][-S sql_script_file] [-G 'diskgroup  [,diskgroup...]']

        The options for the md_restore command are described below.

        backup_file             - Reads the metadata information from
                                  backup_file.
        --silent                - Ignore errors. Normally, if md_restore
                                  encounters an error, it will stop.
                                  Specifying this flag ignores any errors.
        --full                  - Specifies to create a disk group and restore
                                  metadata.
        --nodg                  - Specifies to restore metadata only.
        --newdg -o old_diskgroup:new_diskgroup  - Specifies to create a disk
                                  group with a different name when restoring
                                  metadata. The -o option is required
                                  with --newdg.
        -S sql_script_file      - Write SQL commands to the specified SQL
                                  script file instead of executing the commands.
        -G diskgroup            - Select the disk groups to be restored.
                                  If no disk groups are defined, then all
                                  disk groups will be restored.

        The first example restores the disk group DATA from the backup script
        and creates a copy. The second example takes an existing disk group
        DATA and restores its metadata. The third example restores disk group
        DATA completely but the new disk group that is created is called DATA2.
        The fourth example restores from the backup file after applying the
        overrides defined in the override.sql script file

        ASMCMD [+] > md_restore --full -G data --silent /tmp/dgbackup20090714
        ASMCMD [+] > md_restore --nodg -G data --silent /tmp/dgbackup20090714
        ASMCMD [+] > md_restore --newdg -o 'data:data2' --silent /tmp/dgbackup20090714
        ASMCMD [+] > md_restore -S override.sql --silent /tmp/dgbackup20090714

备份与还原例子
下面将介绍md_backup与md_restore的使用方法:
1.创建一些用户定义ASM目录,别名与模板
2.执行md_backup命令来创建MDB文件
3.使用RMAN来备份数据库并存储在磁盘组中
4.模拟完整磁盘组故障,删除磁盘组
5.使用md_restore还原磁盘组
6.使用RMAN还原与恢复数据库

1.创建用户定义的ASM对象

SQL> alter diskgroup datadg add template temp_unprot attributes(fine unprotected);

Diskgroup altered.

SQL> alter diskgroup datadg add template important_data attributes(fine mirror);

Diskgroup altered.

SQL> alter diskgroup datadg add alias  '+DATADG/jyrac/users_01.dbf'  for'+DATADG/jyrac/datafile/users.259.928610631';

Diskgroup altered.

SQL> alter diskgroup datadg add directory '+DATADG/jyrac/oradata';

Diskgroup altered.

SQL> alter diskgroup datadg add alias '+DATADG/jyrac/oradata/sysaux_01.dbf' for  '+DATADG/jyrac/datafile/sysaux.257.928610631';

Diskgroup altered.

SQL> alter diskgroup datadg add directory '+DATADG/jyrac/temp_files';

Diskgroup altered.

SQL> alter diskgroup datadg add alias '+DATADG/jyrac/temp_files/temp_01.dbf' for  '+DATADG/jyrac/tempfile/temp.263.928610813';

Diskgroup altered.


SQL> select name,redundancy,stripe from v$asm_template where system='N';

NAME                           REDUND STRIPE
------------------------------ ------ ------
TEMP_UNPROT                    UNPROT FINE
IMPORTANT_DATA                 MIRROR FINE
NONCRITCAL_FILES               UNPROT COARSE

SQL> select name,file_number,alias_directory from v$asm_alias where system_created='N'  and alias_directory='Y';

NAME                                                                   FILE_NUMBER A
---------------------------------------------------------------------- ----------- -
asmparameterfile                                                        4294967295 Y
oradata                                                                 4294967295 Y
temp_files                                                              4294967295 Y
yoda                                                                    4294967295 Y
data                                                                    4294967295 Y

2.使用md_backup命令来对磁盘组进行备份

[grid@jyrac1 ~]$ asmcmd md_backup  /home/grid/datadg_backup_20161212 -G datadg
Disk group metadata to be backed up: DATADG
Current alias directory path: JYRAC/PARAMETERFILE
Current alias directory path: JYRAC/ONLINELOG
Current alias directory path: JYRAC
Current alias directory path: JYRAC/temp_files
Current alias directory path: JYRAC/DATAFILE
Current alias directory path: JYRAC/oradata
Current alias directory path: JYRAC/CONTROLFILE
Current alias directory path: JYRAC/TEMPFILE

datadg_backup_20161212文件包含以下内容(系统生成的模板,比如datafile与controlfile)

[grid@jyrac1 ~]$ cat datadg_backup_20161212
@diskgroup_set = (
                   {
                     'ATTRINFO' => {
                                     '_._DIRVERSION' => '11.2.0.0.0',
                                     'COMPATIBLE.ASM' => '11.2.0.0.0',
                                     'COMPATIBLE.RDBMS' => '10.1.0.0.0'
                                   },
                     'DISKSINFO' => {
                                      'DATADG_0001' => {
                                                         'DATADG_0001' => {
                                                                            'TOTAL_MB'  => '5120',
                                                                            'FAILGROUP'  => 'DATADG_0001',
                                                                            'NAME' =>  'DATADG_0001',
                                                                            'DGNAME' =>  'DATADG',
                                                                            'PATH' =>  '/dev/raw/raw11'
                                                                          }
                                                       },
                                      'DATADG_0002' => {
                                                         'DATADG_0002' => {
                                                                            'TOTAL_MB'  => '5120',
                                                                            'FAILGROUP'  => 'DATADG_0002',
                                                                            'NAME' =>  'DATADG_0002',
                                                                            'DGNAME' =>  'DATADG',
                                                                            'PATH' =>  '/dev/raw/raw3'
                                                                          }
                                                       },
                                      'DATADG_0003' => {
                                                         'DATADG_0003' => {
                                                                            'TOTAL_MB'  => '5120',
                                                                            'FAILGROUP'  => 'DATADG_0003',
                                                                            'NAME' =>  'DATADG_0003',
                                                                            'DGNAME' =>  'DATADG',
                                                                            'PATH' =>  '/dev/raw/raw4'
                                                                          }
                                                       },
                                      'DATADG_0000' => {
                                                         'DATADG_0000' => {
                                                                            'TOTAL_MB'  => '5120',
                                                                            'FAILGROUP'  => 'DATADG_0000',
                                                                            'NAME' =>  'DATADG_0000',
                                                                            'DGNAME' =>  'DATADG',
                                                                            'PATH' =>  '/dev/raw/raw10'
                                                                          }
                                                       }
                                    },
                     'DGINFO' => {
                                   'DGTORESTORE' => 0,
                                   'DGCOMPAT' => '11.2.0.0.0',
                                   'DGNAME' => 'DATADG',
                                   'DGDBCOMPAT' => '10.1.0.0.0',
                                   'DGTYPE' => 'NORMAL',
                                   'DGAUSZ' => '1048576'
                                 },
                     'ALIASINFO' => {
                                      '6' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/PARAMETERFILE',
                                               'REFERENCE_INDEX' => '50331966'
                                             },
                                      '1' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/DATAFILE',
                                               'REFERENCE_INDEX' => '50331754'
                                             },
                                      '4' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/ONLINELOG',
                                               'REFERENCE_INDEX' => '50331860'
                                             },
                                      '0' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 0,
                                               'ALIASNAME' => 'JYRAC',
                                               'REFERENCE_INDEX' => '50331701'
                                             },
                                      '3' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/temp_files',
                                               'REFERENCE_INDEX' => '50332072'
                                             },
                                      '7' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/oradata',
                                               'REFERENCE_INDEX' => '50332019'
                                             },
                                      '2' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/CONTROLFILE',
                                               'REFERENCE_INDEX' => '50331807'
                                             },
                                      '5' => {
                                               'DGNAME' => 'DATADG',
                                               'LEVEL' => 1,
                                               'ALIASNAME' => 'JYRAC/TEMPFILE',
                                               'REFERENCE_INDEX' => '50331913'
                                             }
                                    },
                     'TEMPLATEINFO' => {
                                         '11' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'AUTOBACKUP',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '7' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'DATAFILE',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '2' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'DUMPSET',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '17' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'FINE',
                                                   'TEMPNAME' => 'TEMP_UNPROT',
                                                   'REDUNDANCY' => 'UNPROT',
                                                   'SYSTEM' => 'N'
                                                 },
                                         '1' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'ASMPARAMETERFILE',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '18' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'FINE',
                                                   'TEMPNAME' => 'IMPORTANT_DATA',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'N'
                                                 },
                                         '0' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'PARAMETERFILE',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '16' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'OCRFILE',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '13' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'CHANGETRACKING',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '6' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'ONLINELOG',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '3' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'FINE',
                                                  'TEMPNAME' => 'CONTROLFILE',
                                                  'REDUNDANCY' => 'HIGH',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '9' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'BACKUPSET',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '12' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'XTRANSPORT',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '14' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'FLASHBACK',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '15' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'DATAGUARDCONFIG',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '8' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'TEMPFILE',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '4' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'FLASHFILE',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                },
                                         '10' => {
                                                   'DGNAME' => 'DATADG',
                                                   'STRIPE' => 'COARSE',
                                                   'TEMPNAME' => 'XTRANSPORT BACKUPSET',
                                                   'REDUNDANCY' => 'MIRROR',
                                                   'SYSTEM' => 'Y'
                                                 },
                                         '5' => {
                                                  'DGNAME' => 'DATADG',
                                                  'STRIPE' => 'COARSE',
                                                  'TEMPNAME' => 'ARCHIVELOG',
                                                  'REDUNDANCY' => 'MIRROR',
                                                  'SYSTEM' => 'Y'
                                                }
                                       }
                   }
                 );


3.使用RMAN对数据库进行备份:

[oracle@jyrac1 ~]$ rman target/

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 12 15:24:25 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: JYRAC (DBID=2655496871)

RMAN> backup database plus archivelog;


Starting backup at 12-DEC-16
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=14 instance=jyrac1 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=2 sequence=115 RECID=2 STAMP=930409949
input archived log thread=1 sequence=53 RECID=1 STAMP=930409946
input archived log thread=1 sequence=54 RECID=3 STAMP=930410023
input archived log thread=2 sequence=116 RECID=4 STAMP=930410024
input archived log thread=1 sequence=55 RECID=5 STAMP=930410686
input archived log thread=2 sequence=117 RECID=6 STAMP=930410688
channel ORA_DISK_1: starting piece 1 at 12-DEC-16
channel ORA_DISK_1: finished piece 1 at 12-DEC-16
piece handle=/rman_backup/backup_09rn9s66_1_1 tag=TAG20161212T152454 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-DEC-16

Starting backup at 12-DEC-16
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=+DATADG/jyrac/datafile/sysaux.257.928610631
input datafile file number=00001 name=+DATADG/jyrac/datafile/system.256.928610629
input datafile file number=00005 name=+DATADG/jyrac/datafile/example.264.928610823
input datafile file number=00006 name=+DATADG/jyrac/datafile/undotbs2.265.928611101
input datafile file number=00003 name=+DATADG/jyrac/datafile/undotbs1.258.928610631
input datafile file number=00004 name=+DATADG/jyrac/datafile/users.259.928610631
channel ORA_DISK_1: starting piece 1 at 12-DEC-16
channel ORA_DISK_1: finished piece 1 at 12-DEC-16
piece handle=/rman_backup/backup_0arn9s68_1_1 tag=TAG20161212T152456 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 12-DEC-16
channel ORA_DISK_1: finished piece 1 at 12-DEC-16
piece handle=/rman_backup/backup_0brn9s80_1_1 tag=TAG20161212T152456 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 12-DEC-16

Starting backup at 12-DEC-16
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=56 RECID=8 STAMP=930410761
input archived log thread=2 sequence=118 RECID=7 STAMP=930410760
channel ORA_DISK_1: starting piece 1 at 12-DEC-16
channel ORA_DISK_1: finished piece 1 at 12-DEC-16
piece handle=/rman_backup/backup_0crn9s8a_1_1 tag=TAG20161212T152602 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-DEC-16

4.模拟磁盘组丢失,删除磁盘组:
在所有节点执行以下命令:

SQL>  alter diskgroup datadg dismount;

Diskgroup altered.

在任意节点执行以下命令来删除磁盘组:

SQL> drop diskgroup datadg force including contents;

Diskgroup dropped.

5.使用md_restore命令来还原磁盘组:

[grid@jyrac1 ~]$ asmcmd md_restore --full -G DATADG  /home/grid/datadg_backup_20161212
Current Diskgroup metadata being restored: DATADG
Diskgroup DATADG created!
System template AUTOBACKUP modified!
System template DATAFILE modified!
User template TEMP_UNPROT created!
System template DUMPSET modified!
System template ASMPARAMETERFILE modified!
User template IMPORTANT_DATA created!
System template PARAMETERFILE modified!
System template OCRFILE modified!
System template CHANGETRACKING modified!
System template ONLINELOG modified!
System template CONTROLFILE modified!
System template BACKUPSET modified!
System template XTRANSPORT modified!
System template FLASHBACK modified!
System template DATAGUARDCONFIG modified!
System template TEMPFILE modified!
System template FLASHFILE modified!
System template XTRANSPORT BACKUPSET modified!
System template ARCHIVELOG modified!
Directory +DATADG/JYRAC re-created!
Directory +DATADG/JYRAC/DATAFILE re-created!
Directory +DATADG/JYRAC/CONTROLFILE re-created!
Directory +DATADG/JYRAC/temp_files re-created!
Directory +DATADG/JYRAC/ONLINELOG re-created!
Directory +DATADG/JYRAC/TEMPFILE re-created!
Directory +DATADG/JYRAC/PARAMETERFILE re-created!
Directory +DATADG/JYRAC/oradata re-created!

md_restore命令只会在执行该命令的节点mount所还原的磁盘组。因此在RAC环境中,对于其它节点需 要手动mount还原的磁盘组

SQL> alter diskgroup datadg mount;

Diskgroup altered.

6.还原恢复数据库:

[oracle@jyrac1 ~]$ rman target/

Recovery Manager: Release 11.2.0.4.0 - Production on Mon Dec 12 15:41:59 2016

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)


RMAN> set DBID 2655496871

executing command: SET DBID

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
ORA-01565: error in identifying file '+DATADG/jyrac/spfilejyrac.ora'
ORA-17503: ksfdopn:2 Failed to open file +DATADG/jyrac/spfilejyrac.ora
ORA-15056: additional error message
ORA-17503: ksfdopn:2 Failed to open file +DATADG/jyrac/spfilejyrac.ora
ORA-15173: entry 'spfilejyrac.ora' does not exist in directory 'jyrac'
ORA-06512: at line 4

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2260088 bytes
Variable Size                285213576 bytes
Database Buffers             775946240 bytes
Redo Buffers                   5517312 bytes


RMAN> restore spfile from '/rman_backup/backup_0brn9s80_1_1';

Starting restore at 12-DEC-16
using channel ORA_DISK_1

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /rman_backup/backup_0brn9s80_1_1
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 12-DEC-16


RMAN> restore controlfile to '+datadg' from '/rman_backup/backup_0brn9s80_1_1';

Starting restore at 12-DEC-16
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=194 instance=jyrac1 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:03
Finished restore at 12-DEC-16

SQL> alter system set control_files='+DATADG/jyrac/controlfile/current.257.930412709'  scope=spfile sid='*';

System altered.

SQL> shutdown immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 2505338880 bytes
Fixed Size                  2255832 bytes
Variable Size             687866920 bytes
Database Buffers         1795162112 bytes
Redo Buffers               20054016 bytes
Database mounted.



RMAN> recover database;

Starting recover at 12-DEC-16
using channel ORA_DISK_1

starting media recovery

archived log file name=+ARCHDG/jyrac/1_56_928610797.dbf thread=1 sequence=56
archived log file name=+ARCHDG/jyrac/2_118_928610797.dbf thread=2 sequence=118
media recovery complete, elapsed time: 00:00:16
Finished recover at 2012-12-12 22:25:25


SQL> alter database open resetlogs;

Database altered.

Using ASMLIB Management ASM Disk

使用ASMLIB管理磁盘
在存储管理员给服务器提供磁盘设备后,它们对于服务器来说是可用的并且可以在Linux系统中 的/proc/partitions虚拟文件中可以看到。系统管理然后使用Linux fdisk工具来对磁盘设备进行分 区。被分区后磁盘设备现在可以被配置为ASMLIB磁盘,系统管理员创建ASMLIB磁盘。创建命 令:oracleasm createdisk。createdisk命令使用两个输入参数,通过设备来生成用户定义的磁盘名:

[root@racnode1]#/etc/init.d/oracleasm createdisk VOL1 /dev/sdg1
Creating Oracle ASM disk "VOL1" [ OK ]

磁盘名被限制为30个字符。它们必须使用字母开头但可以由其它ASCII字符组成,包括:大写字母, 数字和下划线。每一个被创建成功的磁盘被标识为ASMLIB磁盘并且会被显示在oracleasm文件系统 中/dev/oracleasm/disks/。文件系统是一种特定的不受任何方式进行维护。

用户可查询磁盘设备来判断是否它们是有效的ASMLIB磁盘。为了查询,使用下面的oracleasm querydisk命令。querydisk命令可以应用于裸设备和ASMLIB磁盘

[root@racnode1]#/etc/init.d/oracleasm querydisk /dev/sdg1
Checking if device "/dev/sdg" is an Oracle ASM disk [ OK ]

[root@racnode1]#/etc/init.d/oracleasm querydisk VOL1
Checking for ASM disk "VOL1" [ OK ]

另外,所有被标记的磁盘与使用ASMLIB创建的磁盘可以使用以下oracleasm listdisks命令来显示:

[root@racnode1]#/etc/init.d/oracleasm listdisks
VOL1
VOL2
VOL3

如果一个磁盘设备不是一个ASMLIB磁盘,会显示以下信息:

[root@racnode1]#/etc/init.d/oracleasm querydisk /dev/sdh1
Checking if device "/dev/sdh1" is an Oracle ASM disk [FAILED]

对于ASM不再需要的磁盘可以撤消标记并且使用oracleasm deletedisk命令来删除:

[root@racnode1]#/etc/init.d/oracleasm deletedisk VOL1
Deleting Oracle ASM disk "VOL1" [ OK ]

当ASMLIB用于RAC环境时,对于RAC的共享磁盘架构允许使用oracleasm createdisk命令只在一个节点 上创建ASMLIB磁盘,其它节点只需要使用ASMLIB扫描来查找ASMLIB磁盘就可以了。例如,对于两节点 RAC环境,节点1可以标记ASMLIB磁盘,节点2然后执行扫描ASMLIB磁盘来查找这些ASMLIB磁盘。

[root@racnode1]#/etc/init.d/oracleasm createdisk VOL1 /dev/sdg1
Creating Oracle ASM disk "VOL1" [ OK ]

[root@racnode2]#/etc/init.d/oracleasm scandisks
Scanning system for ASM disks [ OK ]

在合适的ASMLIB磁盘创建后,ASM的init.ora参数asm_diskstring可以保留缺省的NULL或者设置 为’ORCL:*’。一旦设置后,ASM将可以发现以下磁盘:

SQL> select name, library, path from v$asm_disk;
NAME        LIBRARY                   PATH
----------- ------------------------- -------------------------
VOL1        ASM Library Generic Linux ORCL:VOL1
VOL2        ASM Library Generic Linux ORCL:VOL2
VOL3        ASM Library Generic Linux ORCL:VOL3

注意,如果ASMLIB没有使用,那么上面的查询LIBRARY列将返回”System”。

重命名Disk
renamedisk命令被用来改变现有成员的标签而不会丢失数据。注意修改磁盘时只有当ASM不访问该磁 盘才行。因此磁盘组必须dismount,并且在RAC环境中,所有ASM节点必须都dismount磁盘组。当有 ASM实例访问被重新标签的磁盘时执行renamedisk操作可能造成损坏。因为renamedisk命令是危险的 通过打印消息可以看到:

[root@racnode1]#/etc/init.d/oracleasm renamedisk /dev/sdb3 VOL1
Warning: Changing the label of a disk marked for ASM is a very
dangerous operation. If this is really what you mean to do, you
must ensure that all Oracle and ASM instances have ceased using
this disk. Otherwise, you may LOSE DATA. If you really wish to
change the label, rerun with the force-renamedisk command.

[root@racnode1]#/etc/init.d/oracleasm force-renamedisk /dev/sdb3 VOL1
Renaming disk "/dev/sdb3" to "VOL1" [ OK ]

force_renamedisk命令使用两个参数:裸设备名,其次是ASM磁盘名。

discover磁盘
命令/sbin/oracleasm-discover是一个简单的工具来判断Oracle的Linux ASMLIB在discover操作时所看到那个磁盘。这个命令更多一个调试工具来验证discover所列出的请求磁盘。这个命令也列出了每个磁盘的最大I/O大小。最大I/O大小,ASMLIB可以作为一个命令发送给设备。

[root@racnode1]#/usr/sbin/oracleasm-discover 'ORCL:*'
Using ASMLib from /opt/oracle/extapi/32/asm/orcl/1/libasm.so
[ASM Library - Generic Linux, version 2.0.0 (KABI_V1)]
Discovered disk: ORCL:VOL1 [819200 blocks (419430400 bytes), maxio 512]
Discovered disk: ORCL:VOL2 [1955808 blocks (1001373696 bytes), maxio 512]

最大I/O大小来自SCSI HBA设备与磁盘设备链中的其它设备。在上面的例子中,maxio等于512,512 byte或256K。如果maxio显示了最小值,比如128,那么它可能是中间组件比如多路径设备或HBA设备限制的原因。

升级ASMLIB
为了升级ASMLIB,系统管理员可以执行以下步骤。注意这是严格意义上的软件升级并且没有磁盘标签 被维护。这是一个节点本地升级,因此在RAC环境中,每个单独的节点应该被升级。
1.关闭ASM
2.执行/etc/init.d/oracleasm stop
3.执行rpm -Uvh oracleasm-*.rpm
4.执行/etc/init.d/oracleasm start
5.启动ASM

诊断ASMLIB
诊断ASMLIB从上到下的操作步骤为:
1.使用的Oracle ASMLIB的当前版本。验证软件版本。ASMLIB请求一个设备精确匹配给内核,因此使 用与uname -a命令输出匹配的oracleasm内核包。

[root@racnode1]# rpm -qa |grep oracleasm
oracleasm-support-2.0.3-1.i386.rpm
oracleasmlib-2.0.2-1.i386.rpm
oracleasm-2.6.9-42.0.3.ELsmp-2.0.3-1.i686.rpm


[root@racnode1]# uname -a
Linux racnode1.us.oracle.com 2.6.9-42.0.3.ELsmp #1Thu May 15
17:03:45 EST 2006 i686 i686 i386 GNU/Linux

2.验证ASMLIB的安装设置

3.确保oracleasm configure命令正确运行,使用以下信息进行确认配置:
a.以root用户执行lsmod命令来显示加载的oracleasm模块。使用oracleasm模块”Used by”列会被设 置为1.

[root@db2 ~]# lsmod
Module                  Size  Used by
oracleasm              53591  1
8021q                  20994  0
garp                    7297  1 8021q
stp                     2256  1 garp
llc                     5608  2 garp,stp
cpufreq_ondemand        9398  80
ip6t_REJECT             4486  2
nf_conntrack_ipv6      10595  3
nf_defrag_ipv6         11368  1 nf_conntrack_ipv6
xt_state                1370  3
nf_conntrack           84658  2 nf_conntrack_ipv6,xt_state
ip6table_filter         1671  1
ip6_tables             19409  1 ip6table_filter
ipv6                  339024  660 ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
dm_round_robin          2531  34
dm_multipath           18562  18 dm_round_robin
uinput                  8917  0
sg                     30968  0
serio_raw               5631  0
iTCO_wdt                6353  0
iTCO_vendor_support     3030  1 iTCO_wdt
coretemp                6997  0
acpi_cpufreq           13345  0
freq_table              6987  2 cpufreq_ondemand,acpi_cpufreq
mperf                   1555  1 acpi_cpufreq
intel_powerclamp       10841  0
kvm_intel             130025  0
kvm                   438077  1 kvm_intel
crc32c_intel           14496  0
ghash_clmulni_intel     4707  0
microcode             115607  0
pcspkr                  2150  0
igb                   186225  0
hwmon                   2087  2 coretemp,igb
i2c_i801               12911  0
i2c_core               31228  1 i2c_i801
lpc_ich                12496  0
mfd_core                3955  1 lpc_ich
ioatdma                61937  168
dca                     7283  2 igb,ioatdma
i7core_edac            20072  0
edac_core              54168  1 i7core_edac
shpchp                 27901  0
ext4                  532546  2
jbd2                  100769  1 ext4
mbcache                 7575  1 ext4
sd_mod                 41045  38
crc_t10dif              1547  1 sd_mod
qla2xxx               562439  68
scsi_transport_fc      54538  1 qla2xxx
scsi_tgt               12075  1 scsi_transport_fc
sr_mod                 15980  0
cdrom                  40900  1 sr_mod
usb_storage            53806  0
megaraid_sas          101114  3
aesni_intel            45744  0
ablk_helper             2997  1 aesni_intel
cryptd                 10460  3 ghash_clmulni_intel,aesni_intel,ablk_helper
lrw                     4222  1 aesni_intel
aes_x86_64              7967  1 aesni_intel
xts                     3466  1 aesni_intel
gf128mul                7999  2 lrw,xts
pata_acpi               3782  0
ata_generic             3758  0
ata_piix               26525  0
dm_mirror              14208  0
dm_region_hash         11094  1 dm_mirror
dm_log                  9681  2 dm_mirror,dm_region_hash
dm_mod                 85047  41 dm_multipath,dm_mirror,dm_log

b.执行命令cat /proc/filesystem,并且确保在文件系统列表中存在一条名叫oracleasmfs的记录:

[root@db2 ~]# cat /proc/filesystems
nodev   sysfs
nodev   rootfs
nodev   bdev
nodev   proc
nodev   cgroup
nodev   cpuset
nodev   tmpfs
nodev   devtmpfs
nodev   binfmt_misc
nodev   debugfs
nodev   securityfs
nodev   sockfs
nodev   pipefs
nodev   anon_inodefs
nodev   devpts
nodev   ramfs
nodev   hugetlbfs
        iso9660
nodev   pstore
nodev   mqueue
        ext4
nodev   asmdisk
nodev   oracleasmfs

c.执行命令 df -ha,它将显示所mount的oracleasmfs

/dev/mapper/vg_db2-LogVol00
                      1.1T  437G  592G  43% /
proc                     0     0     0    - /proc
sysfs                    0     0     0    - /sys
devpts                   0     0     0    - /dev/pts
tmpfs                 126G 1005M  125G   1% /dev/shm
/dev/sda1             190M   79M   98M  45% /boot
none                     0     0     0    - /proc/sys/fs/binfmt_misc
oracleasmfs              0     0     0    - /dev/oracleasm

确保oracleasm createdisk正确执行。为了让ASM使用,磁盘被通过createdisk命令来标记。当磁盘被标记后,会在磁盘头中写入签名–,磁盘将被标记ASM使用。可以使用以下命令来验证.执行oracleasm listdisks命令。这个命令将显示被标记为ASMLIB的磁盘。

[root@db2 ~]# oracleasm listdisks
ARCH0
ARCH1
ARCH2
ARCH3
CW_DATA1
OCR1
OCR2
OCR3
RLZY_ARCH1
RLZY_DATA1
RLZY_DATA2
RLZY_DATA3
SBK_DATA0
SBK_DATA1
SBK_DATA2
YB_DATA4
YB_DATA5

.对每个被标记为ASMLIB磁盘执行oracleasm querydisk命令来确保标记

[root@db2 ~]# oracleasm querydisk YB_DATA4
Disk "YB_DATA4" is a valid ASM disk

4.执行ls -l /dev/oracleasm/disks来确保磁盘的所属组与权限是grid:asmadmin

[root@db2 ~]# ls -l /dev/oracleasm/disks
total 0
brw-rw---- 1 grid asmadmin 252,  8 Dec  7 20:14 ARCH0
brw-rw---- 1 grid asmadmin 252,  9 Dec  7 20:17 ARCH1
brw-rw---- 1 grid asmadmin 252, 10 Dec  7 20:18 ARCH2
brw-rw---- 1 grid asmadmin 252, 11 Dec  7 20:18 ARCH3
brw-rw---- 1 grid asmadmin 252, 14 Dec  7 20:18 CW_DATA1
brw-rw---- 1 grid asmadmin 252,  1 Dec  7 20:18 OCR1
brw-rw---- 1 grid asmadmin 252,  2 Dec  7 20:18 OCR2
brw-rw---- 1 grid asmadmin 252,  6 Dec  7 20:18 OCR3
brw-rw---- 1 grid asmadmin 252,  7 Dec  7 20:18 RLZY_ARCH1
brw-rw---- 1 grid asmadmin 252,  3 Dec  7 20:18 RLZY_DATA1
brw-rw---- 1 grid asmadmin 252,  4 Dec  7 20:18 RLZY_DATA2
brw-rw---- 1 grid asmadmin 252,  5 Dec  7 20:18 RLZY_DATA3
brw-rw---- 1 grid asmadmin 252, 15 Dec  7 20:18 SBK_DATA0
brw-rw---- 1 grid asmadmin 252, 16 Dec  7 20:18 SBK_DATA1
brw-rw---- 1 grid asmadmin 252, 17 Dec  7 20:18 SBK_DATA2
brw-rw---- 1 grid asmadmin 252, 12 Dec  7 20:18 YB_DATA4
brw-rw---- 1 grid asmadmin 252, 13 Dec  7 20:18 YB_DATA5

5.验证ASMLIB发现字符串(可以在DBCA中指定或设置asm_diskstring参数)是否被设置ORCL:*或NUL。 如果ASM实例在运行,那么检查ASM的alert log查看是否正确设置。

6.对ASM alert log中关于发现所显示的任何信息使用Linux/Unix的grep命令。如果成功加载ASMLIB 将会显示以下信息:

Loaded ASM Library - Generic Linux, version 2.0.1 library for
ASMLIB interface

下面的查询显示被发现的ASMLIB磁盘:

SQL> SELECT LIBRARY, PATH FROM V$ASM_DISK;
LIBRARY                                     PATH
------------------------------------------- ----------------
ASM Library - Generic Linux, version 2.0.0.1 ORCL:VOL1
ASM Library - Generic Linux, version 2.0.0.1 ORCL:VOL2
ASM Library - Generic Linux, version 2.0.0.1 ORCL:VOL3

如果在Library列显示system,那么asm_diskstring没有设备–,ASMLIB不能用于访问磁盘。ASMLIB 需要通过磁盘符ORCL:*来访问磁盘。检查asm_diskstring是否设置为ORCL:*或NULL:

SQL> SELECT LIBRARY, PATH FROM V$ASM_DISK;
LIBRARY        PATH
-------------- -------------------------------------------------
System         /dev/oracleasm/disks/DATA1D1
System         /dev/oracleasm/disks/DATA1D2
System         /dev/oracleasm/disks/DATA1D3

7.查看ASM alert log中是否有以下错误信息:

ORA-15186: ASMLIB error function = [asm_open], error = [1],mesg = [Operation not  permitted]

这个消息通常意味着在/etc/init.d/oracleasm configure操作时ASMLIB配置权限不正确

迁移到ASMLIB
在许多情况下可能需要将一个”member”ASM裸磁盘转换为一个ASMLIB磁盘。例如,当安装ASMLIB后需 要执行。相反,如果需要卸载ASMLIB,可以将一个ASMLIB磁盘转换为一个标准的ASM磁盘。所有这种操 作不会损坏磁盘上的数据。然而,在转换之前必须将磁盘组dismount。

这种转换不会损坏数据因为磁盘上的结构和磁盘打开ASM所读取的信息。ASM读取磁盘头并且识别它属 于那个磁盘组。当一个磁盘被增加到一个磁盘组时,ASM将对磁盘写入一些信息。两个重要的条目是 磁盘标记与ASMLIB标签。所有ASM磁盘有一个标记ORCLSDISK印记在磁盘上面。如果标记已经存在,那 么磁盘可以当前被使用或者被ASM格式化了。这个标记可以由ASM或ASMLIB所创建。例如,当ASM在创 建磁盘组时使用一个磁盘作为一个裸设备时,ASM会自动增加这个标记。相反,当通过ASMLIB命 令/etc/init.d/oracleasm createdisk命令时磁盘会增加ASMLIB标记。不管使用那种工具创建标记, 一旦标记被创建,磁盘就会被打上标签。

磁盘头的第二部分与ASMLIB相关,是ASMLIB标签。这是指派给ASMLIB用来标识磁盘的24个字符的字符 串。当通过ASMLIB的/etc/init.d/oracleasm createdisk命令来配置磁盘时,相关的标签会被写入设备。注意ASM会保存磁盘的内容,但写入这部分信息是留给ASMLIB。

下面是一个对ASM磁盘(不是ASMLIB)的一个简单dump,这个磁盘被加入一个磁盘。在磁盘头中的ASM磁 盘名为DATA_0003:

[root@db2 ~]# dd if=/dev/mapper/yb_data4 bs=128 count=1 | od -a
1+0 records in
1+0 records out
0000000 soh stx soh soh nul nul nul nul etx nul nul nul   K eot   [   l
128 bytes (128 B) copied0000020   N   d   ? nul nul nul nul nul nul nul nul nul nul nul  nul nul
, 0.000253206 s, 506 kB/s
0000040   O   R   C   L   D   I   S   K nul nul nul nul nul nul nul nul
0000060 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000100 nul nul  sp  vt etx nul soh etx   D   A   T   A   _   0   0   0
0000120   3 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000140 nul nul nul nul nul nul nul nul   D   A   T   A nul nul nul nul
0000160 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000200
[root@db2 ~]#

下面例子使对使用/etc/init.d/oracleasm createdisk命令所创建的ASMLIB磁盘进行一个简单的dump 注意YB_DATA4被写入ORCLDISK标签中:

[root@db2 ~]# oracleasm querydisk -v -p  YB_DATA4
Disk "YB_DATA4" is a valid ASM disk
/dev/sdn: LABEL="YB_DATA4" TYPE="oracleasm"
/dev/sdae: LABEL="YB_DATA4" TYPE="oracleasm"
/dev/mapper/yb_data4: LABEL="YB_DATA4" TYPE="oracleasm"
[root@db2 ~]# dd if=/dev/mapper/yb_data4 bs=128 count=1 | od -a
1+0 records in
1+0 records out
128 bytes (128 B) copied, 0.000204442 s, 626 kB/s
0000000 soh stx soh soh nul nul nul nul etx nul nul nul   K eot   [   l
0000020   N   d   ? nul nul nul nul nul nul nul nul nul nul nul nul nul
0000040   O   R   C   L   D   I   S   K   Y   B   _   D   A   T   A   4
0000060 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000100 nul nul  sp  vt etx nul soh etx   D   A   T   A   _   0   0   0
0000120   3 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000140 nul nul nul nul nul nul nul nul   D   A   T   A nul nul nul nul
0000160 nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
0000200

在这个例子中,标记ORCLDISK与YB_DATA4被写入磁盘头。下面ASMLIB扫描磁盘时,它将查看标记 ORCLDISK与YB_DATA4,并使用YB_DATA创建一个ASMLIB磁盘到设备的映射。后续,ASM将通过ASMLIB驱 动来发现这个磁盘。如果磁盘最初没有通过ASMLIB管理,当ASM发现磁盘时,将通过ASM裸设备访问, 它将检测试没有ASMLIB标记存在。这就是为什么从ASMLIB访问迁移到裸设备来访问不存在问题的原因 。

使用ASMLIB与Multipath工具
多路径设备使用伪设备来生成虚拟子路径。在执行磁盘发现操作时,ASMLIB使用伪文 件/proc/partitions。这是一个Linux文件它记录了所有设备与之匹配的分区。

[root@db2 ~]# cat /proc/partitions
major minor  #blocks  name

  11        0    1048575 sr0
  11        1    1048575 sr1
   8        0 1171062784 sda
   8        1     204800 sda1
   8        2   16777216 sda2
   8        3 1154079744 sda3
   8       64  629145600 sde
   8       48   10485760 sdd
   8       32   10485760 sdc
   8       80  629145600 sdf
   8       96  629145600 sdg
   8      112   10485760 sdh
   8      128  629145600 sdi
   8      144  629145600 sdj
   8      160  629145600 sdk
   8      176  629145600 sdl
   8      192  629145600 sdm
   8      224  629145600 sdo
   8      208  629145600 sdn
  65        0  629145600 sdq
   8      240  209715200 sdp
  65       16  629145600 sdr
  65       32  629145600 sds
  65       48   10485760 sdt
  65       64   10485760 sdu
  65       80  629145600 sdv
  65       96  629145600 sdw
  65      112  629145600 sdx
  65      128   10485760 sdy
  65      144  629145600 sdz
  65      160  629145600 sdaa
  65      176  629145600 sdab
  65      192  629145600 sdac
  65      208  629145600 sdad
  65      224  629145600 sdae
  65      240  629145600 sdaf
  66        0  209715200 sdag
  66       16  629145600 sdah
  66       32  629145600 sdai
  66       48  629145600 sdaj
 252        0 1154076672 dm-0
 252        1   10485760 dm-1
 252        2   10485760 dm-2
 252        3  629145600 dm-3
 252        4  629145600 dm-4
 252        5  629145600 dm-5
 252        6   10485760 dm-6
 252        7  629145600 dm-7
 252        8  629145600 dm-8
 252        9  629145600 dm-9
 252       10  629145600 dm-10
 252       11  629145600 dm-11
 252       12  629145600 dm-12
 252       13  629145600 dm-13
 252       14  209715200 dm-14
 252       15  629145600 dm-15
 252       16  629145600 dm-16
 252       17  629145600 dm-17

为了让多路径正确工作,ASMLIB必须只能对伪设备操作。因此ASMLIB必须使用伪设备来进行修改。通 过修改/etc/sysconfig/oracleasm中的两个参数来进行配置:
.oracleasm_scanorder使用通用前缀指定ASMLIB扫描设备的顺序。
.oracleasm_scanexclude通过ASMLIB指定那个设备不被发现。

例如,使用IBM v7000与多路径配置ASMLIB进行如下设置:
ORACLEASM_SCANORDER=”dm”
ORACLEASM_SCANEXCLUDE=”sd”

在这个例子中,ASMLIB基于/dev/dm来扫描磁盘并且排除/dev/sd*的设备。下面 是/etc/sysconfig/oracleasm文件的一个配置例子:

[root@db2 ~]# cat /etc/sysconfig/oracleasm
#
# This is a configuration file for automatic loading of the Oracle
# Automatic Storage Management library kernel driver.  It is generated
# By running /etc/init.d/oracleasm configure.  Please use that method
# to modify this file
#

# ORACLEASM_ENABLED: 'true' means to load the driver on boot.
ORACLEASM_ENABLED=true

# ORACLEASM_UID: Default user owning the /dev/oracleasm mount point.
ORACLEASM_UID=grid

# ORACLEASM_GID: Default group owning the /dev/oracleasm mount point.
ORACLEASM_GID=asmadmin

# ORACLEASM_SCANBOOT: 'true' means scan for ASM disks on boot.
ORACLEASM_SCANBOOT=true

# ORACLEASM_SCANORDER: Matching patterns to order disk scanning
ORACLEASM_SCANORDER="dm"

# ORACLEASM_SCANEXCLUDE: Matching patterns to exclude disks from scan
ORACLEASM_SCANEXCLUDE="sd"

# ORACLEASM_USE_LOGICAL_BLOCK_SIZE: 'true' means use the logical block size
# reported by the underlying disk instead of the physical. The default
# is 'false'
ORACLEASM_USE_LOGICAL_BLOCK_SIZE=false

小结:
ASMLIB是Oracle 10g与11g中ASM功能的支持library。ASMLIB允许Oracle数据库更有效的使用ASM与访 问磁盘组。ASMLIB的目的,它是ASM的一个插件,提供了一种识别与访问块设备的替接口。另外, ASMLIB API能够让存储与操作系统厂商来提供存储相关的扩展功能。这些功能可能提供一些好处,比 如提高性能与增加完整性。但ASMLIB对于ASM不是必须使用的。

Calculate the Number of IOPS and Throughput of a Database with AWR

对于Oracle 11.2.0.4及以后的数据库版本可以通过AWR报告来计算数据库的IOPS与吞吐量。在AWR报告中描述关于IOPS与吞吐量相关信息有以下三个不同的部分:
.Instance Activity Stats
.IO Profile(从11gr2开始)
.Load Profile

Instance Activity Stats
.IOPS(每秒I/O读写操作次数)–它是指每秒物理读取I/O请求总次数与每秒物理写I/O请求
总次数之和。
.吞吐量–它是指物理读取总字节数与物理写总字节数之和。
1

上图中所显示的信息如下:
IOPS=每秒物理读取I/O请求总次数 +每秒物理写I/O请求总次数
=47.13+71.27
=118.4
吞吐量=物理读取总字节数+物理写总字节数
=7819646464+15314800128
=23134446592 bytes
=18.3 GB

IO Profile
.IOPS:Total Requests(这个值是从Instance Avtivity Stats部分计算出来的每秒物理读取
I/O总次数与每秒物理写I/O总次数之和)
吞吐量/每秒:Total(MB)(这个值是指每秒物理读取总字节数与每秒物理写总字节数之和)
2

IOPS/每秒=每秒物理读取I/O总次数+每秒物理写I/O总次数
=47.1+71.3
=118.4
吞吐量/每秒=每秒物理读取总字节数+每秒物理写总字节数
=1+2 MB
=3.1 MB

Load Profile
Load Profile中的信息是IO Profile的一个子集
3

physical read IO requests
它是指应用程序活动所执行的读取请求次数(主要指buffer cache与direct load operation),每次请求读取一个或多个数据块。它是”physical read total IO requests”统计信息的一个子集。

physical read total IO requests
它是指所有实例活动包括应用程序,备份与恢复,以及其它工具的读取请求次数,每次请求读取一个或多个数据块。它与”physical read total multi block requests”之间的差别就是,它代表单块读请求的总次数。

How To Change The Asm Rebalancing Power

ASM Rebalance
使用传统逻辑卷管理器,扩展或收缩条带化的文件系统通常是很困难的。使用ASM,这些磁盘改变现 在调用重新分布(rebalance)可以无逢操作来条带数据。另外,这些操作可以联机执行。存储配置的任何改变–增加,删除或重设置磁盘大小,都会触发rebalance操作。ASM不会动态的围绕 着”host areas”或”hot extents”进行移动。因为ASM跨所有磁盘与数据库buffer cache分布区,阻止 small chunks of data出现在磁盘的host areas,完全消除了host disks或extents。

Rebalance Operation
rebalance operation跨磁盘组中的所有磁盘总是对文件区与空间使用提供了一种均匀分布。对每个 文件执行rebalance操作可以确保每个文件跨所有磁盘均匀分布。最关键的是ASM保证了I/O负载平衡 。ASM后台进程,RBAL管理rebalance操作。RBAL进程检查每个文件区映射,基于新的存储配置区会均 匀分布。例如,有块八磁盘的一个磁盘组,一个数据文件有40个区(每个磁盘将会有五个区),当向磁 盘组增加两块大小一样的磁盘后,数据文件会跨10块磁盘执行rebalance与分布,每个磁盘只包含四 个区。只需要移动8个区就可以完成rebalance操作–,完全重新分布区是不必要,只需要移动最小数 量的区就可以达到均匀分布。

磁盘大小与文件大小是影响rebalance的权重因素。一个大的磁盘将消耗更多的区。ASM rebalance操作有以下工作流程:
1.对ASM实例,DBA向磁盘组增加磁盘或从磁盘组中删除磁盘。

2.调用RBAL进程来创建一个rebalance计划,然后开始调度重新分布操作。

3.RBAL计算评估时间与执行任务所需要的工作,然后给ASM rebalance(ARBx)进程发送处理请求。调 用的ARBx进程的数量直接由init.ora参数asm_power_limit或在add ,drop或rebalance命令所指定的 power level所决定。

4.持续操作目录(COD)会被更新来反映一个rebalance活动。COD在influx rebalance失败时很重要。 恢复实例时对于rebalance与重启将会看到一个显著的COD条目。

5.RBAL对ARBs分布计划。一般,RBAL对每个文件生成一个计划,然而,大文件可能被多个ARBs分解。

6.ARBx对这些区执行rebalance。每个区会被锁定,重定位与解锁。当一个区被锁定时可以被读取。 写也仍然可以执行,但可能需要对新位置重新执行。这个操作会在v$asm_operation中显示了REBAL。

测试过程如下:
1.查看asm_power_limit参数设置

SQL> show parameter asm_power

NAME                                 TYPE                   VALUE
------------------------------------ ----------------------  ------------------------------
asm_power_limit                      integer                1

2.向磁盘组datadg增加磁盘

SQL> alter diskgroup datadg add disk '/dev/raw/raw5'

Diskgroup altered.

3.查看alert_+ASM1.log

SQL> alter diskgroup datadg add disk '/dev/raw/raw5'
Thu Dec 01 15:39:18 CST 2016
NOTE: reconfiguration of group 1/0x489bd291 (DATADG), full=1
Thu Dec 01 15:39:18 CST 2016
NOTE: initializing header on grp 1 disk DATADG_0001
NOTE: cache opening disk 1 of grp 1: DATADG_0001 path:/dev/raw/raw5
NOTE: requesting all-instance disk validation for group=1
Thu Dec 01 15:39:18 CST 2016
NOTE: disk validation pending for group 1/0x489bd291 (DATADG)
SUCCESS: validated disks for 1/0x489bd291 (DATADG)
Thu Dec 01 15:39:21 CST 2016
NOTE: PST update: grp = 1
NOTE: requesting all-instance membership refresh for group=1
Thu Dec 01 15:39:21 CST 2016
NOTE: membership refresh pending for group 1/0x489bd291 (DATADG)
SUCCESS: refreshed membership for 1/0x489bd291 (DATADG)
Thu Dec 01 15:39:27 CST 2016
NOTE: starting rebalance of group 1/0x489bd291 (DATADG) at power 1
Starting background process ARB0
ARB0 started with pid=19, OS id=21560
Thu Dec 01 15:39:27 CST 2016
NOTE: assigning ARB0 to group 1/0x489bd291 (DATADG)
Thu Dec 01 15:39:31 CST 2016
NOTE: X->S down convert bast on F1B3 bastCount=2
NOTE: X->S down convert bast on F1B3 bastCount=3
NOTE: X->S down convert bast on F1B3 bastCount=4
NOTE: X->S down convert bast on F1B3 bastCount=5
NOTE: X->S down convert bast on F1B3 bastCount=6
NOTE: X->S down convert bast on F1B3 bastCount=7
Thu Dec 01 15:40:34 CST 2016
NOTE: stopping process ARB0
Thu Dec 01 15:40:37 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
Thu Dec 01 15:40:37 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
NOTE: PST update: grp = 1
NOTE: PST update: grp = 1
Thu Dec 01 15:48:29 CST 2016

当使用缺省参数值asm_power_limit=1,向磁盘组增加一块磁盘执行rebalance操作花了将近9分钟( 从2016-12-01 15:39:12开始到2016-12-01 15:48:29完成)

手动指定rebalance power操作如下:
1.向磁盘组datadg增加磁盘

SQL> alter diskgroup datadg add disk '/dev/raw/raw6';

Diskgroup altered.

2.查看alert_+ASM1.log

SQL> alter diskgroup datadg add disk '/dev/raw/raw6' rebalance power 4
Thu Dec 01 15:48:30 CST 2016
NOTE: reconfiguration of group 1/0x489bd291 (DATADG), full=1
Thu Dec 01 15:48:30 CST 2016
NOTE: initializing header on grp 1 disk DATADG_0002
NOTE: cache opening disk 2 of grp 1: DATADG_0002 path:/dev/raw/raw6
NOTE: requesting all-instance disk validation for group=1
Thu Dec 01 15:48:30 CST 2016
NOTE: disk validation pending for group 1/0x489bd291 (DATADG)
SUCCESS: validated disks for 1/0x489bd291 (DATADG)
Thu Dec 01 15:48:33 CST 2016
NOTE: PST update: grp = 1
NOTE: requesting all-instance membership refresh for group=1
Thu Dec 01 15:48:33 CST 2016
NOTE: membership refresh pending for group 1/0x489bd291 (DATADG)
SUCCESS: refreshed membership for 1/0x489bd291 (DATADG)
Thu Dec 01 15:48:39 CST 2016
NOTE: starting rebalance of group 1/0x489bd291 (DATADG) at power 4
Starting background process ARB0
Starting background process ARB1
ARB0 started with pid=19, OS id=25110
Thu Dec 01 15:48:39 CST 2016
Starting background process ARB2
ARB1 started with pid=21, OS id=25114
Thu Dec 01 15:48:39 CST 2016
Starting background process ARB3
ARB2 started with pid=22, OS id=25119
Thu Dec 01 15:48:40 CST 2016
NOTE: assigning ARB0 to group 1/0x489bd291 (DATADG)
ARB3 started with pid=23, OS id=25121
Thu Dec 01 15:48:40 CST 2016
NOTE: assigning ARB1 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB2 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB3 to group 1/0x489bd291 (DATADG)
Thu Dec 01 15:48:47 CST 2016
NOTE: X->S down convert bast on F1B3 bastCount=8
NOTE: X->S down convert bast on F1B3 bastCount=9
NOTE: X->S down convert bast on F1B3 bastCount=10
NOTE: X->S down convert bast on F1B3 bastCount=11
NOTE: X->S down convert bast on F1B3 bastCount=12
NOTE: X->S down convert bast on F1B3 bastCount=13
Thu Dec 01 15:49:21 CST 2016
NOTE: stopping process ARB1
NOTE: stopping process ARB2
NOTE: stopping process ARB0
NOTE: stopping process ARB3
Thu Dec 01 15:49:25 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
Thu Dec 01 15:49:25 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
NOTE: PST update: grp = 1
NOTE: PST update: grp = 1

手动指定rebalance power=4,向磁盘组增加一块磁盘执行rebalance操作花了将近1分钟(从2016- 12-01 15:48:30开始到2016-12-01 15:49:25完成)。

对于如何设置rebalance进程数可以参考文档《Oracle Sun Database Machine High Availability Best Practices (Doc ID 1069521.1)》

对于rebalance操作所调用的每个ARB进程将会创建一个ARB跟踪文件。这个ARB跟踪文件可以在DIAG目 录上的子目录中找到。跟踪文件的内容类似如下:

/u01/app/oracle/admin/+ASM/bdump/+asm1_arb0_25110.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/10.2.0/db
System name:	Linux
Node name:	jyrac3
Release:	2.6.18-164.el5PAE
Version:	#1 SMP Tue Aug 18 15:59:11 EDT 2009
Machine:	i686
Instance name: +ASM1
Redo thread mounted by this instance: 0 
Oracle process number: 19
Unix process pid: 25110, image: oracle@jyrac3 (ARB0)

*** SERVICE NAME:() 2016-12-01 15:48:40.086
*** SESSION ID:(34.29) 2016-12-01 15:48:40.086
ARB0 relocating file +DATADG.2.1 (1 entries)
ARB0 relocating file +DATADG.256.926895041 (34 entries)
*** 2016-12-01 15:48:58.473
ARB0 relocating file +DATADG.257.926895043 (1 entries)
ARB0 relocating file +DATADG.258.926895047 (16 entries)
ARB0 relocating file +DATADG.259.926895047 (1 entries)
ARB0 relocating file +DATADG.260.926895413 (6 entries)
ARB0 relocating file +DATADG.261.926895419 (18 entries)
*** 2016-12-01 15:49:08.569
ARB0 relocating file +DATADG.262.926895423 (19 entries)
ARB0 relocating file +DATADG.263.926895443 (8 entries)
ARB0 relocating file +DATADG.264.926895475 (33 entries)

在开始执行rebalance操作之后修改asm rebalance power
rebalance power的缺省值由asm_power_limit参数所指定为1。rebalance power的值越高, rebalance操作可能完成的越快。较低的rebalance power值可能造成rebalance操作时间很长,但是 消耗较少的CPU与I/O资源。

power的取值范围从0到11,当为0时停止rebalance,当为11时最快。从oracle 11.2.0.2开始,如果 磁盘组属性compatible.asm被设置为11.2.0.2或更高的版本,那么它的取值范围为0到1024。可以动 态调用这个参数,然而调整asm_power_limit只会影响之后的rebalance操作。不影响正在执行的 rebalance操作。为了在开始执行rebalance操作之后修改power,可以执行如下命令:
alter diskgroup rebalance [power n];

测试情况如下:

SQL> show parameter asm_power_limit

NAME                                 TYPE                   VALUE
------------------------------------ ----------------------  ------------------------------
asm_power_limit                      integer                1


SQL> alter diskgroup datadg add disk '/dev/raw/raw5','/dev/raw/raw6';

Diskgroup altered.

SQL> select * from v$asm_operation;

GROUP_NUMBER OPERATION  STATE         POWER     ACTUAL      SOFAR   EST_WORK   EST_RATE  EST_MINUTES
------------ ---------- -------- ---------- ---------- ---------- ---------- ----------  -----------
           1 REBAL      RUN               1          1          2        772         60           12

查看alert_+ASM1.log

Thu Dec 01 16:47:43 CST 2016
NOTE: reconfiguration of group 1/0x489bd291 (DATADG), full=1
Thu Dec 01 16:47:43 CST 2016
NOTE: initializing header on grp 1 disk DATADG_0001
NOTE: initializing header on grp 1 disk DATADG_0002
NOTE: cache opening disk 1 of grp 1: DATADG_0001 path:/dev/raw/raw5
NOTE: cache opening disk 2 of grp 1: DATADG_0002 path:/dev/raw/raw6
NOTE: requesting all-instance disk validation for group=1
Thu Dec 01 16:47:43 CST 2016
NOTE: disk validation pending for group 1/0x489bd291 (DATADG)
SUCCESS: validated disks for 1/0x489bd291 (DATADG)
Thu Dec 01 16:47:47 CST 2016
NOTE: PST update: grp = 1
NOTE: requesting all-instance membership refresh for group=1
Thu Dec 01 16:47:48 CST 2016
NOTE: membership refresh pending for group 1/0x489bd291 (DATADG)
SUCCESS: refreshed membership for 1/0x489bd291 (DATADG)
Thu Dec 01 16:47:54 CST 2016
NOTE: starting rebalance of group 1/0x489bd291 (DATADG) at power 1
Starting background process ARB0
ARB0 started with pid=18, OS id=16007
Thu Dec 01 16:47:54 CST 2016
NOTE: assigning ARB0 to group 1/0x489bd291 (DATADG)
Thu Dec 01 16:48:00 CST 2016
NOTE: X->S down convert bast on F1B3 bastCount=27
NOTE: X->S down convert bast on F1B3 bastCount=28
NOTE: X->S down convert bast on F1B3 bastCount=29
NOTE: X->S down convert bast on F1B3 bastCount=30
NOTE: X->S down convert bast on F1B3 bastCount=31
NOTE: X->S down convert bast on F1B3 bastCount=32
NOTE: X->S down convert bast on F1B3 bastCount=33
NOTE: X->S down convert bast on F1B3 bastCount=34
NOTE: X->S down convert bast on F1B3 bastCount=35
NOTE: X->S down convert bast on F1B3 bastCount=36
Thu Dec 01 16:48:09 CST 2016

从信息Starting background process ARB0,可知只启动了一个ARB进程,因为asm_power_limit参数为1


SQL> alter diskgroup datadg rebalance power 8;

Diskgroup altered.

查看alert_+ASM1.log

Thu Dec 01 16:48:09 CST 2016
ERROR: ORA-1013 thrown in ARB0 for group number 1
Thu Dec 01 16:48:09 CST 2016
Errors in file /u01/app/oracle/admin/+ASM/bdump/+asm1_arb0_16007.trc:
ORA-01013: user requested cancel of current operation
Thu Dec 01 16:48:09 CST 2016
NOTE: stopping process ARB0
Thu Dec 01 16:48:12 CST 2016
NOTE: rebalance interrupted for group 1/0x489bd291 (DATADG)
Thu Dec 01 16:48:12 CST 2016
NOTE: PST update: grp = 1
NOTE: requesting all-instance membership refresh for group=1
Thu Dec 01 16:48:12 CST 2016
NOTE: membership refresh pending for group 1/0x489bd291 (DATADG)
SUCCESS: refreshed membership for 1/0x489bd291 (DATADG)
Thu Dec 01 16:48:18 CST 2016
NOTE: starting rebalance of group 1/0x489bd291 (DATADG) at power 8
Starting background process ARB0
Starting background process ARB1
ARB0 started with pid=18, OS id=16133
Thu Dec 01 16:48:19 CST 2016
Starting background process ARB2
ARB1 started with pid=19, OS id=16135
Thu Dec 01 16:48:19 CST 2016
Starting background process ARB3
ARB2 started with pid=21, OS id=16142
Thu Dec 01 16:48:19 CST 2016
Starting background process ARB4
ARB3 started with pid=22, OS id=16144
Thu Dec 01 16:48:19 CST 2016
Starting background process ARB5
ARB4 started with pid=23, OS id=16146
Thu Dec 01 16:48:19 CST 2016
Starting background process ARB6
ARB5 started with pid=24, OS id=16148
Thu Dec 01 16:48:20 CST 2016
Starting background process ARB7
ARB6 started with pid=25, OS id=16150
Thu Dec 01 16:48:20 CST 2016
NOTE: assigning ARB0 to group 1/0x489bd291 (DATADG)
ARB7 started with pid=26, OS id=16157
Thu Dec 01 16:48:20 CST 2016
NOTE: assigning ARB1 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB2 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB3 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB4 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB5 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB6 to group 1/0x489bd291 (DATADG)
NOTE: assigning ARB7 to group 1/0x489bd291 (DATADG)
Thu Dec 01 16:48:48 CST 2016
NOTE: stopping process ARB5
NOTE: stopping process ARB2
NOTE: stopping process ARB7
NOTE: stopping process ARB1
NOTE: stopping process ARB6
Thu Dec 01 16:49:01 CST 2016
NOTE: stopping process ARB0
Thu Dec 01 16:49:11 CST 2016
NOTE: stopping process ARB4
NOTE: stopping process ARB3
Thu Dec 01 16:49:14 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
Thu Dec 01 16:49:14 CST 2016
SUCCESS: rebalance completed for group 1/0x489bd291 (DATADG)
NOTE: PST update: grp = 1
NOTE: PST update: grp = 1

从信息NOTE: stopping process ARB0,可知在执行alter diskgroup datadg rebalance power 8命 令后,终止了之前所启动的rebalance进程,后面启动了8个ARB进程来完成rebalance操作。