zoukankan      html  css  js  c++  java
  • 关于位图数据和标记位-P3

    1 背景

    对于LMT的表空间,dump真正的位图块后(比如3号块开始,2号是位图段头),竟然看到7,F值。
    引用作者的话,只看到0和1两个值做代表。

    位图块中每一个二进制位对应一个区是否被分配给某个表、索引等对象。如果第一个二进制位0说明表空间中第一个区未分配,如果为1说明已分配;第二个二进制位对应第二个区,以此类推。

    那么7,F又代表什么意思。另外,

    在Oracle 10g中,3~8号块是位图数据块,共6个位图块,大小是48K字节,每个字节8个二进制位,一共393216个二进制。每个二进制位对应一个区,一共就393216个区。如果是Oracle 11GR2,这个数字又要多出好多倍。

    按照这样的计算,每个位图数据块(默认8k算),可以对应8*1024*8=65536个区。但事实上,我在做实验发现只能对应63488个。

    关于标记位,Vage描述如下:

    Oracle如何在这30多万个二进制为中,确定哪个二进制位对应的区可以分配给表呢?
    Oracle用的方法其实很简单,在位图块中,找一个标记位,如果0 ~ 2号区被占用了,标记为的值为3;如果3 ~ 4号区又被占用了,标记为增加为5。假设此时2号区被释放了。标记为变为2。
    如果需要分配新的区,从这个标记为处开始查找即可。假设目前标记为值为5,有进程需要4个未分配区,Oracle就从5号区开始向下查找。

    1.1 问题

    1. 实际dump出来的内容中,存在7,B,F这类值,代表什么信息
    2. 实际位图数据块可以对应的区的个数
    3. 位图的标记位如何查看

    2 问题1探究

    实际不考虑删除分区的情况下,很容易发现,每个数字代表4个区,并且每分配一个区,前两个数字的值变化规律如下:

    区数量 对应值(16进制) 2进制(对应8个区)
    0 00 00000000
    1 01 00000001
    2 03 00000011
    3 07 00000111
    4 0F 00001111
    5 1F 00011111
    6 3F 00111111

    其中第3列中,0代表未被使用,1代表被使用。

    2.1 没有区的情况

    注意:如果使用alter system dump datafile 6 block 3;可能需要alter system flush buffer_cache;才能看到最新的信息。

    SYS@zkm1> drop tablespace tbs1 including contents and datafiles;
    
    Tablespace dropped.
    
    SYS@zkm1> create tablespace tbs1 datafile '+arch' size 1g autoextend on uniform size 40k;
    
    Tablespace created.
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_8394.trc
    
    SYS@zkm1> exec dbms_space_admin.tablespace_dump_bitmaps('TBS1');  --或者alter system dump datafile 6 block 3;
    
    PL/SQL procedure successfully completed.
    
    

    查看zkm1_ora_8394.trc文件,可以发现:

    Header Control:
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302
    Initial Area: 6, Tail: 131072, First: 0, Free: 26213
    Deallocation scn: 3.0
    Header Opcode:
    Save: No Pending Op
    File Space Bitmap Block:
    BitMap Control:
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 0, Free: 63488
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    …篇幅省略…
    0000000000000000 0000000000000000 0000000000000000 0000000000000000

    2.2 一个区的情况

    重新开启一个新的会话。

    SYS@zkm1> create table zkm.test as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> select EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    ---------- ---------- ---------- ---------- ----------
             0          6          8      40960          5
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_11456.trc
    
    SYS@zkm1> exec dbms_space_admin.tablespace_dump_bitmaps('TBS1');
    
    PL/SQL procedure successfully completed.
    
    

    查看zkm1_ora_11456.trc文件,可以发现:

    Header Control:
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302
    Initial Area: 6, Tail: 131072, First: 1, Free: 26212
    Deallocation scn: 3.0
    Header Opcode:
    Save: No Pending Op
    File Space Bitmap Block:
    BitMap Control:
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 1, Free: 63487
    0100000000000000 0000000000000000 0000000000000000 0000000000000000
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    …篇幅省略…
    0000000000000000 0000000000000000 0000000000000000 0000000000000000

    2.3 两个区的情况

    重新开启一个新的会话。

    SYS@zkm1> alter table zkm.test allocate extent (size 40k);
    
    Table altered.
    
    SYS@zkm1> select EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    ---------- ---------- ---------- ---------- ----------
             0          6          8      40960          5
             1          6         13      40960          5
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_12801.trc
    
    SYS@zkm1> exec dbms_space_admin.tablespace_dump_bitmaps('TBS1');
    
    PL/SQL procedure successfully completed.
    
    

    查看zkm1_ora_12801.trc文件,可以发现:

    Header Control:
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302
    Initial Area: 6, Tail: 131072, First: 2, Free: 26211
    Deallocation scn: 3.0
    Header Opcode:
    Save: No Pending Op
    File Space Bitmap Block:
    BitMap Control:
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 2, Free: 63486
    0300000000000000 0000000000000000 0000000000000000 0000000000000000
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    …篇幅省略…
    0000000000000000 0000000000000000 0000000000000000 0000000000000000

    2.4 三个区的情况

    重新开启一个新的会话。

    SYS@zkm1> alter table zkm.test allocate extent (size 40k);
    
    Table altered.
    
    SYS@zkm1> select EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    ---------- ---------- ---------- ---------- ----------
             0          6          8      40960          5
             1          6         13      40960          5
             2          6         18      40960          5
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_15908.trc
    
    SYS@zkm1> exec dbms_space_admin.tablespace_dump_bitmaps('TBS1');
    
    PL/SQL procedure successfully completed.
    
    

    查看zkm1_ora_15908.trc文件,可以发现:

    Header Control:
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302
    Initial Area: 6, Tail: 131072, First: 3, Free: 26210
    Deallocation scn: 3.0
    Header Opcode:
    Save: No Pending Op
    File Space Bitmap Block:
    BitMap Control:
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 3, Free: 63485
    0700000000000000 0000000000000000 0000000000000000 0000000000000000
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    …篇幅省略…
    0000000000000000 0000000000000000 0000000000000000 0000000000000000

    2.5 四个区的情况

    重新开启一个新的会话。

    SYS@zkm1> alter table zkm.test allocate extent (size 40k);
    
    Table altered.
    
    SYS@zkm1> select EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    ---------- ---------- ---------- ---------- ----------
             0          6          8      40960          5
             1          6         13      40960          5
             2          6         18      40960          5
             3          6         23      40960          5
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_15908.trc
    
    SYS@zkm1> exec dbms_space_admin.tablespace_dump_bitmaps('TBS1');
    
    PL/SQL procedure successfully completed.
    
    

    查看zkm1_ora_15908.trc文件,可以发现:

    Header Control:
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302
    Initial Area: 6, Tail: 131072, First: 4, Free: 26209
    Deallocation scn: 3.0
    Header Opcode:
    Save: No Pending Op
    File Space Bitmap Block:
    BitMap Control:
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 4, Free: 63484
    0F00000000000000 0000000000000000 0000000000000000 0000000000000000
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    …篇幅省略…
    0000000000000000 0000000000000000 0000000000000000 0000000000000000

    2.6 五个区的情况

    步骤雷同,略。

    3 问题2探究

    实际位图数据块可以对应的区的个数,以一个数据块为例子。
    按照Vage的说法,一个块对应65536个区,因为一个8k的块,共65536bit。
    实际上我们以2.1中zkm1_ora_8394.trc文件为例子的话结果只可以对应63488个区。

    Header Control: 
    RelFno: 6, Unit: 5, Size: 131072, Flag: 9 
    AutoExtend: YES, Increment: 12800, MaxSize: 4194302 
    Initial Area: 6, Tail: 131072, First: 0, Free: 26213 
    Deallocation scn: 3.0 
    Header Opcode: 
    Save: No Pending Op 
    File Space Bitmap Block: 
    BitMap Control: 
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 0, Free: 63488 
    0000000000000000 0000000000000000 0000000000000000 0000000000000000 
    ...省略了246...
    0000000000000000 0000000000000000 0000000000000000 0000000000000000
    

    加上首尾共248行,每行64个0,总共15872个0。
    其中,一个0可以对应4个区,总的对应63488个区,和“Free: 63488”是相符合的。

    3.1 模拟63488+1个区

    目的:模拟处63488个区,这样第一个位图块(文件6块号3)应该是全F的情况,在拓展多一个区就会用到4号块了。

    3.1.1 拓展分区

    可以看到,当前已经有6个区了。需要拓展多63482个区,共2539280k大小。

    SYS@zkm1> select EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    ---------- ---------- ---------- ---------- ----------
             0          6          8      40960          5
             1          6         13      40960          5
             2          6         18      40960          5
             3          6         23      40960          5
             4          6         28      40960          5
             5          6         33      40960          5
    
    6 rows selected.
    
    SYS@zkm1> alter table zkm.test allocate extent (size 2539280k);
    
    Table altered.
    
    SYS@zkm1> select count(*) from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
      COUNT(*)
    ----------
         63488
    

    3.1.2 dump 3,4号块

    SYS@zkm1> alter system flush buffer_cache;
    
    System altered.
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_67300.trc
    
    SYS@zkm1> alter system dump datafile 6 block min 3 block max 4;
    
    System altered.
    

    3.1.3 查看zkm1_ora_67300.trc内容

    ///////////以下是3号块的内容///////////
    ...省略部分内容...
    Block dump from disk:
    buffer tsn: 7 rdba: 0x01800003 (6/3)
    scn: 0x0000.001b87b5 seq: 0x0e flg: 0x04 tail: 0x87b51e0e
    frmt: 0x02 chkval: 0x4188 type: 0x1e=KTFB Bitmapped File Space Bitmap
    Hex dump of block: st=0, typ_found=1
    ...省略部分内容...
    File Space Bitmap Block: 
    BitMap Control: 
    RelFno: 6, BeginBlock: 8, Flag: 0, First: 63488, Free: 0 
    FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 
    ...省略部分内容...
    FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 
    ...省略部分内容...
    ///////////以下是4号块的内容///////////
    Block dump from cache:
    Dump of buffer cache at level 4 for tsn=7 rdba=25165828
    Block dump from disk:
    buffer tsn: 7 rdba: 0x01800004 (6/4)
    scn: 0x0000.001afbf4 seq: 0x01 flg: 0x04 tail: 0xfbf41e01
    frmt: 0x02 chkval: 0x998a type: 0x1e=KTFB Bitmapped File Space Bitmap
    Hex dump of block: st=0, typ_found=1
    ...省略部分内容...
    File Space Bitmap Block: 
    BitMap Control: 
    RelFno: 6, BeginBlock: 317448, Flag: 0, First: 0, Free: 63488 
    0000000000000000 0000000000000000 0000000000000000 0000000000000000 
    ...省略部分内容...
    0000000000000000 0000000000000000 0000000000000000 0000000000000000 
    ...省略部分内容...
    End dump data blocks tsn: 7 file#: 6 minblk 3 maxblk 4
    

    可以看到,3号块的Free已经是0了,表示3号块已经满了。从4号块的信息看,还未被使用。

    3.1.4 拓展第63489个区

    SYS@zkm1> alter table zkm.test allocate extent (size 40k);
    
    Table altered.
    
    SYS@zkm1> select count(*) from dba_extents where owner='ZKM' and SEGMENT_NAME='TEST';
    
      COUNT(*)
    ----------
         63489
        
    SYS@zkm1> alter system flush buffer_cache;
    
    System altered.
    
    SYS@zkm1> select value from v$diag_info where name like 'De%';
    
    VALUE
    --------------------------------------------------------------------------------
    /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_70162.trc
    
    SYS@zkm1> alter system dump datafile 6 block 4;
    
    System altered.
    
    SYS@zkm1> !cat /u01/app/oracle/diag/rdbms/zkm/zkm1/trace/zkm1_ora_70162.trc | more
    ...省略部分内容...
    File Space Bitmap Block: 
    BitMap Control: 
    RelFno: 6, BeginBlock: 317448, Flag: 0, First: 1, Free: 63487 
    0100000000000000 0000000000000000 0000000000000000 0000000000000000 
    ...省略部分内容...
    0000000000000000 0000000000000000 0000000000000000 0000000000000000 
    ...省略部分内容...
    

    已经符合规律。其实Vage的计算方法在11.2.0.4.0就错了,10g我没做实验去验证。

    目前没环境,先当做任务留着吧。

    • 10g验证一个位图数据块对应的区个数

    4 问题3探究

    删除并重新创建表空间,创建8张表,每个表一个区,可以做到随时回收某一个区。

    SYS@zkm1> drop tablespace tbs1 including contents and datafiles;
    
    Tablespace dropped.
    
    SYS@zkm1> create tablespace tbs1 datafile '+arch' size 1g autoextend on uniform size 40k;
    
    Tablespace created.
    
    SYS@zkm1> create table zkm.test1 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test2 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test3 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test4 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test5 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test6 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test7 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> create table zkm.test8 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> set linesize 500
    SYS@zkm1> col SEGMENT_NAME for a15
    SYS@zkm1> select SEGMENT_NAME,EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME like 'TEST%';
    
    SEGMENT_NAME     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    --------------- ---------- ---------- ---------- ---------- ----------
    TEST1                    0          6          8      40960          5
    TEST2                    0          6         13      40960          5
    TEST3                    0          6         18      40960          5
    TEST4                    0          6         23      40960          5
    TEST5                    0          6         28      40960          5
    TEST6                    0          6         33      40960          5
    TEST7                    0          6         38      40960          5
    TEST8                    0          6         43      40960          5
    
    8 rows selected.
    

    因为正好8个区,做dump后有:

    区数量 对应值(16进制) 2进制(对应8个区)
    8 FF 11111111

    删除TEST3表,继续做dump有:

    需要注意的是删除表时候要加purge,不然默认表进了回收站是看不到想要的结果的。

    区数量 对应值(16进制) 2进制(对应8个区)
    7 FB 11111011

    确实看到第3个区被标记为0了。

    添加test9表,看是否使用了第3个区:

    SYS@zkm1> create table zkm.test9 as select rownum id from dual where rownum=1;
    
    Table created.
    
    SYS@zkm1> select SEGMENT_NAME,EXTENT_ID,FILE_ID,BLOCK_ID,BYTES,BLOCKS from dba_extents where owner='ZKM' and SEGMENT_NAME like 'TEST%';
    
    SEGMENT_NAME     EXTENT_ID    FILE_ID   BLOCK_ID      BYTES     BLOCKS
    --------------- ---------- ---------- ---------- ---------- ----------
    TEST1                    0          6          8      40960          5
    TEST2                    0          6         13      40960          5
    TEST9                    0          6         18      40960          5
    TEST4                    0          6         23      40960          5
    TEST5                    0          6         28      40960          5
    TEST6                    0          6         33      40960          5
    TEST7                    0          6         38      40960          5
    TEST8                    0          6         43      40960          5
    
    8 rows selected.
    

    段TEST9的区第一个块的id为18,和之前的TEST3是一样的。看来是重用了。
    从dump结果看(省略),确实变为FF了。

    • 但是仍然不知道标记位怎么看。
  • 相关阅读:
    Silverlight学习(五)图形标绘
    Silverlight学习(四) domainservice动态多条件查询
    MySQL之单表查询
    mysql外键的三种关系
    mysql之完整性约束
    接口类和抽象类的区别
    mysql中的sql_mode
    html5本地存储技术 localstorage
    mysql数值类型
    mysql
  • 原文地址:https://www.cnblogs.com/PiscesCanon/p/12723501.html
Copyright © 2011-2022 走看看