ITPub博客

首页 > 数据库 > Oracle > Oracle (block clean out) oracle的块清除

Oracle (block clean out) oracle的块清除

原创 Oracle 作者:Steven1981 时间:2008-08-07 12:12:02 0 删除 编辑
Clean out有2种: fast commit cleanout
delayed block cleanout
[@more@]
1,如果一个事务(transaction)修改不超过10%buffer cache的数据块时,oracle做的是fast commit cleanout。
2,如果一个事务(transaction)修改的块超过10% buffer cache,那么"超过的块"就执行delayed block cleanout,
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 (
2 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已经清除
data_block_dump,data header at 0x3171064
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x03171064
bdba: 0x02000024
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x42d
avsp=0x419
tosp=0x419
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x42d
block_row_dump:
tab 0, row 0, @0x42d
tl: 7019 fb: --H-FL-- lb: 0x2 cc: 5
col 0: [ 3] c2 4c 3c
col 1: [2000]
2f 31 30 30 37 36 62 32 33 5f 4f 72 61 43 75 73 74 6f 6d 44 61 74 75 6d 43
6c 6f 73 75 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20

... ... 数据内容部分省略

20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 2: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 3: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 4: [1000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump
End dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36

--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%的块未被清除
data_block_dump,data header at 0x3321064
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x03321064
bdba: 0x02000024
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x42d
avsp=0x419
tosp=0x419
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x42d
block_row_dump:
tab 0, row 0, @0x42d
tl: 7019 fb: --H-FL-- lb: 0x2 cc: 5
col 0: [ 3] c2 4c 3c
col 1: [2000]
2f 31 30 30 37 36 62 32 33 5f 4f 72 61 43 75 73 74 6f 6d 44 61 74 75 6d 43
6c 6f 73 75 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 2: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 3: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
,,, ,,,
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 4: [1000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump

End dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36



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%的块被清除

data_block_dump,data header at 0x3321064
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x03321064
bdba: 0x02000488
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x42d
avsp=0x419
tosp=0x419
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x42d
block_row_dump:
tab 0, row 0, @0x42d
tl: 7019 fb: --H-FL-- lb: 0x0 cc: 5
col 0: [ 3] c3 02 30
col 1: [2000]
2f 33 39 32 39 37 38 38 39 5f 42 79 74 65 43 6f 6d 70 6f 6e 65 6e 74 52 61
73 74 65 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 2: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 3: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 4: [1000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump
End dump data blocks tsn: 8 file#: 8 minblk 1160 maxblk 1160


--再次访问这些块时,会被清除


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%的块也被清除成功
data_block_dump,data header at 0x3321064
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x03321064
bdba: 0x02000024
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x42d
avsp=0x419
tosp=0x419
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x42d
block_row_dump:
tab 0, row 0, @0x42d
tl: 7019 fb: --H-FL-- lb: 0x0 cc: 5
col 0: [ 3] c2 4c 3c
col 1: [2000]
2f 31 30 30 37 36 62 32 33 5f 4f 72 61 43 75 73 74 6f 6d 44 61 74 75 6d 43
6c 6f 73 75 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 2: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 3: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 4: [1000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump
End dump data blocks tsn: 8 file#: 8 minblk 36 maxblk 36

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%的块不变

data_block_dump,data header at 0x3321064
===============
tsiz: 0x1f98
hsiz: 0x14
pbl: 0x03321064
bdba: 0x02000488
76543210
flag=--------
ntab=1
nrow=1
frre=-1
fsbo=0x14
fseo=0x42d
avsp=0x419
tosp=0x419
0xe:pti[0] nrow=1 offs=0
0x12:pri[0] offs=0x42d
block_row_dump:
tab 0, row 0, @0x42d
tl: 7019 fb: --H-FL-- lb: 0x0 cc: 5
col 0: [ 3] c3 02 30
col 1: [2000]
2f 33 39 32 39 37 38 38 39 5f 42 79 74 65 43 6f 6d 70 6f 6e 65 6e 74 52 61
73 74 65 72 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 2: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 3: [2000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
col 4: [1000]
63 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
... ...
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
end_of_block_dump
End dump data blocks tsn: 8 file#: 8 minblk 1160 maxblk 1160

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/703656/viewspace-1008650/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: SELECT也需要COMMIT
请登录后发表评论 登录
全部评论
  • 博文量
    127
  • 访问量
    855003