Oracle Data Block物理结构

转自:http://blog.chinaunix.net/u/19782/showart_412187.html

 

近来在Itpub上看到AnySQL的Mydul的第一版本的源码, http://www.itpub.net/858109.html 学习中。其实好多地方不是很明白, java也不是很熟悉, 格式不是很了解, 很多Oracle的功能也不熟悉。慢慢学习中。。。

与这个相关的东西还有 ITpub grassbell 斑主在 2004-07-27 一篇Oracle Data Block物理结构的文章http://epub.itpub.net/9/9.htm, 好早啊, 那时我还在学校,什么Oracle几乎没什么接触。 不想那么多了, 就想弄明白,哪怕已经很过时了。

我使用英文的google查询了一下找到这个篇文章
http://www.orafaq.com/papers/dissassembling_the_data_block.pdf

这个应该比较全面的了:
下面的内容主要来源 orafaq 的Oracle Data block格式的小节, 不是很具体:

Oracle Data Block Format

=================
struct kcbh, 20 bytes               Block Header Structure
    ub1 type_kcbh                   Block Type
                                    Different block types are designated by
                                    the first byte of the block.
                                    
                                    01  Undo segment header
                                    02  Undo data block
                                    03  Save undo header
                                    04  Save undo data block
                                    05  Data segment header(temp, index, 
                                        data and so on)
                                    06  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                   Block format 
                                    1   Oracle 7
                                    2   Oracle 8+
                                    
    ub1 spare1_kcbh                 Not used
    ub1 spare2_kcbh                 Not used
    ub4 rbda_kcbh                   RDBA - Relative Data Block Address
    ub4 bas_kcbh                    SCN Base
    ub2 wrp_kcbh                    SCN Wrap
    ub1 seq_kcbh                    Sequence number, incremented for every
                                      change made to the block at the same SCN

    ub1 flg_kcbh                    Flag:
                                    0x01    New Block
                                    0x02    Delayed Logging Change 
                                            advanced SCN/seq
                                    0x04    Check value saved - block 
                                            XOR's to zero
                                    0x08    Temporary block

    ub2 chkval_kcbh                 Optional block checksum (if
                                      DB_BLOCK_CHECKSUM = TRUE)

    ub2 spare3_kcbh                 Not used

------------------
struct ktbbh, 72 bytes              Transaction Fixed Header Structure
    ub1 ktbbhtyp                    Block type 
                                    1   Data 
                                    2   Index
    union ktbbhsid, 4 bytes         Segment / Object ID
    struct ktbbhcsc, 8 bytes        SCN at last block cleanout
    b2 ktbbhict                     Number of ITL slots
    ub1 ktbbhflg                    0 = on the freelist
    ub1 ktbbhfs1                    ITL TX freelist slot
    ub4 ktbbhfnx                    DBA of next block on the freelist
    struct ktbbhitl[2], 48 bytes    ITL list index

-------------------
struct kdbh, 14 bytes               Data Header Structure
    ub1 kdbhflag                    N = pctfree hit(clusters); 
                                    F = do not put on freelist;
                                    K = flushable cluster keys
    b1 kdbhntab                     Number of tables (> 1 in clusters)
    b2 kdbhnrow                     Number of rows
    sb2 kdbhfrre                    First free row entry index; 
                                    -1 = you have to add one
    sb2 kdbhfsbo                    Freespace begin offset
    sb2 kdbhfseo                    Freespace end offset
    b2 kdbhavsp                     Available space in the block
    b2 kdbhtosp                     Total available space when all TXs commit

--------------------
struct kdbt[1], 4 bytes             Table Directory Entry Structure
    b2 kdbtoffs
    b2 kdbtnrow

--------------------
sb2 kdbr[1]                         Row Directory
ub1 freespace[8030]                 Free Space
ub1 rowdata[38]                     Row Data
ub4 tailchk                         
    
Tailchecks:
The tail of an Oracle 8+ block is a concatenation of the lower order two bytes of the SCN base, the block type and the SCN sequence number.
E.g. if the SCN base number is 0x00029728, the block type is 06 and the SCN sequence number is 0x02, the tail check would be 0x97280602:

SCN base        Type    SCN seq
9728            06      02

Although this tail check value is generated from three components. Oracle treats the final value as a single unsigned integer stored as a word(4 bytes). On little-endian architecture machines, which include Intel, the value will be stores as low-order byte first. 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值