之前在Data Block Structure (Try to Understand)中通过dump文件来尝试去分析一个block的结构,结果费了半天劲,也没有得到一个很清晰的概念。发现BBED的map命令很好很强大,可以用来得到一个block的结构组织情况,
通过设置dba来得到一个block的结构,如下所示...
BBED
>
map
/
v dba
6
,
12
File : / u01 / app / oracle / oradata / orcl / small_tbs01.dbf ( 6 )
Block: 12 Dba: 0x0180000c
-- ----------------------------------------------------------
KTB Data Block ( Table / Cluster)
struct kcbh, 20 bytes @0
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 ktbbh, 72 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
b2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl [ 2 ] , 48 bytes @44
struct kdbh, 14 bytes @100
ub1 kdbhflag @100
b1 kdbhntab @101
b2 kdbhnrow @102
sb2 kdbhfrre @104
sb2 kdbhfsbo @106
sb2 kdbhfseo @108
b2 kdbhavsp @110
b2 kdbhtosp @112
struct kdbt [ 1 ] , 4 bytes @114
b2 kdbtoffs @114
b2 kdbtnrow @116
sb2 kdbr [ 1 ] @118
ub1 freespace [ 8056 ] @120
ub1 rowdata [ 12 ] @8176
ub4 tailchk @8188
BBED >
File : / u01 / app / oracle / oradata / orcl / small_tbs01.dbf ( 6 )
Block: 12 Dba: 0x0180000c
-- ----------------------------------------------------------
KTB Data Block ( Table / Cluster)
struct kcbh, 20 bytes @0
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 ktbbh, 72 bytes @20
ub1 ktbbhtyp @20
union ktbbhsid, 4 bytes @24
struct ktbbhcsc, 8 bytes @28
b2 ktbbhict @36
ub1 ktbbhflg @38
ub1 ktbbhfsl @39
ub4 ktbbhfnx @40
struct ktbbhitl [ 2 ] , 48 bytes @44
struct kdbh, 14 bytes @100
ub1 kdbhflag @100
b1 kdbhntab @101
b2 kdbhnrow @102
sb2 kdbhfrre @104
sb2 kdbhfsbo @106
sb2 kdbhfseo @108
b2 kdbhavsp @110
b2 kdbhtosp @112
struct kdbt [ 1 ] , 4 bytes @114
b2 kdbtoffs @114
b2 kdbtnrow @116
sb2 kdbr [ 1 ] @118
ub1 freespace [ 8056 ] @120
ub1 rowdata [ 12 ] @8176
ub4 tailchk @8188
BBED >
这里面的一系列的struct,可以参见如下介绍...
///////////////////////////////////////////////////////////////////////////////////////
/
//////////// Block Header Structure, 20 bytes //////////////////////////////////////////
struct kcbh, 20 bytes @ 0
ub1 type_kcbh @ 0 -- Block Type
-- 01 - Undo segment header
-- 02 - Undo data block
-- 03 - Save undo header
-- 04 - Save undo data block
-- 05 - Data segment header
-- 06 - Trans data, KTB managed data block(with ITL)
-- 07 - Temp table data block (no ITL)
-- 08 - Sort key
-- 09 - Sort Run
-- 10 - Segment free list block
-- 11 - Data file header
ub1 frmt_kcbh @ 1 -- Block Format 1 = Oracle7, 2 = Oracle8 +
ub1 spare1_kcbh @ 2 -- Not used, filler field
ub1 spare2_kcbh @ 3 -- Not used, filler field
ub4 rdba_kcbh @ 4 -- RDBA ( 4 bytes) - Relative Data Block Address
ub4 bas_kcbh @ 8 -- SCN Base ( 4 bytes)
ub2 wrp_kcbh @ 12 -- SCN Wrap ( 2 bytes)
ub1 seq_kcbh @ 14 -- Sequence Number, incremented for every change made to the block at the same SCN
ub1 flg_kcbh @ 15 -- Flag:
-- 0x01 New Block
-- 0x02 Delayed Logging Chang advanced SCN / seq
-- 0x04 Check value saved - block XOR ' s to Zero
-- 0x08 Temporary block
ub2 chkval_kcbh @ 16 -- Optional block checksum ( if DB_BLOCK_CHECKSUM = TRUE)
ub2 spare3_kcbh @ 18 -- Not used, filler field
/////////////////////////////////////////////////////////////////////////////////////// //
///////// Transaction Fixed Header Structure, 72 Bytes ////////////////////////////////////
struct ktbbh, 72 bytes @ 20
ub1 ktbbhtyp @ 20 -- Block type ( 1 = DATA, 2 = INDEX)
union ktbbhsid, 4 bytes @ 24 -- Segment / Object ID
struct ktbbhcsc, 8 bytes @ 28 -- SCN at last block cleanout
b2 ktbbhict @ 36 -- Number of ITL slots
ub1 ktbbhflg @ 38 -- 0 = on the freelist
ub1 ktbbhfsl @ 39 -- ITL TX freelist slot
ub4 ktbbhfnx @ 40 -- DBA of next block on the freelist
struct ktbbhitl[ 2 ], 48 bytes @ 44 -- ITL list index, each ITL takes up 24 bytes
//////////////////////////////////////////////////////////////////////////////////////////
/////////////// Data Header Structure, 14 bytes ////////////////////////////////////////// //
struct kdbh, 14 bytes @ 100
ub1 kdbhflag @ 100 -- N = pctfree hit(clusters)
-- F = do not put on freelist
-- K = flushable cluster keys
b1 kdbhntab @ 101 -- Number of tables ( > 1 in clusters)
b2 kdbhnrow @ 102 -- Number of rows ( 2 bytes)
sb2 kdbhfrre @ 104 -- First free row entry index; - 1 = you have to add one
sb2 kdbhfsbo @ 106 -- Freespace begin offset
sb2 kdbhfseo @ 108 -- Freespace end offset
b2 kdbhavsp @ 110 -- Available space in the block
b2 kdbhtosp @ 112 -- Total available space when all TXs commit
/////////////////////////////////////////////////////////////////////////////////////// /
///////////////////// Table Directory Entry Structure, 4 bytes ///////////////////////////
struct kdbt[ 1 ], 4 bytes @ 114
b2 kdbtoffs @ 114
b2 kdbtnrow @ 116
/////////////////////////////////////////////////////////////////////////////////////// /
////////////////// Row Directory ////////////////////////////////////////////////////// /
sb2 kdbr[ 1 ] @ 118
/////////////////////////////////////////////////////////////////////////////////////// /
/////////////// // Free Space ///////////////////////////////////////////////////////// //
ub1 freespace[ 8056 ] @ 120
///////////////////////////////////////////////////////////////////////////////////////
///////////////////// Row Data ///////////////////////////////////////////////////////// /
ub1 rowdata[ 12 ] @ 8176
//////////////////////////////////////////////////////////////////////////////////// //
///////////////////// Block Tail Check, 4 bytes /////////////////////////////////////// /
ub4 tailchk @ 8188 -- Lower order two bytes of SCN Base + Block Type + SCN Seq
//////////// Block Header Structure, 20 bytes //////////////////////////////////////////
struct kcbh, 20 bytes @ 0
ub1 type_kcbh @ 0 -- Block Type
-- 01 - Undo segment header
-- 02 - Undo data block
-- 03 - Save undo header
-- 04 - Save undo data block
-- 05 - Data segment header
-- 06 - Trans data, KTB managed data block(with ITL)
-- 07 - Temp table data block (no ITL)
-- 08 - Sort key
-- 09 - Sort Run
-- 10 - Segment free list block
-- 11 - Data file header
ub1 frmt_kcbh @ 1 -- Block Format 1 = Oracle7, 2 = Oracle8 +
ub1 spare1_kcbh @ 2 -- Not used, filler field
ub1 spare2_kcbh @ 3 -- Not used, filler field
ub4 rdba_kcbh @ 4 -- RDBA ( 4 bytes) - Relative Data Block Address
ub4 bas_kcbh @ 8 -- SCN Base ( 4 bytes)
ub2 wrp_kcbh @ 12 -- SCN Wrap ( 2 bytes)
ub1 seq_kcbh @ 14 -- Sequence Number, incremented for every change made to the block at the same SCN
ub1 flg_kcbh @ 15 -- Flag:
-- 0x01 New Block
-- 0x02 Delayed Logging Chang advanced SCN / seq
-- 0x04 Check value saved - block XOR ' s to Zero
-- 0x08 Temporary block
ub2 chkval_kcbh @ 16 -- Optional block checksum ( if DB_BLOCK_CHECKSUM = TRUE)
ub2 spare3_kcbh @ 18 -- Not used, filler field
/////////////////////////////////////////////////////////////////////////////////////// //
///////// Transaction Fixed Header Structure, 72 Bytes ////////////////////////////////////
struct ktbbh, 72 bytes @ 20
ub1 ktbbhtyp @ 20 -- Block type ( 1 = DATA, 2 = INDEX)
union ktbbhsid, 4 bytes @ 24 -- Segment / Object ID
struct ktbbhcsc, 8 bytes @ 28 -- SCN at last block cleanout
b2 ktbbhict @ 36 -- Number of ITL slots
ub1 ktbbhflg @ 38 -- 0 = on the freelist
ub1 ktbbhfsl @ 39 -- ITL TX freelist slot
ub4 ktbbhfnx @ 40 -- DBA of next block on the freelist
struct ktbbhitl[ 2 ], 48 bytes @ 44 -- ITL list index, each ITL takes up 24 bytes
//////////////////////////////////////////////////////////////////////////////////////////
/////////////// Data Header Structure, 14 bytes ////////////////////////////////////////// //
struct kdbh, 14 bytes @ 100
ub1 kdbhflag @ 100 -- N = pctfree hit(clusters)
-- F = do not put on freelist
-- K = flushable cluster keys
b1 kdbhntab @ 101 -- Number of tables ( > 1 in clusters)
b2 kdbhnrow @ 102 -- Number of rows ( 2 bytes)
sb2 kdbhfrre @ 104 -- First free row entry index; - 1 = you have to add one
sb2 kdbhfsbo @ 106 -- Freespace begin offset
sb2 kdbhfseo @ 108 -- Freespace end offset
b2 kdbhavsp @ 110 -- Available space in the block
b2 kdbhtosp @ 112 -- Total available space when all TXs commit
/////////////////////////////////////////////////////////////////////////////////////// /
///////////////////// Table Directory Entry Structure, 4 bytes ///////////////////////////
struct kdbt[ 1 ], 4 bytes @ 114
b2 kdbtoffs @ 114
b2 kdbtnrow @ 116
/////////////////////////////////////////////////////////////////////////////////////// /
////////////////// Row Directory ////////////////////////////////////////////////////// /
sb2 kdbr[ 1 ] @ 118
/////////////////////////////////////////////////////////////////////////////////////// /
/////////////// // Free Space ///////////////////////////////////////////////////////// //
ub1 freespace[ 8056 ] @ 120
///////////////////////////////////////////////////////////////////////////////////////
///////////////////// Row Data ///////////////////////////////////////////////////////// /
ub1 rowdata[ 12 ] @ 8176
//////////////////////////////////////////////////////////////////////////////////// //
///////////////////// Block Tail Check, 4 bytes /////////////////////////////////////// /
ub4 tailchk @ 8188 -- Lower order two bytes of SCN Base + Block Type + SCN Seq