详细解析LMT的datafile的物理结构

| No Comments

之前已经写过:

"详细解析9i10gdatafile header"

 

这里是详细解析系列的第二篇文章,在这篇文章里,我们详细解析了LMT所在的datafile的物理结构。

 

对于LMT所在的datafile的物理结构,我们先来看一个图及随后的一段文字:

LMT structure resize.jpg

The locally-managed (bitmapped) tablespace file has the following structure:

1File header: 1 block

2Bitmapped file space header: 1 block

3Head portion of bitmap blocks: N blocks

4Useful file blocks: U units (A unit is a number of blocks.)

5Tail portion of bitmap blocks: M blocks

If a Unit = B blocks, then the total file size = 1 + 1 + N + U*B +M.

The operating system file allocated will in some cases be file size + 1 block for the OS header.

 

有了上述理论基础,现在我们来看一个实例:

SQL> create tablespace testlmt datafile '/dras20/astca/testlmt01.dbf' size 10M extent management local uniform size 1m segment space management auto;

 

Tablespace created

 

SQL> create table testlmttb tablespace testlmt as select * from dba_objects;

 

Table created

 

SQL> select extent_id,file_id,block_id,bytes from dba_extents where segment_name='TESTLMTTB';

 

 EXTENT_ID    FILE_ID   BLOCK_ID      BYTES

---------- ---------- ---------- ----------

         0        138          9    1048576

         1        138        137    1048576

         2        138        265    1048576

         3        138        393    1048576

 

$ ls -l /dras20/astca/testlmt01.dbf

-rw-r-----   1 oracle   dba        10493952 Sep 02 10:43 /dras20/astca/testlmt01.dbf

 

SQL>  select 1048576/8192 extent_block_num,10493952-1024*1024*10 os_block_size from dual;

 

EXTENT_BLOCK_NUM OS_BLOCK_SIZE

---------------- -------------

             128          8192

 

很明显,对于表TESTLMTTB而言,oracle这里分配了4extent,并且这4extentadjacent的。Oracle这里保留了9blockblock 0OS header,我们这里来详细看一下上述datafile/dras20/astca/testlmt01.dbf)的物理结构:

 

Block 0OS header

 

Block 1datafile header,这个datafile header的详细结构我已经在"详细解析9i10gdatafile header"中逐个byte的解析过。

 

Block 2Bitmapped file space header,它的详细结构如下:

BBED> set file 138

        FILE#           138

 

BBED> set block 2

        BLOCK#          2

 

BBED> dump

 File: /dras20/astca/testlmt01.dbf (138)

 Block: 2                Offsets:    0 to  511           Dba:0x22800002

------------------------------------------------------------------------

 1d020000 22800002 aa35c791 00080204 8a370000 0000008a 00000080 00000500

 00000001 00000000 00000000 00000007 00000488 00000004 00000005 00000000

 00000000 00000000 00000000 00000000 00000189 00000080 00000000 00000000

......省略显示部分全为0的内容

 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

 

 <32 bytes per line>

 

BBED> set offset 8000

        OFFSET          8000

 

BBED> dump

 File: /dras20/astca/testlmt01.dbf (138)

 Block: 2                Offsets: 8000 to 8191           Dba:0x22800002

------------------------------------------------------------------------

 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

 ......省略显示部分全为0的内容

 00000000 00000000 00000000 00000000 00000000 00000000 00000000 c7911d02

 

 <32 bytes per line>

 

buffer tsn: 89 rdba: 0x22800002 (138/2)

scn: 0x0008.aa35c791 seq: 0x02 flg: 0x04 tail: 0xc7911d02

frmt: 0x02 chkval: 0x8a37 type: 0x1d=KTFB Bitmapped File Space Header

File Space Header Block:

Header Control:

RelFno: 138, Unit: 128, Size: 1280, Flag: 1

AutoExtend: NO, Increment: 0, MaxSize: 0

Initial Area: 7, Tail: 1160, First: 4, Free: 5

Header Opcode:

Save: No Pending Op

 

SQL> select to_char(138,'XXXX') RelFno,to_char(128,'XXXX') Unit,to_char(1280,'XXXX') Datafile_Size,to_char(1160,'XXXX') Tail from dual;

 

RELFNO UNIT  DATAFILE_SIZE TAIL

------     -----    ------         ------

   8A     80   500           488

 

上述dump内容中各个字段的含义是一目了然的,这里不再赘述。

从上述dump内容中我们可以看到unit size128block,即1M

 

Block 3Block 8Head portion of bitmap blocks

BBED> set file 138

        FILE#           138

 

BBED> set block 3

        BLOCK#          3

 

BBED> set offset 0

        OFFSET          0

 

BBED> dump

 File: /dras20/astca/testlmt01.dbf (138)

 Block: 3                Offsets:    0 to  511           Dba:0x22800003

------------------------------------------------------------------------

 1e020000 22800003 aa35c791 00080104 71c20000 0000008a 00000009 00000000

 00000004 0000f7fc 00000000 00000000 00000000 00000000 0f000000 00000000

 ......省略显示部分全为0的内容

 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

 

 <32 bytes per line>

 

buffer tsn: 89 rdba: 0x22800003 (138/3)

scn: 0x0008.aa35c791 seq: 0x01 flg: 0x04 tail: 0xc7911e01

frmt: 0x02 chkval: 0x71c2 type: 0x1e=KTFB Bitmapped File Space Bitmap

File Space Bitmap Block:

BitMap Control:

RelFno: 138, BeginBlock: 9, Flag: 0, First: 4, Free: 63484

 

上述dump内容中的其他部分乏善可陈,唯一可以说的就是最后的一个0f0f就是00001111,按照oraclebitmap的惯例(以每个byte为一组,整体是从左往右读,但组内是从右往左读),这样翻译过来就是11110000,即used, used, used, used, free, free, free, free.

所以oracle这里需要free extent的时候是从第4extent开始扫描(0,1,2,3都已经被用了),这也和我们从dba_extents里看到的结果一致。

 

这也就是LMT的真正含义,即用bitmap来代替fet$uet$

 

Block 3里的bitmap里还有那么多bit0呢,所以Block 4Block 8中的bitmap必然全为0

 

上述图中的第4部分Useful file blocks这里不再赘述,这些内容我会考虑在后续的文章里进一步阐述。

 

上述图中的第5部分Tail portion of bitmap blocks我在实际的dump过程中并没有看到,有些奇怪。

Leave a comment