之前已经写过:
这里是详细解析系列的第二篇文章,在这篇文章里,我们详细解析了LMT所在的datafile的物理结构。
对于LMT所在的datafile的物理结构,我们先来看一个图及随后的一段文字:
The locally-managed (bitmapped) tablespace file has the following structure: 1、File header: 1 block 2、Bitmapped file space header: 1 block 3、Head portion of bitmap blocks: N blocks 4、Useful file blocks: U units (A unit is a number of blocks.) 5、Tail 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 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这里分配了4个extent,并且这4个extent是adjacent的。Oracle这里保留了9个block,block 0是OS header,我们这里来详细看一下上述datafile(/dras20/astca/testlmt01.dbf)的物理结构: Block 0:OS header Block 1:datafile header,这个datafile header的详细结构我已经在"详细解析9i和 Block 2:Bitmapped 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 aa 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 <32 bytes per line> buffer tsn: 89 rdba: 0x22800002 (138/2) scn: 0x0008.aa frmt: 0x02 chkval: 0x 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 ------ ----- ------ ------ 上述dump内容中各个字段的含义是一目了然的,这里不再赘述。 从上述dump内容中我们可以看到unit size是128个block,即1M。 Block 3至Block 8:Head 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 aa 00000004 ......省略显示部分全为0的内容 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 <32 bytes per line> buffer tsn: 89 rdba: 0x22800003 (138/3) scn: 0x0008.aa frmt: 0x02 chkval: 0x File Space Bitmap Block: BitMap Control: RelFno: 138, BeginBlock: 9, Flag: 0, First: 4, Free: 63484 上述dump内容中的其他部分乏善可陈,唯一可以说的就是最后的一个0f,0f就是00001111,按照oracle看bitmap的惯例(以每个byte为一组,整体是从左往右读,但组内是从右往左读),这样翻译过来就是11110000,即used, used, used, used, free, free, free, free. 所以oracle这里需要free extent的时候是从第4个extent开始扫描(0,1,2,3都已经被用了),这也和我们从dba_extents里看到的结果一致。 这也就是LMT的真正含义,即用bitmap来代替fet$和uet$。 Block 3里的bitmap里还有那么多bit是0呢,所以Block 4至Block 8中的bitmap必然全为0。 上述图中的第4部分Useful file blocks这里不再赘述,这些内容我会考虑在后续的文章里进一步阐述。 上述图中的第5部分Tail portion of bitmap blocks我在实际的dump过程中并没有看到,有些奇怪。
Leave a comment