Oracle(block clean out)的块清除
Clean out有2种: fast commit cleanout,delayed block cleanout
1.如果一个事务(transaction)修改不超过10%buffer cache的数据块时,oracle做的是fast commit leanout。
2.如果一个事务(transaction)修改的块超过10% buffer cache,那么超过的块"就执行delayed block leanout,
3.在事务commit前,修改的数据块已经写入硬盘,当发生commit时,oracle并不会把block重新读入内存来做cleanout,这样成本太高.而是把cleanout留到下一次对此块的访问(select,update)时完成。

SQL> show parameter db_cache;
  NAME TYPE VALUE
  ------------------------------------ ----------- ------------------------------
  db_cache_size big integer 58720256
--只需更改50M/10=5M的数据量就会触发DELAY CLEAN OUT
SQL> create table t2 (id int ,col1 char(2000),col2 char(2000),col3 char(2000),col4 char(1000));   
  表已创建。
      --1行一个块,
SQL> insert into t2 select object_id,object_name,'1','1','1' from all_objects where rownum <=1000;
  已创建1000行。
SQL> commit;
SQL> select * from (
         select rownum rn, id,dbms_rowid.rowid_relative_fno(rowid) "file#",dbms_rowid.rowid_block_number(rowid) "block#" from t2 )
  3 where rn=1 or rn=1000;
  RN ID file# block#
  ---------- ---------- ---------- ----------
  1 7559 8 36
  1000 14700 8 1160
--fast clean out 快速块清除
SQL> update t2 set id=id,col1=col1,col2='c',col3='c',col4='c' where id='7559'; --第36块
  1 ROWS UPDATED
SQL> select xidusn,xidslot,xidsqn,ubafil,ubablk,ubarec from v$transaction;
  XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK UBAREC
  -------- ---------- ---------- ---------- ---------- ----------
  10 22 339 2 41167 11
SQL> COMMIT;
  提交成功 
SQL> alter system dump datafile 8 block 36;
  系统已更改。
Start dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36
  buffer tsn: 8 rdba: 0x02000024 (8/36)
  scn: 0x0000.000b21db seq: 0x01 flg: 0x00 tail: 0x21db0601
  frmt: 0x02 chkval: 0x0000 type: 0x06=trans data
  Block header dump: 0x02000024
  Object id on Block? Y
  seg/obj: 0x739d csc: 0x00.b21db itc: 2 flg: E typ: 1 - DATA
  brn: 0 bdba: 0x2000021 ver: 0x01
  inc: 0 exflg: 0
  Itl Xid Uba Flag Lck Scn/Fsc
  0x01 0x000a.02b.00000152 0x0080a0c5.002a.2a C--- 0 scn 0x0000.000b218f
  0x02 0x000a.016.00000153 0x0080a0cf.002a.0b ---- 1 fsc 0x0000.00000000
    ----这里的FLAG已经清除
--delay clean out 延时块清除
SQL> update t2 set id=id,col1=col1,col2='c',col3='c',col4='c'; --8M的更新数据
  已更新1000行。
SQL> select xidusn,xidslot,xidsqn,ubafil,ubablk,ubarec from v$transaction;
  XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK UBAREC
  ---------- ---------- ---------- ---------- ---------- ----------
  3 8 470 2 6788 1
SQL> COMMIT;
SQL> alter system dump datafile 8 block 36; --大于db_cache_size 10%的块
  系统已更改。
SQL> alter system dump datafile 8 block 1160; --小于db_cache_size 10%的块
  系统已更改。
 Start dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36
  buffer tsn: 8 rdba: 0x02000024 (8/36)
  scn: 0x0000.000b2b52 seq: 0x01 flg: 0x02 tail: 0x2b520601
  frmt: 0x02 chkval: 0x0000 type: 0x06=trans data
  Block header dump: 0x02000024
  Object id on Block? Y
  seg/obj: 0x739d csc: 0x00.b21db itc: 2 flg: E typ: 1 - DATA
  brn: 0 bdba: 0x2000021 ver: 0x01
  inc: 0 exflg: 0
  Itl Xid Uba Flag Lck Scn/Fsc
  0x01 0x000a.02b.00000152 0x0080a0c5.002a.2a C--- 0 scn 0x0000.000b218f
  0x02 0x0003.008.000001d6 0x0080129d.0043.01 --U- 1 fsc 0x0000.000b2b52
  |
  |
