您的位置:首页 > 其它

commit之后undo和data block 做了什么?

2013-08-19 00:12 197 查看
  commit之后undo和data block 做了什么?
 今天是2013-08-18,从今天我能够上网这一刻开始,我的生活算是真正的进入了状态。不知道何时,我喜欢上了oracle,刚刚开始就像品茶一样那样苦涩,但是

慢慢的感觉味道还是蛮不错的。现在我一边跟着前辈的步伐一步一步的往前赶着,期待我能从“掉队”中,到融入大家的队伍一起前进。生命不息,奋斗不止。

   好了,不扯了。现在开始看一下oracle在commit的时候,undo和 数据块都做了哪些改变。

在undo_镜像块探究(一)中,我学习到了在undo header中存储的事务表信息,在record中存储的前镜像信息,在 数据块 中存在着itl信息。那么undo是 一个循

环使用的,当 事务结束之后,势必要记录 redo,以便此时该事务已经完成修改,同时在数据块中的itl需要清除锁信息,以便可以被其他事务进行修改该数据块,

这就是块清除。对于块清除分为两种,一种为快速块清除,另一种叫做延迟块清除。快速块清除就是修改的数据块仍然在buffer cache中被修改并进行了提交,

oracle会完成块清除,当块的数量占据了buffer cache的10%的时候,那么超出部分讲进行延迟块清除。延迟块清除就是,修改的数据已经被写入到了数据文件中。

将在下一次访问的时候进行块清除操作。

现在开始研究一下延迟块清除内容:

eg:

SQL> col name for a50     

SQL> select obj#,name from t where rownum<5;

      OBJ# NAME

---------- --------------------------------------------------

        46 I_USER1

        28 Rhys1

        15 RHYS20

        29 RHYS3

SQL> update t set name='rhys1' where obj#=46;

1 row updated.

SQL> update t set name='rhys2' where obj#=28;

1 row updated.

SQL> update t set name='rhys3' where obj#=15;

1 row updated.

SQL> update t set name='rhys4' where obj#=29;

1 row updated.

SQL> alter system set events 'immediate trace name flush_cache';

System altered.

SQL> commit;

Commit complete.

SQL> select * from v$transaction;

no rows selected

isconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

1)首先看一下这时的undo header 信息,转储过程和信息 如下:

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 18 23:08:44 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> set linesize 200

SQL> alter system dump undo  header '_SYSSMU12_584745277$';

System altered.

SQL> select * from v$diag_info where name like 'Default Trace File';

   INST_ID NAME

---------- ----------------------------------------------------------------

VALUE

-----------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------

         1 Default Trace File

/opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_9458.trc

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

摘录转储信息:

  TRN TBL::

 

  index  state cflags  wrap#    uel         scn            dba            parent-xid    nub     stmt_num    cmt

  ------------------------------------------------------------------------------------------------

   0x00    9    0x00  0x0059  0x0016  0x0000.009b9292  0x020005d3  0x0000.000.00000000  0x00000001   0x00000000  1376806203

   0x01    9    0x00  0x005a  0x0007  0x0000.009b94e5  0x020005d5  0x0000.000.00000000  0x00000001   0x00000000  1376806887

   0x02    9    0x00  0x005a  0x000a  0x0000.009b9461  0x020005d5  0x0000.000.00000000  0x00000001   0x00000000  1376806707

   0x03    9    0x00  0x0059  0x0017  0x0000.009b930e  0x020005d3  0x0000.000.00000000  0x00000001   0x00000000  1376806203

   0x04    9    0x00  0x0059  0x0005  0x0000.009b92cf  0x020005d3  0x0000.000.00000000  0x00000001   0x00000000  1376806203

   0x05    9    0x00  0x0059  0x0008  0x0000.009b92d8  0x020005d3  0x0000.000.00000000  0x00000001   0x00000000  1376806203

   0x06    9    0x00  0x0059  0x0009  0x0000.009b92aa  0x020005d3  0x0000.000.00000000  0x00000001   0x00000000  1376806203

   0x07    9    0x00  0x005a  0xffff  0x0000.009c149e  0x020005d5  0x0000.000.00000000  0x00000001   0x00000000  1376838457

可以看到事务表中的07槽位状态已经为inactive了。也就是该事务已经完成了。

然后我在看一下undo 这个数据块的信息。

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 18 23:10:05 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> alter system dump datafile 8 block 1493;

System altered.

SQL> set linesize 200

SQL> col name for a40

SQL> col value for a80

SQL> select * from v$diag_info where name like 'Default Trace File';

   INST_ID NAME                                     VALUE

---------- ---------------------------------------- --------------------------------------------------------------------------------

         1 Default Trace File                       /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_9471.trc

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

摘录信息如下:

没有commit之前

UNDO BLK: 

