今天是2013-12-16,今天和明天是我学习oracle生涯中一个特殊的日子。今天晚上进行了一下表空间管理方式的学习,在此记录一下笔记。

对于oracle数据库最小i/0单位是数据块,最想分配空间单位是区,对于表空间的管理其实是对区的管理,在8i之前采用数据字典管理表空间 ,通过uet$和fet$进行管理。可是从8i开始引入了本地管理表空间方式(LMT),以此缓解了系统性能问题(如碎片产生等)。

对于oracle段管理方式,在9i之前采用的是mssm手动段空间管理技术,采用了是在数据段头加入free list进行管理,可是往往出现性能问题(如 buffer busy wai),以此到9i开始引入了assm自动段管理方式。

首先了解段管理表空间方式assm;

在11g中存在延迟段,且在第一次分配区间的时候,在11.2.0.4版本中1-2数据块为数据文件头部信息,3-7为区间位图信息,8-10为段位图信息。

创建测试表空间:

SQL> create tablespace test datafile '+DATAGROUP1/rhys/datafile/test.dbf' size 20M autoextend off extent management local uniform size 156K segment space management auto;

Tablespace created.

创建用户:

SQL> create user amy identified by root default tablespace test temporary tablespace temp quota 10M on test password expire;

User created.

SQL> grant create session,resource to amy;

Grant succeeded.

SQL> conn amy/root
ERROR:
ORA-28001: the password has expired

Changing password for amy
New password:
Retype new password:
Password changed
Connected.

创建测试表:
SQL> create table t (
  2  a number,
  3  b varchar2(20));

Table created.
SQL> insert into t values(1,'a');

1 row created.

SQL> commit;

查看区间分配情况:(sys用户)

SQL> select owner,segment_name,segment_type,file_id,extent_id,block_id from dba_extents where segment_name='T';

OWNER                          SEGMENT_NAME                                                                      SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID
------------------------------ --------------------------------------------------------------------------------- ------------------ ---------- ---------- ----------
AMY                            T                                                                                 TABLE                       5          0          8

SQL> ALTER TABLE AMY.T ALLOCATE EXTENT;

Table altered.

SQL> select owner,segment_name,segment_type,file_id,extent_id,block_id,BLOCKS from dba_extents where segment_name='T';

OWNER                          SEGMENT_NAME                   SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID     BLOCKS
------------------------------ ------------------------------ ------------------ ---------- ---------- ---------- ----------
AMY                            T                              TABLE                       5          0          8         20
AMY                            T                              TABLE                       5          1         28         20

SQL> alter system dump datafile 5 block 9;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3386.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

查看trace文件:

可以看到这是第一个位图块,没有任何数据。

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 1    
   unformatted: 0       total: 4         first useful block: 0     
   owning instance : 1
   instance ownership changed at 12/16/2013 20:38:38
   Last successful Search 12/16/2013 20:38:38
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 4     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 0     
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000001 (-/-/-/-/-/HWM)
   Inc #: 0 Objd: 87521
  HWM Flag: HWM Set
      Highwater::  0x0140001c  ext#: 0      blk#: 20     ext size: 20   
  #blocks in seg. hdr's freelists: 0    
  #blocks below: 16   
  mapblk  0x00000000  offset: 0    
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x01400018  Length: 4      Offset: 0     
 
   0:75-100% free   1:75-100% free   2:75-100% free   3:75-100% free
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 9 maxblk 9

父指针指向第10个块parent dba: 0x0140000a
当插入数据之后:

SQL> show user
USER is "SYS"
SQL> conn sudo[amy]/proxy
Connected.
SQL> begin
  2  for i in 202..200000 loop
  3  insert into t(a) values(i);
  4  commit;
  5  end loop;
  6  end;
  7  /

PL/SQL procedure successfully completed.

SQL> select owner,segment_name,segment_type,file_id,extent_id,block_id,BLOCKS from dba_extents where segment_name='T';

