Cache Header and Tail

Cache Header and Tail

All datafile blocks are written and read by the cache layer of the Oracle kernel (KCB) generally through the database buffer cache. The cache layer reads and maintains a 20-byte header and 4-byte tail on each data block, called the  cache header and tail. The cache header is called the  common block headerin V$TYPE_SIZE and elsewhere. Controlfile blocks also have a cache header and tail, although not all the fields are used.

This is what the cache header and tail look like in a datablock dump. (This is taken from a blockdump of the segment header block of the SYSTEM rollback segment.)

buffer tsn: 0 rdba: 0x00400002 (1/2)
scn: 0x0000.00e9ffb4 seq: 0x01 flg: 0x04 tail: 0xffb40e01
frmt: 0x02 chkval: 0xb31e type: 0x0e=KTU UNDO HEADER W/UNLIMITED EXTENTS
The header is comprised of the following fields.
database
block address
4 bytesThe tablespace relative database block address (RDBA). This is constructed from the tablespace relative file number, and the block number of the data block within that file.
SCN6 bytesThe SCN at which the block was last changed. The low-order 4 bytes are called the SCN base, and the high-order 2 bytes are called the SCN wrap.
sequence1 byteA sequence number incremented for each change to a block at the same SCN. If the sequence number wraps, a new SCN must be allocated.

The value 0xff is reserved. When present it indicates that the block has been marked as corrupt by Oracle.

flag1 byteA combination of 1-bit flag values.
1 = virgin block
2 = last change to the block was for a cleanout operation
4 = checksum value is set
8 = temporary data
format1 byteThe format of the cache header was changed for Oracle8. Under Oracle8 and 9, the value is always 2. Previously, it was 1.
checksum2 bytesAn optional checksum of the block contents. When a block is written, the checksum is either cleared or set depending on the setting of the db_block_checksum parameter. When a block is read, the checksum is verified if present and if the parameter is set to TRUE. Checksums are always calculated and checked for blocks in the SYSTEM tablespace.

The checksum is the XOR of all the other 2-byte pairs in the block. Thus when a block with a checksum is checked, the XOR of all the 2-byte words in the block should be 0.

block type1 byteThe most common block types is 6, which is used for all table, index and cluster data blocks.
unused4 bytesUnused space, possibly for backward or forward compatibility.
The tail is comprised of the low-order two bytes of the SCN base followed by the block type and the sequence number. The consistency of the header and tail is checked whenever a block is read. This detects most block corruptions, in particular split blocks from hot backups.

The physical order of the header fields is: block type, format, unused (2 bytes), RDBA, SCN, sequence, flag, checksum, unused (2 bytes). The following output from BBED (a low level block browser / editor utility) corresponds to the above extract from a blockdump of the segment header block of the SYSTEM rollback segment.

BBED> print kcbh
struct kcbh, 20 bytes                       @0
   ub1 type_kcbh                            @0        0x0e
   ub1 frmt_kcbh                            @1        0x02
   ub1 spare1_kcbh                          @2        0x00
   ub1 spare2_kcbh                          @3        0x00
   ub4 rdba_kcbh                            @4        0x00400002
   ub4 bas_kcbh                             @8        0x00e9ffb4
   ub2 wrp_kcbh                             @12       0x0000
   ub1 seq_kcbh                             @14       0x01
   ub1 flg_kcbh                             @15       0x04 (KCBHFCKV)
   ub2 chkval_kcbh                          @16       0xb31e
   ub2 spare3_kcbh                          @18       0x0000

BBED> print tailchk
ub4 tailchk                                 @2044     0xffb40e01

 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值