xid: 0x000c.007.0000005a  seq: 0x33a cnt: 0x27  irb: 0x27  icl: 0x0   flg: 0x0000

 

 Rec Offset      Rec Offset      Rec Offset      Rec Offset      Rec Offset

---------------------------------------------------------------------------

0x01 0x1f4c     0x02 0x1ec4     0x03 0x1db0     0x04 0x1d3c     0x05 0x1cb8    

0x06 0x1c4c     0x07 0x1be8     0x08 0x1b94     0x09 0x1aec     0x0a 0x1a4c    

0x0b 0x19ac     0x0c 0x1900     0x0d 0x1854     0x0e 0x17ac     0x0f 0x171c    

0x10 0x167c     0x11 0x15d4     0x12 0x1544     0x13 0x14a4     0x14 0x13f8    

0x15 0x139c     0x16 0x1328     0x17 0x128c     0x18 0x117c     0x19 0x1114    

0x1a 0x10bc     0x1b 0x1068     0x1c 0x100c     0x1d 0x0f98     0x1e 0x0f3c    

0x1f 0x0ee8     0x20 0x0e60     0x21 0x0dd4     0x22 0x0d6c     0x23 0x0cd0    

0x24 0x0c2c     0x25 0x0bb0     0x26 0x0b50     0x27 0x0ad4  

commit之后如下:

 

UNDO BLK:

xid: 0x000c.021.00000059  seq: 0x33a cnt: 0x3b  irb: 0x3b  icl: 0x0   flg: 0x0000

 Rec Offset      Rec Offset      Rec Offset      Rec Offset      Rec Offset

---------------------------------------------------------------------------

0x01 0x1f4c     0x02 0x1ec4     0x03 0x1db0     0x04 0x1d3c     0x05 0x1cb8

0x06 0x1c4c     0x07 0x1be8     0x08 0x1b94     0x09 0x1aec     0x0a 0x1a4c

0x0b 0x19ac     0x0c 0x1900     0x0d 0x1854     0x0e 0x17ac     0x0f 0x171c

0x10 0x167c     0x11 0x15d4     0x12 0x1544     0x13 0x14a4     0x14 0x13f8

0x15 0x139c     0x16 0x1328     0x17 0x128c     0x18 0x117c     0x19 0x1114

0x1a 0x10bc     0x1b 0x1068     0x1c 0x100c     0x1d 0x0f98     0x1e 0x0f3c

0x1f 0x0ee8     0x20 0x0e60     0x21 0x0dd4     0x22 0x0d6c     0x23 0x0cd0

0x24 0x0c2c     0x25 0x0bb0     0x26 0x0b50     0x27 0x0ad4     0x28 0x0a38

0x29 0x09b0     0x2a 0x0898     0x2b 0x0824     0x2c 0x07a0     0x2d 0x0734

0x2e 0x06d0     0x2f 0x067c     0x30 0x05f8     0x31 0x057c     0x32 0x0500

0x33 0x0478     0x34 0x040c     0x35 0x0388     0x36 0x031c     0x37 0x02a0

0x38 0x022c     0x39 0x01c0     0x3a 0x0144     0x3b 0x00c0

可以看到record增加了不少,但是还是保留之前的数据信息。

然后再看一下数据块的信息

[oracle@oracle-one ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 18 23:11:05 2013

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> set linesize 200

SQL> alter system dump datafile 1 block 124916;

System altered.

SQL> col name for a40

SQL> col value for a80

SQL> select * from v$diag_info where name like 'Default Trace File';

   INST_ID NAME                                     VALUE

---------- ---------------------------------------- --------------------------------------------------------------------------------

         1 Default Trace File                       /opt/app/oracle/diag/rdbms/rhys/RHYS/trace/RHYS_ora_9480.trc

SQL> 

转储信息如下:

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc

0x01   0x000c.007.0000005a  0x020005d5.033a.27  ----    4  fsc 0x0003.00000000

0x02   0x0014.001.00000044  0x02000628.037b.06  C---    0  scn 0x0000.009b94a8

bdba: 0x0041e7f4

data_block_dump,data header at 0x7f9937628a5c

可以看到还存在itl信息。

这就是delayed block cleanout;

然后,我读取该表,看一下。

eg:

Block header dump:  0x0041e7f4

 Object id on Block? Y

 seg/obj: 0x11e0d  csc: 0x00.9c3ca7  itc: 2  flg: O  typ: 1 - DATA

     fsl: 0  fnx: 0x41e7f3 ver: 0x01

 

 Itl           Xid                  Uba         Flag  Lck        Scn/Fsc

0x01   0x000c.007.0000005a  0x020005d5.033a.27  C---    0  scn 0x0000.009c149e

0x02   0x0014.009.0000005f  0x02000670.037f.0d  C---    0  scn 0x0000.009c3c2d

bdba: 0x0041e7f4

data_block_dump,data header at 0x7fc2a4f26a5c

哈哈。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: