Oracle数据块主要有两种:文件头块和数据块。
下面先介绍数据块:
数据块简单分为下面几层:
BBED> set dba 1,58914DBA0x0040e622 (4253218 1,58914)
BBED>mapFile: /u01/app/oracle/oradata/qxptfh01/system01.dbf (1)
Block:58914 Dba:0x0040e622
------------------------------------------------------------
KTB Data Block (Table/Cluster)
struct kcbh,20 bytes @0-- - Cache Layer -
struct ktbbh,72 bytes @20--- Transaction Layer -
struct kdbh,14 bytes @92-- Data Header -
struct kdbt[1], 4 bytes @106-- Table Directory -
sb2 kdbr[3] @110- Row Directory -
ub1 freespace[8041] @116- Free Space -
ub1 rowdata[31] @8157- Row Data -
ub4 tailchk@8188 -- Tailchk -
从Data header到Row Data部分合称Data Layer。
Cache Layer:Block的第一部分,长度为20字节,内部数据结构名为kcbh,包括
下列几部分
BBED>p kcbh
struct kcbh,20 bytes @0ub1 type_kcbh@0 0x06 --块类型(table/index,rollback segment,temporary segment等)ub1 frmt_kcbh@1 0xa2 --块格式(v6,v7,v8)ub1 spare1_kcbh@2 0x00 --保留ub1 spare2_kcbh@3 0x00 --保留ub4 rdba_kcbh@4 0x0040e622 --块地址DBAub4 bas_kcbh@8 0x01a9b470 --scn baseub2 wrp_kcbh@12 0x0000 --scn wrapub1 seq_kcbh@14 0x07 --块的序列号,设置为0xff,则认为是坏块。ub1 flg_kcbh@15 0x06(KCBHFDLC, KCBHFCKV) --块的标志,即块的属性。
ub2 chkval_kcbh@16 0x153c --校验值,db_block_checksum=true,才有值。ub2 spare3_kcbh@18 0x0000 --保留
flg_kcbh:
define KCBHFNEW 0×01 /* new block - zeroed data area */
#define KCBHFDLC 0×02 /* Delayed Logging Change advance SCN/seq */
#define KCBHFCKV 0×04 /* ChecK Value saved-block xor’s to zero */
#define KCBHFTMP 0×08 /* Temporary block */
这是一个可以组合的值 也就是说有为 6 的时候是 2,4 两种情况的组合
type_kcbh:
Transaction Layer:内部结构名kcbbh。分成两部分:
第一部分为固定长度,长度为24字节,包含事务相关的一些基本信息。
第二部分为可变长度,包含itl,长度根据itl条目的个数变化,每个itl长度为24字节,内部结构名ktbbhitl。
BBED>p ktbbh
struct ktbbh,72 bytes @20ub1 ktbbhtyp@20 0x01(KDDBTDATA) --块类型。1为表,2为索引union ktbbhsid, 4 bytes @24--段或者对象的ID,也就是下边的0x00016f66转换为10进制就是
ub4 ktbbhsg1@24 0x00016f66 --段号ub4 ktbbhod1@24 0x00016f66 --对象号struct ktbbhcsc,8 bytes @28--最后一次块清除的SCN
ub4 kscnbas@28 0x01a9b461 --scn baseub2 kscnwrp@32 0x0000 --scn wrapb2 ktbbhict@36 2 --事务槽个数(ITL NUMBER)ub1 ktbbhflg@38 0x03(KTBFONFL) --0 = ON THE FREELIST
ub1 ktbbhfsl@39 0x00 --ITL TX FREELIST SLOTub4 ktbbhfnx@40 0x00000000 --下一个空闲块的地址 dbastruct ktbbhitl[0], 24 bytes @44--事务槽1
struct ktbitxid,8 bytes @44 --xidub2 kxidusn@44 0x0007 --usnub2 kxidslt@46 0x002d --slotub4 kxidsqn@48 0x0000150a --seqstruct ktbituba,8 bytes @52 --ubaub4 kubadba@52 0x008008b0 --dbaub2 kubaseq@56 0x145d --sequb1 kubarec@58 0x36 --ubarecub2 ktbitflg@60 0x2003(KTBFUPB)union _ktbitun, 2 bytes @62b2 _ktbitfsc@62 0ub2 _ktbitwrp@62 0x0000ub4 ktbitbas@64 0x01a9b470struct ktbbhitl[1], 24 bytes @68 --事务槽2struct ktbitxid,8 bytes @68ub2 kxidusn@68 0x0000ub2 kxidslt@70 0x0000ub4 kxidsqn@72 0x00000000struct ktbituba,8 bytes @76ub4 kubadba@76 0x00000000ub2 kubaseq@80 0x0000ub1 kubarec@82 0x00ub2 ktbitflg@84 0x0000(NONE)union _ktbitun, 2 bytes @86b2 _ktbitfsc@86 0ub2 _ktbitwrp@86 0x0000ub4 ktbitbas@88 0x00000000
下面通过ub4 ktbbhod1@24 0x00016f66 查询对应的是哪个对象:
SQL> select to_number('00016f66','xxxxxxxx') fromdual;
TO_NUMBER('00016F66','XXXXXXXX')--------------------------------
94054SQL> col OBJECT_NAMEFORMAT A15;
SQL>COL OBJECT_TYPE FORMAT A15
SQL> select object_name,object_type from dba_objects where object_id='94054';OBJECT_NAMEOBJECT_TYPE--------------- ---------------
T1 TABLE
Data Layer:包括Data Header,Table Directory,Row Directory,Free Space和Row Data。其中
Data Header:长度14字节,内部数据结构名kdbh
BBED>p kdbh
struct kdbh,14 bytes @92ub1 kdbhflag@92 0x00(NONE) --标志位 (N:pctfree hit. F:do not put on freelist. K:flushable cluster keys)
b1 kdbhntab@93 1 --表的个数b2 kdbhnrow@94 3 --这个块的行数sb2 kdbhfrre@96 -1 --是否在空闲列表。-1:不在空闲列表sb2 kdbhfsbo@98 24 --空闲空间的开始offsetsb2 kdbhfseo@100 8065 --空闲空间的结束offsetb2 kdbhavsp@102 8041 --块的平均空间b2 kdbhtosp@104 8041 --总共可以用的空间
Table Directory: 一般table只有一个条目,cluster则有一个或多个条目。每个条目长4字节,内部数据结构名kdbt。
BBED>p kdbt
struct kdbt[0], 4 bytes @106b2 kdbtoffs@106 0b2 kdbtnrow@108 3
Row Directory:数目由块中数据的行数决定,每个条目长2字节,内部数据结构名kdbr
BBED>p kdbr
sb2 kdbr[0] @110 8085sb2 kdbr[1] @112 8075sb2 kdbr[2] @114 8065
Free Space:表示数据块中可用空间,内部数据结构名freespace
Row Data:表示实际的数据,内部数据结构名rowdata
BBED>p freespace
ub1 freespace[0] @116 0x00ub1 freespace[1] @117 0x00ub1 freespace[2] @118 0x00ub1 freespace[3] @119 0x00.........................................................
BBED>p rowdata
ub1 rowdata[0] @8157 0x2cub1 rowdata[1] @8158 0x01ub1 rowdata[2] @8159 0x02ub1 rowdata[3] @8160 0x02ub1 rowdata[4] @8161 0xc1ub1 rowdata[5] @8162 0x04ub1 rowdata[6] @8163 0x03ub1 rowdata[7] @8164 0x78ub1 rowdata[8] @8165 0x6e
...........................................................................................
Tailchk:保存在块结尾用于校验的数据,长度4个字节,内部结构名tailchk。
tailchk=bas_kcbh最后两2字节(b470)+type_kcbh(06)+seq_kcbh(07).
BBED>p tailchk
ub4 tailchk@8188 0xb4700607 --尾部校验码。
下面是文件头块信息:
BBED> set dba 1,1DBA0x00400001 (4194305 1,1)
BBED>mapFile: /u01/app/oracle/oradata/qxptfh01/system01.dbf (1)
Block:1 Dba:0x00400001
------------------------------------------------------------
Data FileHeader
struct kcvfh,676 bytes @0ub4 tailchk@8188BBED>p kcvfh
struct kcvfh,676 bytes @0struct kcvfhbfh,20 bytes @0ub1 type_kcbh@0 0x0b -----数据的块类型 11可以看出是否是数据文件头ub1 frmt_kcbh@1 0xa2 -----数据块的格式。1=oracle7 ,2=oracle8+ub1 spare1_kcbh@2 0x00ub1 spare2_kcbh@3 0x00ub4 rdba_kcbh@4 0x00400001ub4 bas_kcbh@8 0x00000000 ---SCN BASEub2 wrp_kcbh@12 0x0000 ---SCN WRAPub1 seq_kcbh@14 0x01 ---SCN序列号ub1 flg_kcbh@15 0x04(KCBHFCKV) ----块属性
ub2 chkval_kcbh@16 0x5064 ---检验值ub2 spare3_kcbh@18 0x0000struct kcvfhhdr,76 bytes @20---此结构存储这个数据文件的属性
ub4 kccfhswv@20 0x00000000ub4 kccfhcvn@24 0x0a200500 ---文件创建的版本号ub4 kccfhdbi@28 0x783cfa8c ---数据库的DBID
text kccfhdbn[0] @32Q ---所属实例的名字text kccfhdbn[1] @33Xtext kccfhdbn[2] @34Ptext kccfhdbn[3] @35Ttext kccfhdbn[4] @36Ftext kccfhdbn[5] @37Htext kccfhdbn[6] @38 0
text kccfhdbn[7] @39 1ub4 kccfhcsq@40 0x00003db5 ---控制序列,控制文件事务会增加此值ub4 kccfhfsz@44 0x0000f000 ---文件当前所包含数据块的个数s_blkz kccfhbsz@48 0x00 ---文件存放的块大小,关闭数据库有值ub2 kccfhfno@52 0x0001 ---文件号ub2 kccfhtyp@54 0x0003 ---文件类型,03代表数据文件,06表示undo文件ub4 kccfhacid@56 0x00000000 ---活动IDub4 kccfhcks@60 0x00000000 ---创建检查点的SCN
text kccfhtag[0] @64
text kccfhtag[1] @65
text kccfhtag[2] @66
text kccfhtag[3] @67
text kccfhtag[4] @68
text kccfhtag[5] @69
text kccfhtag[6] @70
text kccfhtag[7] @71
text kccfhtag[8] @72
text kccfhtag[9] @73
text kccfhtag[10] @74
text kccfhtag[11] @75
text kccfhtag[12] @76
text kccfhtag[13] @77
text kccfhtag[14] @78
text kccfhtag[15] @79
text kccfhtag[16] @80
text kccfhtag[17] @81
text kccfhtag[18] @82
text kccfhtag[19] @83
text kccfhtag[20] @84
text kccfhtag[21] @85
text kccfhtag[22] @86
text kccfhtag[23] @87
text kccfhtag[24] @88
text kccfhtag[25] @89
text kccfhtag[26] @90
text kccfhtag[27] @91
text kccfhtag[28] @92
text kccfhtag[29] @93
text kccfhtag[30] @94
text kccfhtag[31] @95ub4 kcvfhrdb@96 0x00400179 ---ROOT DBAstruct kcvfhcrs,8 bytes @100---文件创建的SCN
ub4 kscnbas@100 0x00000007 ---SCN BASEub2 kscnwrp@104 0x0000 ---SCN WRAPub4 kcvfhcrt@108 0x2ab9923a ---文件创建的时间戳ub4 kcvfhrlc@112 0x30f3d1cf ---resetlogs的次数struct kcvfhrls,8 bytes @116 ---resetlogs的SCNub4 kscnbas@116 0x0005eca9 ---SCN BASEub2 kscnwrp@120 0x0000 ---SCN WRAPub4 kcvfhbti@124 0x00000000struct kcvfhbsc,8 bytes @128 ---备份的SCNub4 kscnbas@128 0x00000000 ---SCN BASEub2 kscnwrp@132 0x0000 ---SCN WRAPub2 kcvfhbth@136 0x0000ub2 kcvfhsta@138 0x2004(KCVFHOFZ) ---数据文件状态:04为正常,00为关闭,01为begin backup
struct kcvfhckp,36 bytes @484 ---检查点checkpointstruct kcvcpscn,8 bytes @484 ---数据文件改变的检查点SCNub4 kscnbas@484 0x01a947ff --SCN BASEub2 kscnwrp@488 0x0000 --SCN WRAPub4 kcvcptim@492 0x338a07e7 --最后改变的时间ub2 kcvcpthr@496 0x0001 --resetlogs的线程号
union u, 12 bytes @500struct kcvcprba,12 bytes @500ub4 kcrbaseq@500 0x000005a0 --序列号ub4 kcrbabno@504 0x00000002 --块号ub2 kcrbabof@508 0x0010 --偏移量offsetub1 kcvcpetb[0] @512 0x02 --最大线程数ub1 kcvcpetb[1] @513 0x00ub1 kcvcpetb[2] @514 0x00ub1 kcvcpetb[3] @515 0x00ub1 kcvcpetb[4] @516 0x00ub1 kcvcpetb[5] @517 0x00ub1 kcvcpetb[6] @518 0x00ub1 kcvcpetb[7] @519 0x00ub4 kcvfhcpc@140 0x00000619 --数据文件发生checkpoint的次数ub4 kcvfhrts@144 0x3348a98a --resetlogs的次数ub4 kcvfhccc@148 0x00000618 --控制文件记录的检查点次数struct kcvfhbcp,36 bytes @152struct kcvcpscn,8 bytes @152ub4 kscnbas@152 0x00000000ub2 kscnwrp@156 0x0000ub4 kcvcptim@160 0x00000000ub2 kcvcpthr@164 0x0000
union u, 12 bytes @168struct kcvcprba,12 bytes @168ub4 kcrbaseq@168 0x00000000ub4 kcrbabno@172 0x00000000ub2 kcrbabof@176 0x0000ub1 kcvcpetb[0] @180 0x00ub1 kcvcpetb[1] @181 0x00ub1 kcvcpetb[2] @182 0x00ub1 kcvcpetb[3] @183 0x00ub1 kcvcpetb[4] @184 0x00ub1 kcvcpetb[5] @185 0x00ub1 kcvcpetb[6] @186 0x00ub1 kcvcpetb[7] @187 0x00ub4 kcvfhbhz@312 0x00000000struct kcvfhxcd,16 bytes @316ub4 space_kcvmxcd[0] @316 0x00000000ub4 space_kcvmxcd[1] @320 0x00000000ub4 space_kcvmxcd[2] @324 0x00000000ub4 space_kcvmxcd[3] @328 0x00000000word kcvfhtsn@332 0 --表空间号ub2 kcvfhtln@336 0x0006
text kcvfhtnm[0] @338S --表空间的名字,最长为30字符text kcvfhtnm[1] @339Ytext kcvfhtnm[2] @340Stext kcvfhtnm[3] @341Ttext kcvfhtnm[4] @342Etext kcvfhtnm[5] @343Mtext kcvfhtnm[6] @344
text kcvfhtnm[7] @345
text kcvfhtnm[8] @346
text kcvfhtnm[9] @347
text kcvfhtnm[10] @348
text kcvfhtnm[11] @349
text kcvfhtnm[12] @350
text kcvfhtnm[13] @351
text kcvfhtnm[14] @352
text kcvfhtnm[15] @353
text kcvfhtnm[16] @354
text kcvfhtnm[17] @355
text kcvfhtnm[18] @356
text kcvfhtnm[19] @357
text kcvfhtnm[20] @358
text kcvfhtnm[21] @359
text kcvfhtnm[22] @360
text kcvfhtnm[23] @361
text kcvfhtnm[24] @362
text kcvfhtnm[25] @363
text kcvfhtnm[26] @364
text kcvfhtnm[27] @365
text kcvfhtnm[28] @366
text kcvfhtnm[29] @367ub4 kcvfhrfn@368 0x00000001 --相对文件号struct kcvfhrfs,8 bytes @372 --文件SCNub4 kscnbas@372 0x00000000 --SCN BASEub2 kscnwrp@376 0x0000 --SCN WRAPub4 kcvfhrft@380 0x00000000struct kcvfhafs,8 bytes @384 --绝对文件号ub4 kscnbas@384 0x00000000 --SCN BASEub2 kscnwrp@388 0x0000 --SCN WRAPub4 kcvfhbbc@392 0x00000000ub4 kcvfhncb@396 0x00000000ub4 kcvfhmcb@400 0x00000000ub4 kcvfhlcb@404 0x00000000ub4 kcvfhbcs@408 0x00000000ub2 kcvfhofb@412 0x000aub2 kcvfhnfb@414 0x000aub4 kcvfhprc@416 0x2ab99238 --上个resetlogs的次数struct kcvfhprs,8 bytes @420 --上个resetlogs的SCNub4 kscnbas@420 0x00000001ub2 kscnwrp@424 0x0000struct kcvfhprfs,8 bytes @428ub4 kscnbas@428 0x00000000ub2 kscnwrp@432 0x0000ub4 kcvfhtrt@444 0x00000000BBED>
type_kcbh:数据的块类型