OWNER                          SEGMENT_NAME                             SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID     BLOCKS
------------------------------ ---------------------------------------- ------------------ ---------- ---------- ---------- ----------
AMY                            T                                        TABLE                       5          0          8         20
AMY                            T                                        TABLE                       5          1         28         20
AMY                            T                                        TABLE                       5          2         48         20
AMY                            T                                        TABLE                       5          3         68         20
AMY                            T                                        TABLE                       5          4         88         20
AMY                            T                                        TABLE                       5          5        108         20
AMY                            T                                        TABLE                       5          6        128         20
AMY                            T                                        TABLE                       5          7        148         20
AMY                            T                                        TABLE                       5          8        168         20
AMY                            T                                        TABLE                       5          9        188         20
AMY                            T                                        TABLE                       5         10        208         20

OWNER                          SEGMENT_NAME                             SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID     BLOCKS
------------------------------ ---------------------------------------- ------------------ ---------- ---------- ---------- ----------
AMY                            T                                        TABLE                       5         11        228         20
AMY                            T                                        TABLE                       5         12        248         20
AMY                            T                                        TABLE                       5         13        268         20
AMY                            T                                        TABLE                       5         14        288         20
AMY                            T                                        TABLE                       5         15        308         20
AMY                            T                                        TABLE                       5         16        328         20

17 rows selected.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3540.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

查看trace日志:

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 1    
   unformatted: 0       total: 4         first useful block: 0     
   owning instance : 1
   instance ownership changed at 12/16/2013 20:38:38
   Last successful Search 12/16/2013 20:38:38
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 4     
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x01400018  Length: 4      Offset: 0     
 
   0:FULL   1:FULL   2:FULL   3:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 9 maxblk 9
该位图块管理的数据块以及填满数据。父指针指向第10个块parent dba: 0x0140000a

查看第10个块:

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 21:11:20 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a700
SQL> col value for a70
SQL> alter system dump datafile 5 block 10;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3560.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

Start dump data blocks tsn: 6 file#:5 minblk 10 maxblk 10
Block dump from cache:
Dump of buffer cache at level 4 for tsn=6 rdba=20971530
BH (0x7bbf6610) file#: 5 rdba: 0x0140000a (5/10) class: 9 ba: 0x7bb54000
  set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,25
  dbwrid: 0 obj: 87521 objn: 87521 tsn: 6 afn: 5 hint: f
  hash: [0x83d3a660,0x83d3a660] lru: [0x7bbf6838,0x7bbf6490]
  lru-flags: hot_buffer
  obj-flags: object_ckpt_list
  ckptq: [0x73bf43f0,0x73bf4660] fileq: [0x73bf4058,0x73fde770] objq: [0x73fde740,0x7bbf6860] objaq: [0x7bbf6870,0x7bbf64c8]
  st: XCURRENT md: NULL fpin: 'ktspswh4: ktspfsbmb' tch: 20
  flags: buffer_dirty block_written_once redo_since_read
  LRBA: [0x7.16957.0] LSCN: [0x0.15daf9] HSCN: [0x0.160e8c] HSUB: [1]
Block dump from disk:
buffer tsn: 6 rdba: 0x0140000a (5/10)
scn: 0x0000.0015a824 seq: 0x02 flg: 0x04 tail: 0xa8242102
frmt: 0x02 chkval: 0xd354 type: 0x21=SECOND LEVEL BITMAP BLOCK
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007F8C57405A00 to 0x00007F8C57407A00
7F8C57405A00 0000A221 0140000A 0015A824 04020000  [!.....@.$.......]
7F8C57405A10 0000D354 00000000 00000000 00000000  [T...............]
7F8C57405A20 00000000 00000000 00000000 00000000  [................]
        Repeat 1 times
7F8C57405A40 00000000 00000000 00000000 0140000B  [..............@.]
7F8C57405A50 0000000F 00000001 0000000E 00000000  [................]
7F8C57405A60 00000000 00000000 000155E1 00000001  [.........U......]
7F8C57405A70 00000000 01400008 00010001 01400009  [......@.......@.]
7F8C57405A80 00010001 0140001C 00010001 0140001D  [......@.......@.]
7F8C57405A90 00010001 01400030 00010001 01400031  [[email protected].@.]
7F8C57405AA0 00010001 01400044 00010001 01400045  [[email protected].@.]
7F8C57405AB0 00010001 01400058 00010001 01400059  [[email protected].@.]
7F8C57405AC0 00010001 0140006C 00010001 0140006D  [[email protected].@.]
7F8C57405AD0 00010001 01400080 00010001 014000BC  [......@.......@.]
7F8C57405AE0 00010001 014000F8 00010005 00000000  [......@.........]
7F8C57405AF0 00000000 00000000 00000000 00000000  [................]
        Repeat 495 times
7F8C574079F0 00000000 00000000 00000000 A8242102  [.............!$.]
Dump of Second Level Bitmap Block
   number: 15      nfree: 1       ffree: 14     pdba:     0x0140000b
   Inc #: 0 Objd: 87521
  opcode:0
 xid:
  L1 Ranges :
  --------------------------------------------------------
   0x01400008  Free: 1 Inst: 1
   0x01400009  Free: 1 Inst: 1
   0x0140001c  Free: 1 Inst: 1
   0x0140001d  Free: 1 Inst: 1
   0x01400030  Free: 1 Inst: 1
   0x01400031  Free: 1 Inst: 1
   0x01400044  Free: 1 Inst: 1
   0x01400045  Free: 1 Inst: 1
   0x01400058  Free: 1 Inst: 1
   0x01400059  Free: 1 Inst: 1
   0x0140006c  Free: 1 Inst: 1
   0x0140006d  Free: 1 Inst: 1
   0x01400080  Free: 1 Inst: 1
   0x014000bc  Free: 1 Inst: 1
   0x014000f8  Free: 5 Inst: 1
 
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 10 maxblk 10
该块为二级位图块,其中包含了每个一级块信息。父指针指向了0b也就是第11个块(三级位图块)

查看第11块信息:

oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 21:13:53 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a20
SQL> col value for a70
SQL> alter system dump datafile 5 block 11;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                 VALUE
---------- -------------------- ----------------------------------------------------------------------
         1 Diag Enabled         TRUE
         1 ADR Base             /opt/app/oracle
         1 ADR Home             /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace           /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert           /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident        /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump           /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor       /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File   /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3583.trc
         1 Active Problem Count 0
         1 Active Incident Coun 0

INST_ID NAME                 VALUE
---------- -------------------- ----------------------------------------------------------------------
           t

11 rows selected.

SQL>

Start dump data blocks tsn: 6 file#:5 minblk 11 maxblk 11
Block dump from cache:
Dump of buffer cache at level 4 for tsn=6 rdba=20971531
BH (0x7bbf6748) file#: 5 rdba: 0x0140000b (5/11) class: 4 ba: 0x7bb56000
  set: 3 pool: 3 bsz: 8192 bsi: 0 sflg: 1 pwc: 0,25
  dbwrid: 0 obj: 87521 objn: 87521 tsn: 6 afn: 5 hint: f
  hash: [0x83e16550,0x83e16550] lru: [0x7bbf6970,0x7bbf6700]
  lru-flags: hot_buffer
  ckptq: [NULL] fileq: [NULL] objq: [0x7bbf6728,0x73bf3ef0] objaq: [0x80b5d9d8,0x7bbf6738]
  st: XCURRENT md: NULL fpin: 'ktswh03: ktscts' tch: 26
  flags: block_written_once redo_since_read
  LRBA: [0x0.0.0] LSCN: [0x0.0] HSCN: [0xffff.ffffffff] HSUB: [1]
Block dump from disk:
buffer tsn: 6 rdba: 0x0140000b (5/11)
scn: 0x0000.00160e8d seq: 0x02 flg: 0x04 tail: 0x0e8d2302
frmt: 0x02 chkval: 0xffa2 type: 0x23=PAGETABLE SEGMENT HEADER
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007FE375257A00 to 0x00007FE375259A00
7FE375257A00 0000A223 0140000B 00160E8D 04020000  [#.....@.........]
7FE375257A10 0000FFA2 00000000 00000000 00000000  [................]
7FE375257A20 00000000 00000011 00000154 00000A9C  [........T.......]
7FE375257A30 00000010 00000014 00000014 0140015C  [............\.@.]
7FE375257A40 00000000 00000010 00000000 00000142  [............B...]
7FE375257A50 00000000 00000000 00000000 00000001  [................]
7FE375257A60 00000010 00000014 0140002C 00000000  [........,.@.....]
7FE375257A70 00000001 00000000 00000022 0140001C  [........".....@.]
7FE375257A80 01400134 00000000 00000000 00000000  [4.@.............]
7FE375257A90 00000000 00000000 00000000 00000000  [................]
        Repeat 3 times
7FE375257AD0 00000001 00002000 00000000 00001434  [..... ......4...]
7FE375257AE0 00000000 0140000A 00000001 01400134  [[email protected].@.]
7FE375257AF0 0140000A 00000000 00000000 00000000  [..@.............]
7FE375257B00 00000000 00000000 00000011 00000000  [................]
7FE375257B10 000155E1 10000000 01400008 00000014  [.U........@.....]
7FE375257B20 0140001C 00000014 01400030 00000014  [[email protected].@.....]
7FE375257B30 01400044 00000014 01400058 00000014  [[email protected].@.....]
7FE375257B40 0140006C 00000014 01400080 00000014  [l.@.......@.....]
7FE375257B50 01400094 00000014 014000A8 00000014  [..@.......@.....]
7FE375257B60 014000BC 00000014 014000D0 00000014  [..@.......@.....]
7FE375257B70 014000E4 00000014 014000F8 00000014  [..@.......@.....]
7FE375257B80 0140010C 00000014 01400120 00000014  [..@..... .@.....]
7FE375257B90 01400134 00000014 01400148 00000014  [[email protected].@.....]
7FE375257BA0 00000000 00000000 00000000 00000000  [................]
        Repeat 144 times
7FE3752584B0 01400008 0140000C 0140001C 0140001E  [..@...@...@...@.]
7FE3752584C0 01400030 01400032 01400044 01400046  [[email protected][email protected][email protected].@.]
7FE3752584D0 01400058 0140005A 0140006C 0140006E  [[email protected][email protected][email protected].@.]
7FE3752584E0 01400080 01400081 01400080 01400094  [..@...@...@...@.]
7FE3752584F0 01400080 014000A8 014000BC 014000BD  [..@...@...@...@.]
7FE375258500 014000BC 014000D0 014000BC 014000E4  [..@...@...@...@.]
7FE375258510 014000F8 014000F9 014000F8 0140010C  [..@...@...@...@.]
7FE375258520 014000F8 01400120 01400134 01400135  [..@. [email protected][email protected].@.]
7FE375258530 01400134 01400148 00000000 00000000  [[email protected].@.........]
7FE375258540 00000000 00000000 00000000 00000000  [................]
        Repeat 143 times
7FE375258E40 00000000 00000000 0140000A 00000000  [..........@.....]
7FE375258E50 00000000 00000000 00000000 00000000  [................]
        Repeat 185 times
7FE3752599F0 00000000 00000000 00000000 0E8D2302  [.............#..]
  Extent Control Header
  -----------------------------------------------------------------
  Extent Header:: spare1: 0      spare2: 0      #extents: 17     #blocks: 340  
                  last map  0x00000000  #maps: 0      offset: 2716 
      Highwater::  0x0140015c  ext#: 16     blk#: 20     ext size: 20   
  #blocks in seg. hdr's freelists: 0    
  #blocks below: 322  
  mapblk  0x00000000  offset: 16   
                   Unlocked
  --------------------------------------------------------
  Low HighWater Mark :
      Highwater::  0x0140002c  ext#: 1      blk#: 16     ext size: 20   
  #blocks in seg. hdr's freelists: 0    
  #blocks below: 34   
  mapblk  0x00000000  offset: 1    
  Level 1 BMB for High HWM block: 0x01400134
  Level 1 BMB for Low HWM block: 0x0140001c
  --------------------------------------------------------
  Segment Type: 1 nl2: 1      blksz: 8192   fbsz: 0     
  L2 Array start offset:  0x00001434
  First Level 3 BMB:  0x00000000
  L2 Hint for inserts:  0x0140000a
  Last Level 1 BMB:  0x01400134
  Last Level II BMB:  0x0140000a
  Last Level III BMB:  0x00000000
     Map Header:: next  0x00000000  #extents: 17   obj#: 87521  flag: 0x10000000
  Inc # 0
  Extent Map
  -----------------------------------------------------------------
   0x01400008  length: 20   
   0x0140001c  length: 20   
   0x01400030  length: 20   
   0x01400044  length: 20   
   0x01400058  length: 20   
   0x0140006c  length: 20   
   0x01400080  length: 20   
   0x01400094  length: 20   
   0x014000a8  length: 20   
   0x014000bc  length: 20   
   0x014000d0  length: 20   
   0x014000e4  length: 20   
   0x014000f8  length: 20   
   0x0140010c  length: 20   
   0x01400120  length: 20   
   0x01400134  length: 20   
   0x01400148  length: 20   
 
  Auxillary Map
  --------------------------------------------------------
   Extent 0     :  L1 dba:  0x01400008 Data dba:  0x0140000c
   Extent 1     :  L1 dba:  0x0140001c Data dba:  0x0140001e
   Extent 2     :  L1 dba:  0x01400030 Data dba:  0x01400032
   Extent 3     :  L1 dba:  0x01400044 Data dba:  0x01400046
   Extent 4     :  L1 dba:  0x01400058 Data dba:  0x0140005a
   Extent 5     :  L1 dba:  0x0140006c Data dba:  0x0140006e
   Extent 6     :  L1 dba:  0x01400080 Data dba:  0x01400081
   Extent 7     :  L1 dba:  0x01400080 Data dba:  0x01400094
   Extent 8     :  L1 dba:  0x01400080 Data dba:  0x014000a8
   Extent 9     :  L1 dba:  0x014000bc Data dba:  0x014000bd
   Extent 10    :  L1 dba:  0x014000bc Data dba:  0x014000d0
   Extent 11    :  L1 dba:  0x014000bc Data dba:  0x014000e4
   Extent 12    :  L1 dba:  0x014000f8 Data dba:  0x014000f9
   Extent 13    :  L1 dba:  0x014000f8 Data dba:  0x0140010c
   Extent 14    :  L1 dba:  0x014000f8 Data dba:  0x01400120
   Extent 15    :  L1 dba:  0x01400134 Data dba:  0x01400135
   Extent 16    :  L1 dba:  0x01400134 Data dba:  0x01400148
  --------------------------------------------------------
 
   Second Level Bitmap block DBAs
   --------------------------------------------------------
   DBA 1:   0x0140000a
 
End dump data blocks tsn: 6 file#: 5 minblk 11 maxblk 11

可以看出11块为数据段头信息。

继续查看第二个extent的第一个块(28块)

oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 21:25:41 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 28;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3650.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 2    
   unformatted: 0       total: 16        first useful block: 2     
   owning instance : 1
   instance ownership changed at 12/16/2013 21:06:16
   Last successful Search 12/16/2013 21:06:16
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 16    
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x0140001c  Length: 16     Offset: 0     
 
   0:Metadata   1:Metadata   2:FULL   3:FULL
   4:FULL   5:FULL   6:FULL   7:FULL
   8:FULL   9:FULL   10:FULL   11:FULL
   12:FULL   13:FULL   14:FULL   15:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 28 maxblk 28
这一是第二个extent的第一位图块,父指针为第10个块。

查看第29个块。

oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 21:27:36 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 29;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3664.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL> exit

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 3    
   unformatted: 0       total: 4         first useful block: 0     
   owning instance : 1
   instance ownership changed at 12/16/2013 21:06:15
   Last successful Search 12/16/2013 21:06:15
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 4     
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x0140002c  Length: 4      Offset: 0     
 
   0:FULL   1:FULL   2:FULL   3:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 29 maxblk 29
这个也是第一位图块,其中管理4个块。而第28位图块管理16个块,一共管理20个块,正好到下一个extent。

继续查看30块;

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 21:30:54 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 30;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3683.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL>

。。。。。。。。。。。。。。。

col  0: [ 4]  c3 03 0c 39
tab 0, row 36, @0x1e70
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3a
tab 0, row 37, @0x1e68
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3b
tab 0, row 38, @0x1e60
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3c
tab 0, row 39, @0x1e58
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3d
tab 0, row 40, @0x1e50
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3e
tab 0, row 41, @0x1e48
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 3f
tab 0, row 42, @0x1e40
tl: 8 fb: --H-FL-- lb: 0x0  cc: 1
col  0: [ 4]  c3 03 0c 40
tab 0, row 43, @0x1e38

。。。。。。。。。。。。。。

这就记录了数据信息。

继续查看第三个extent,第一个块48。

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 22:06:00 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 48;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3916.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL>
SQL>
SQL>
SQL> exit

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 4    
   unformatted: 0       total: 16        first useful block: 2     
   owning instance : 1
   instance ownership changed at 12/16/2013 21:06:21
   Last successful Search 12/16/2013 21:06:21
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 16    
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x01400030  Length: 16     Offset: 0     
 
   0:Metadata   1:Metadata   2:FULL   3:FULL
   4:FULL   5:FULL   6:FULL   7:FULL
   8:FULL   9:FULL   10:FULL   11:FULL
   12:FULL   13:FULL   14:FULL   15:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 48 maxblk 48
这是第三个分区的第一个块,为第一位图块,管理16个块,父指针指向了第10个块二级位图块。

继续查看49个块

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 22:11:30 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 49;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_3967.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL>
SQL>
SQL>
SQL>
SQL> exit

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 5    
   unformatted: 0       total: 4         first useful block: 0     
   owning instance : 1
   instance ownership changed at 12/16/2013 21:06:20
   Last successful Search 12/16/2013 21:06:20
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 4     
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x01400040  Length: 4      Offset: 0     
 
   0:FULL   1:FULL   2:FULL   3:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 49 maxblk 49
注意这也是第一个位图块,父指针指向第二个位图块10块,管理4个block,加上48块的位图块管理块,正好是20个块。

注意:刚刚开始在dump第九个块开始,可是在创建表的时候分配的第一个块为第8个块。下面查看一下:

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Mon Dec 16 22:24:38 2013

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile  5 block 8;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_4037.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL> exit

Dump of First Level Bitmap Block
 --------------------------------
   nbits : 4 nranges: 1         parent dba:  0x0140000a   poffset: 0    
   unformatted: 0       total: 16        first useful block: 4     
   owning instance : 1
   instance ownership changed at 12/16/2013 21:03:15
   Last successful Search 12/16/2013 21:03:15
   Freeness Status:  nf1 0      nf2 0      nf3 0      nf4 0     
 
   Extent Map Block Offset: 4294967295
   First free datablock : 16    
   Bitmap block lock opcode 0
   Locker xid:     :  0x0000.000.00000000
   Dealloc scn: 925704.0
   Flag: 0x00000000 (-/-/-/-/-/-)
   Inc #: 0 Objd: 87521
  --------------------------------------------------------
  DBA Ranges :
  --------------------------------------------------------
   0x01400008  Length: 16     Offset: 0     
 
   0:Metadata   1:Metadata   2:Metadata   3:Metadata
   4:FULL   5:FULL   6:FULL   7:FULL
   8:FULL   9:FULL   10:FULL   11:FULL
   12:FULL   13:FULL   14:FULL   15:FULL
  --------------------------------------------------------
End dump data blocks tsn: 6 file#: 5 minblk 8 maxblk 8
可以看出该块管理16个块前四个包含了元数据信息,除了第一个extent的第8个块之外,其他extent的第一个block都有两个块包含元数据。且该父指针指向了第10个块第二位图块。

总结一下:

每个extent除了第一个exten之外其他的每个extent的第一个块和第二个块都属于第一位图块,父指针都指向第二位图块(10block),且每个extent的第一个块和第二个块都作为第一位图块管理其他剩余的块。对于第一个extent来说,第一位图块为8到9,第二位图块为10,如果第二位图块不能满足需求则到第三位图块也就是11块。

简要图片如下:

oracle 表空管理方式(LMT)、ASSM段管理方式、一级位图块、二级位图块、三级位图块。-LMLPHP

在来看一下表空间管理方式的lmt。

SQL> conn sys/root as sysdba
Connected.
SQL> set linesize 200
SQL> col name for a30
SQL> col value for a70
SQL> alter system dump datafile 5 block 3;

System altered.

SQL> select * from v$diag_info;

INST_ID NAME                           VALUE
---------- ------------------------------ ----------------------------------------------------------------------
         1 Diag Enabled                   TRUE
         1 ADR Base                       /opt/app/oracle
         1 ADR Home                       /opt/app/oracle/diag/rdbms/rhys/RHYS
         1 Diag Trace                     /opt/app/oracle/diag/rdbms/rhys/RHYS/trace
         1 Diag Alert                     /opt/app/oracle/diag/rdbms/rhys/RHYS/alert
         1 Diag Incident                  /opt/app/oracle/diag/rdbms/rhys/RHYS/incident
         1 Diag Cdump                     /opt/app/oracle/diag/rdbms/rhys/RHYS/cdump
         1 Health Monitor                 /opt/app/oracle/diag/rdbms/rhys/RHYS/hm
         1 Default Trace File             /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_4079.trc
         1 Active Problem Count           0
         1 Active Incident Count          0

11 rows selected.

SQL>

Block dump from disk:
buffer tsn: 6 rdba: 0x01400003 (5/3)
scn: 0x0000.00160e8c seq: 0x01 flg: 0x04 tail: 0x0e8c1e01
frmt: 0x02 chkval: 0xb146 type: 0x1e=KTFB Bitmapped File Space Bitmap
Hex dump of block: st=0, typ_found=1
Dump of memory from 0x00007F0928BD0A00 to 0x00007F0928BD2A00
7F0928BD0A00 0000A21E 01400003 00160E8C 04010000  [......@.........]
7F0928BD0A10 0000B146 00000005 00000008 00000000  [F...............]
7F0928BD0A20 00000011 0000F7EF 00000000 00000000  [................]
7F0928BD0A30 00000000 00000000 0001FFFF 00000000  [................]
7F0928BD0A40 00000000 00000000 00000000 00000000  [................]
        Repeat 506 times
7F0928BD29F0 00000000 00000000 00000000 0E8C1E01  [................]
File Space Bitmap Block:
BitMap Control:
RelFno: 5, BeginBlock: 8, Flag: 0, First: 17, Free: 63471
FFFF010000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000
0000000000000000 0000000000000000 0000000000000000 0000000000000000

对于oracle 每组数据信息,组和组直接从左往右读,组内从右边往左读。那么FFFF010000000000转换为2进制为111111111111111100000001,在此准换为:10000000 11111111 11111111,1代表extent为used,0代表为free,可以看到正好是17个extent。和如下查询一直。

SQL> select owner,segment_name,segment_type,file_id,extent_id,block_id,BLOCKS from dba_extents where segment_name='T';

OWNER                          SEGMENT_NAME                             SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID     BLOCKS
------------------------------ ---------------------------------------- ------------------ ---------- ---------- ---------- ----------
AMY                            T                                        TABLE                       5          0          8         20
AMY                            T                                        TABLE                       5          1         28         20
AMY                            T                                        TABLE                       5          2         48         20
AMY                            T                                        TABLE                       5          3         68         20
AMY                            T                                        TABLE                       5          4         88         20
AMY                            T                                        TABLE                       5          5        108         20
AMY                            T                                        TABLE                       5          6        128         20
AMY                            T                                        TABLE                       5          7        148         20
AMY                            T                                        TABLE                       5          8        168         20
AMY                            T                                        TABLE                       5          9        188         20
AMY                            T                                        TABLE                       5         10        208         20

OWNER                          SEGMENT_NAME                             SEGMENT_TYPE          FILE_ID  EXTENT_ID   BLOCK_ID     BLOCKS
------------------------------ ---------------------------------------- ------------------ ---------- ---------- ---------- ----------
AMY                            T                                        TABLE                       5         11        228         20
AMY                            T                                        TABLE                       5         12        248         20
AMY                            T                                        TABLE                       5         13        268         20
AMY                            T                                        TABLE                       5         14        288         20
AMY                            T                                        TABLE                       5         15        308         20
AMY                            T                                        TABLE                       5         16        328         20

17 rows selected.

这就是lmt管理方式。

总结一下: 对于表空间分配是以extent为最小单位,使用3-7位图块进行管理,对于表空间最小i/0单位是block,采用assm位图管理方式。

that's all

 
04-22 19:18