----大于10%的块未被清除
 Start dump data blocks tsn: 8 file#: 8 minblk 1160 maxblk 1160
  buffer tsn: 8 rdba: 0x02000488 (8/1160)
  scn: 0x0000.000b2b5d seq: 0x01 flg: 0x00 tail: 0x2b5d0601
  frmt: 0x02 chkval: 0x0000 type: 0x06=trans data
  Block header dump: 0x02000488
  Object id on Block? Y
  seg/obj: 0x739d csc: 0x00.b2b5d itc: 2 flg: E typ: 1 - DATA
  brn: 0 bdba: 0x200040a ver: 0x01
  inc: 0 exflg: 0
  Itl Xid Uba Flag Lck Scn/Fsc
  0x01 0x000a.02b.00000152 0x0080a0ce.002a.6a C--- 0 scn 0x0000.000b218f
  0x02 0x0003.008.000001d6 0x00801a84.004a.01 C--- 0 scn 0x0000.000b2b52
  |
  |
  ----小于10%的块被清除
--再次访问这些块时,会被清除 
SQL> set autot on
SQL> select count(*) from t2;
  COUNT(*)
  ----------
  1000
  Execution Plan
  ----------------------------------------------------------
  0 SELECT STATEMENT Optimizer=CHOOSE
  1 0 SORT (AGGREGATE)
  2 1 TABLE ACCESS (FULL) OF 'T2'
  Statistics
  ----------------------------------------------------------
  0 recursive calls
  0 db block gets
  1265 consistent gets
  0 physical reads
  15600 redo size
--产生很多的REDO信息,用于块清除
 376 bytes sent via SQL*Net to client
  503 bytes received via SQL*Net from client
  2 SQL*Net roundtrips to/from client
  0 sorts (memory)
  0 sorts (disk)
  1 rows processed
  SQL> /
  COUNT(*)
  ----------
  1000
  Execution Plan
  ----------------------------------------------------------
  0 SELECT STATEMENT Optimizer=CHOOSE
  1 0 SORT (AGGREGATE)
  2 1 TABLE ACCESS (FULL) OF 'T2'
  Statistics
  ----------------------------------------------------------
  0 recursive calls
  0 db block gets
  1005 consistent gets
  0 physical reads
  0 redo size
     --再访问就没有REDO了
 376 bytes sent via SQL*Net to client
  503 bytes received via SQL*Net from client
  2 SQL*Net roundtrips to/from client
  0 sorts (memory)
  0 sorts (disk)
  1 rows processed
  --再来看清除的数据块信息 
SQL> alter system dump datafile 8 block 36;
  系统已更改。  
SQL> alter system dump datafile 8 block 1160;
  系统已更改。  


Start dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36
  buffer tsn: 8 rdba: 0x02000024 (8/36)
  scn: 0x0000.000b3059 seq: 0x01 flg: 0x02 tail: 0x30590601
  frmt: 0x02 chkval: 0x0000 type: 0x06=trans data
  Block header dump: 0x02000024
  Object id on Block? Y
  seg/obj: 0x739d csc: 0x00.b2c2a itc: 2 flg: E typ: 1 - DATA
  brn: 0 bdba: 0x2000021 ver: 0x01
  inc: 0 exflg: 0
  Itl Xid Uba Flag Lck Scn/Fsc
  0x01 0x0008.000.000001d7 0x00800761.003e.01 C--- 1 fsc 0x0000.000b3059
  0x02 0x0003.008.000001d6 0x0080129d.0043.01 C--- 0 scn 0x0000.000b2b52
  |
  |
  ----大于10%的块也被清除成功 
  Start dump data blocks tsn: 8 file#: 8 minblk 1160 maxblk 1160
  buffer tsn: 8 rdba: 0x02000488 (8/1160)
  scn: 0x0000.000b305a seq: 0x01 flg: 0x00 tail: 0x305a0601
  frmt: 0x02 chkval: 0x0000 type: 0x06=trans data
  Block header dump: 0x02000488
  Object id on Block? Y
  seg/obj: 0x739d csc: 0x00.b305a itc: 2 flg: E typ: 1 - DATA
  brn: 0 bdba: 0x200040a ver: 0x01
  inc: 0 exflg: 0
  Itl Xid Uba Flag Lck Scn/Fsc
  0x01 0x0008.000.000001d7 0x00801ec8.0046.01 C--- 0 scn 0x0000.000b3059
  0x02 0x0003.008.000001d6 0x00801a84.004a.01 C--- 0 scn 0x0000.000b2b52
  |
  |
----小于10%的块不变 

参考至:http://blog.sina.com.cn/s/blog_7414f6640100thhf.html

如有错误,欢迎指正