• Oracle ITL(Interested Transaction List)理解


    ITL(Interested Transaction List)

        ITL是位于数据块头部的事物槽列表,它是由一系列的ITS(Interested Transaction Slot,事物槽)组成,其初始的ITL Slot数量由INITRANS决定的,如果有足够的剩余空间,oracle也会根据需要动态的分配这些slot,直到受到空间限制或者达到MAXTRANS,注意10g以后MAXTRANS被废弃,默认为255。

        ITL里的信息包括了xid,uba,flag,lck和scn/fsc,它是用来记录数据块上发生的事务相关信息,其中xid表示事物的id,uba表示对应到undo块上的地址,flag用来表示该条事务的状态,lck是块上的锁标记等。

          我们使用dump命令来认识一下itl里的内容:

    SQL> conn /as sysdba
    Connected.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    
    SQL> conn scott/tiger
    Connected.
    SQL> select rowid,dbms_rowid.rowid_relative_fno(rowid) fno,
      2  dbms_rowid.rowid_block_number(rowid) block_id,
      3  dbms_rowid.rowid_row_number(rowid) 
      4  from dept;
    
    ROWID                     FNO   BLOCK_ID DBMS_ROWID.ROWID_ROW_NUMBER(ROWID)
    ------------------ ---------- ---------- ----------------------------------
    AAAR3bAAEAAAACHAAA          4        135                                  0
    AAAR3bAAEAAAACHAAB          4        135                                  1
    AAAR3bAAEAAAACHAAC          4        135                                  2
    AAAR3bAAEAAAACHAAD          4        135                                  3
    
    
    SQL> update dept set dname='development' where deptno=10;
    
    1 row updated.      --注意未提交

    --另开一个会话

    [oracle@std ~]$ sqlplus scott/tiger
    
    SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 16 15:24:12 2015
    
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    
    
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    
    SQL> update dept set dname='AAAAA' where deptno=40;
    
    1 row updated.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> conn /as sysdba
    Connected.
    
    SQL> alter system dump datafile 4 block 135;
    
    System altered.
    
    SQL> oradebug setmypid
    Statement processed.
    SQL> oradebug tracefile_name
    /u02/app/diag/rdbms/orcl/ORCL/trace/ORCL_ora_7978.trc

    查看一下dump出来的内容:

    more /u02/app/diag/rdbms/orcl/ORCL/trace/ORCL_ora_7978.trc
    ......
    Block header dump:  0x01000087
     Object id on Block? Y
     seg/obj: 0x11ddb  csc: 0x00.105858  itc: 2  flg: E  typ: 1 - DATA
         brn: 0  bdba: 0x1000080 ver: 0x01 opc: 0
         inc: 0  exflg: 0
     
     Itl           Xid                  Uba         Flag  Lck        Scn/Fsc
    0x01   0x0001.010.00000198  0x00c15aac.0061.36  C---    0  scn 0x0000.000b6f31
    0x02   0x0000.000.00000000  0x00000000.0000.00  ----    0  fsc 0x0000.00000000
    bdba: 0x01000087
    data_block_dump,data header at 0xcac664

        

    可以看到dump出来的内容包括了事务id,对应的undo地址,事务的状态,锁信息等,通过这些信息就可以标识当前数据块的DML情况。

    理解flg标识位含义:

    ---- = transaction is active, or committed pending cleanout
    C--- = transaction has been committed and locks cleaned out
    -B-- = this undo record contains the undo for this ITL entry
    --U- = transaction committed (maybe long ago); SCN is an upper bound
    ---T = transaction was still active at block cleanout SCN

    ------ITL在ORACLE中的使用

            当发出一条sql语句时,ORACLE会记录下这个时刻(SCN),然后在buffer cache中查找需要的BLOCK,或者从磁盘上读。当别的会话修改了数据,或者正在修改数据,就会在相应的block上记录ITL,此时ORACLE发现ITL中记录的SCN(Scn/Fsc)大于SELECT时刻的SCN,那么ORACLE就会根据ITL中的Uba找到UNDO信息获得该block的前镜像,然后在buffer cache 中构造出CR(consistent read)块,此时ORALCE也会检查构造出来的BLOCK中ITL记录的SCN(Scn/Fsc),如果SCN(Scn/Fsc)还大于select时刻的SCN,那么一直重复构造前镜像,然后ORACLE找到前镜像BLOCK中的ITL的SCN是否小于select的SCN,同时检查这个事物有没有提交或者回滚,如果没有,那么继续构造前镜像,直到找到需要的BLOCK,如果在构造前镜像的过程中所需的UNDO信息被覆盖了,就会报ORA-01555快照过旧的错误。

    参考:http://wenku.baidu.com/link?url=Pp9XTyF_4rYzhdNOeewFhmp_YAoVS1Pq8FJYvOy1_DS10DWIWreYDSLDpGwLhibjFO6SYGunPcvZ_aTP1P5fZzFCbw0m7qwXCT4EMYMSBpK

  • 相关阅读:
    Lightoj 1023
    Tju 4119. HDFS
    Lightoj 1020
    Lightoj 1019
    小奇挖矿 2(4和7)
    [AHOI2012]树屋阶梯
    漂亮字串
    Prison 监狱
    2-XOR-SAT
    牛宫
  • 原文地址:https://www.cnblogs.com/myrunning/p/4885451.html
Copyright © 2020-2023  润新知