Oracle Internals Notes

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 header in 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 bytes The 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.
SCN 6 bytes The 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.
sequence 1 byte A 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.

flag 1 byte A 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
format 1 byte The format of the cache header was changed for Oracle8. Under Oracle8 and 9, the value is always 2. Previously, it was 1.
checksum 2 bytes An 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 type 1 byte The most common block types is 6, which is used for all table, index and cluster data blocks.
unused 4 bytes Unused 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


Ixora Pty Ltd.   All rights reserved.
12-Oct-2007 22:22
Search   Questions   Feedback   Up   Home