首先来看看oracle data block整体结构:

 

 
 
 
下面我们通过BBED工具来研究数据块的结构,map看到的是一个data block整体结构
 
BBED> map
 File: /data/oracle/oradata/ora10g/system01.dbf (0)
 Block: 30                                     Dba:0x00000000
------------------------------------------------------------
 KTB Data Block (Table/Cluster)
 
  struct kcbh, 20 bytes                      @0       ----------对应cache layer大小是20个字节
 
  struct ktbbh, 72 bytes                     @20      ----------对应transaction layer一共是72字节
 
 struct kdbh, 14 bytes                       @92       ------对应data layer
 
 struct kdbt[6], 24 bytes                    @106      ------对应data layer
 
 sb2 kdbr[133]                               @130      ------对应data layer
 
 ub1 freespace[245]                          @396      ------对应data layer
 
 ub1 rowdata[7547]                           @641      ------对应data layer
 
 ub4 tailchk                                 @8188    ------对应footer 一共4字节
 
 
数据块的结构图:
 
 

 
 
关于struct kcbh(kernel cache block header),kcbh对应的是cache layer。
BBED> p kcbh
struct kcbh, 20 bytes                        @0      
   ub1 type_kcbh                            @0        0x06
   ub1 frmt_kcbh                            @1        0xa2
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x0040001e
   ub4 bas_kcbh                             @8        0x0002f9b0
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7f
   ub2 spare3_kcbh                          @18       0x0000
 
 
 
每个数据块的前20个字节是kcbh结构的部分:
 
type_kcbh 占用1个字节   表示block类型
frmt_kcbh 占用1个字节   表示block format 9i,8i这个值都是0x02,10g是0xa2
rdba_kcbh 占用4个字节   表示relative database address
bas_kcbh占用4个字节 表示SCN base
wrp_kcbh占用2个字节 表示SCN warp
seq_kcbh占用1个字节     表示同一个transaction里同一个block发生多次修改的序列号
chkval_kcbh占用2个字节   表示optional check value for block
 
 
对于一个正常的block    scnbase的低两位+block type+scn seq=tailchk,如下面的示例f9b0+06+01=0xf9b00601,若不相等,说明block为一个坏块。
BBED> map
 File: /data/oracle/oradata/ora10g/system01.dbf (0)
 Block: 30                                     Dba:0x00000000
------------------------------------------------------------
 KTB Data Block (Table/Cluster)
 
 struct kcbh, 20 bytes                       @0      
 
 struct ktbbh, 72 bytes                      @20      
 
 struct kdbh, 14 bytes                       @92     
 
 struct kdbt[6], 24 bytes                    @106    
 
 sb2 kdbr[133]                               @130    
 
 ub1 freespace[245]                          @396    
 
 ub1 rowdata[7547]                           @641    
 
 ub4 tailchk                                 @8188   
 
 
BBED>
BBED>
BBED> p tailchk
ub4 tailchk                                  @8188     0xf9b00601
 
BBED> p kcbh     
struct kcbh, 20 bytes                        @0      
   ub1 type_kcbh                            @0        0x06
   ub1 frmt_kcbh                            @1        0xa2
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x0040001e
   ub4 bas_kcbh                             @8        0x0002f9b0
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x06 (KCBHFDLC, KCBHFCKV)
   ub2 chkval_kcbh                          @16       0x1d7f
   ub2 spare3_kcbh                          @18       0x0000
 
 
 参考文档oracle DSI401