当前位置:数据库 > Oracle >>

Oracle Block scn/commit scn/cleanout scn说明

Oracle Block scn/commit scn/cleanout scn说明
 
一. 说明
       Block的cache header部分,记录着一个block scn,它是当前块最后一次变更的时间戳,确切说,这个更新并不是指itl上的scn的最新更新,在接下来delayed block cleanout下的slot重用情况下,可以看到blockscn并不等于itl上的最后一次更新的scn。可以通过dump获得block scn/last itl scn 和发布ora_rowscn语句获得last itl scn。
 
       Eachdata block in a datafile contains an SCN, which is the SCN at which the lastchange was made to the block. During an incremental backup, RMAN reads the SCNof each data block in the input file and compares it to the checkpoint SCN ofthe parent incremental backup. RMAN reads the entire file every time whether ornot the blocks have been used.
 
       发布transaction后,未提交之前,block scn是不会改变的,对应的itl中也并不做scn记录。Block scn的改变,确切的说不是在发布commit之时(因为有delayed block cleanout的情况存在),而是在transaction对应的itl获得commit scn之时。
 
       cleanout分为2钟,一种是fast commit cleanout,另一种是delayed block cleanout.
       oracle有一个modified block list结构,用来记录每个transaction更改过的block,每个transaction大约可以记录10% buffer cache这多的modified block。这部分block就是当发生commit的时候,oracle可以根据modified block list定位到那些块并做fast commit cleanout。如果一个transaction修改的块超过10% buffer cache,那么超过的块就执行delayed block cleanout。
       当做fast commit cleanout时,oracle不会清理 Row locks lb标志位,ITL lck标志位。
       另一种情况是delayed block cleanout,当transaction还未commit或rollback时modified block已经被写回磁盘,当发生commit时oracle并不会把block重新读入做cleanout,这样成本太高,而是把cleanout留到下一次对此块的dml时来完成。当delayed cleanout时候如果undo segment header的transaction table slot还没有被覆盖,那么可以找回该事务递交的exact scn,如果slot已经被覆盖,那么将会使用undo segment header中的control scn来做为upper bound scn。
 
       当发生fast commit cleanout,系统将transaction提交时刻的scn作为commit scn,更新block上 itl和undo segment header的Transaction table的slot上的 scn,并修改block scn,三者是一致的。
       发生delayed block cleanout的时候,之前的transaction commit更新的只是Transaction table,而并未做block上的处理,等待下次使用此block的时候,更新block scn和itl状态。block scn和itl的更新又分2种情况:
       (1)当不产生slot重用的时候(ITL不重用), delayed block cleanout时,根据Transaction table里面的信息,更新block scn和itl上的Scn/Fsc为transaction曾经提交时候的scn。
       (2)当产生slot重用的时候(重用ITL),更新对应itl上scn为control scn,而block scn 为delayed block cleanout发生时刻的scn。
 
说明:ITL 中SCN 和 FSC 的区别
dump block的ITL 的信息如下:
Itl Xid Uba Flag Lck Scn/Fsc
0x01 0x000e.007.00000236 0x00000000.0000.00C-U- 0 scn 0x0000.005b1f7f
0x02 0x000c.005.000003b4 0x01401727.0144.13C--- 0 scn 0x0000.005bbf0b
0x03 0x0011.007.00000406 0x0140015b.00c7.57--U- 483 fsc 0x0000.005bdee1
 
       这里的SCN和FSC其实就是这个ITL对应的事务提交时候的SCN,那么这里所有槽位上的最大的一个SCN号就表示这个BLOCK最后被更新的时候的SCN。每一个事务对应一个itl 记录。如果该事务没有涉及延时块清除,那么显示的FSC。 如果是延时块清除(delayed block cleanout),那么显示的就是SCN。
 
       在ITL信息中有一个显示的Flag的状态,FLAG在block中占用1个字节大小。 不同flag 标记的意义如下:
---- = transaction is active, or committedpending cleanout
C--- = transaction has been committed andlocks cleaned out
-B-- = this undo record contains the undofor this ITL entry
--U- = transaction committed (maybe longago); SCN is an upper bound
---T = transaction was still active atblock cleanout SCN
 
 
二. 测试
2.1 fast commit cleanout
SYS@anqing2(rac2)> create table fcc(idnumber);
Table created.
SYS@anqing2(rac2)> insert into fccvalues(1);
1 row created.
SYS@anqing2(rac2)> insert into fccvalues(2);
1 row created.
SYS@anqing2(rac2)> commit;
Commit complete.
SYS@anqing2(rac2)> selectdbms_rowid.rowid_block_number(rowid),ora_rowscn from fcc;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)ORA_ROWSCN
----------------------------------------------
                              305906    7262675
                              305906    7262675
 
--刚才插入的2条记录都存放在block305906里,并且ora_rowscn也一样。
 
对fcc 表进行update:
SYS@anqing2(rac2)> update fcc set id=3where id=1;
1 row updated.
SYS@anqing2(rac2)> update fcc set id=4where id=2;
1 row updated.
SYS@anqing2(rac2)> selectdbms_rowid.rowid_block_number(rowid),ora_rowscn from fcc;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)ORA_ROWSCN
----------------------------------------------
                              305906    7262675
                              305906    7262675
--ora_rowscn 没有变化
 
SYS@anqing2(rac2)> commit;
Commit complete.
SYS@anqing2(rac2)> selectdbms_rowid.rowid_block_number(rowid),ora_rowscn from fcc;
DBMS_ROWID.ROWID_BLOCK_NUMBER(ROWID)ORA_ROWSCN
----------------------------------------------
                              305906    7262794
                             305906    7262794
--ora_rowscn 已经改变,这个在ora_rowscn 那篇blog里有说明,这个ora_rowscn是从block header SCN 里读取的。
 
  
2.2 delayed block cleanout
--.创建一个小undo表空间.
SYS@dave2(db2)> create undo tablespaceundotbs2 datafile '/u01/app/oracle/oradata/dave2/undotbs02.dbf' size 1M;
Tablespace created.
SYS@dave2(db2)> alter system setundo_tablespace='undotbs2';
System altered.
 
--创建测试表并insertdata
SYS@dave2(db2)> create table dbc(idnumber);
Table created.
SYS@dave2(db2)> insert into dbcvalues(1);
1 row created.
SYS@dave2(db2)> insert into dbc values(2);
1 row created.
SYS@dave2(db2)> commit;
Commit complete.
SYS@dave2(db2)> selectdbms_rowid.rowid_block_number(rowid) block,dbms_rowid.rowid_relative_fno(rowid) fileno, ora_rowscn from dbc;
 
BLOCK    FILENO ORA_ROWSCN
---------- ---------- ----------
   115346          1      2147768913
   115346          1              2147768913
 
--update table
SYS@da
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,