Chinaunix首页 | 论坛 | 博客
  • 博客访问: 96242
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 202
  • 用 户 组: 普通用户
  • 注册时间: 2013-09-07 01:56
个人简介

数据库技术爱好者

文章分类

全部博文(20)

文章存档

2016年(11)

2015年(9)

我的朋友

分类: Oracle

2016-06-26 23:52:01


点击(此处)折叠或打开

  1. 一、分析undo segment header bock的结构
  2. ##dump undo段头块
  3. SQL> alter system dump undo header '_SYSSMU7_3286610060$';

  4. System altered.

  5. SQL> select * from v$diag_info;
  6. SQL> select * from v$diag_info where name='Default Trace File';

  7.    INST_ID NAME VALUE
  8. ---------- -------------------- ----------------------------------------------------------------------------------------------------
  9.          1 Default Trace File /u01/oracle/diag/rdbms/edus/edus/trace/edus_ora_5131.trc
  10.         
  11.  index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
  12.   ------------------------------------------------------------------------------------------------
  13.    0x00 9 0x00 0x6eef 0x0007 0x0000.04f8de47 0x00c03dc2 0x0000.000.00000000 0x00000003 0x00000000 1467124072
  14.    0x01 9 0x00 0x6efb 0x001c 0x0000.04f8dcd4 0x00c03daf 0x0000.000.00000000 0x00000003 0x00000000 1467123537
  15.    0x02 9 0x00 0x6ef7 0x001a 0x0000.04f8de59 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 1467124073
  16.    0x03 9 0x00 0x6ef0 0x0018 0x0000.04f8de68 0x00c03dcf 0x0000.000.00000000 0x00000003 0x00000000 1467124073
  17.    0x04 9 0x00 0x6f05 0x0020 0x0000.04f8de71 0x00c03dd3 0x0000.000.00000000 0x00000003 0x00000000 1467124073
  18. // 0x05 10 0x80 0x6f03 0x0023 0x0000.04f8d0de 0x00c03dd3 0x0000.000.00000000 0x00000001 0x00000000 0
  19. #猜测state=9,表示已经事务,state=10表示事务未提交
  20. SQL> select to_number('3dd3','XXXXXXXXXXXXX') from dual;

  21. TO_NUMBER('3DD3','XXXXXXXXXXXXX')
  22. ---------------------------------
  23.                             15827 //v$transaction中UBABLK字段值对应
  24. SQL> select to_number('6f03','XXXXXXXXXXXXX') from dual;

  25. TO_NUMBER('6F03','XXXXXXXXXXXXX')
  26. ---------------------------------
  27.                             28419 //v$transaction XIDSLOT字段值对应
  28.                             
  29.                             
  30. 二、描述延迟块清除的过程
  31. 事务发生时会从回滚段获取一个 ITL(事务槽),分配空间,记录事务相关信息,Transaction 提交后,redo 完成记录,同时还清除回滚段事务信息
  32. 包括行级锁,ITL 信息(commit 标志,SCN 等)清除这些事务段的信息的过程就叫做块清除


  33. 三、用实验证明DDL操作有两个COMMIT
  34. session1:
  35. SQL> create table ilvtu(id number,name varchar2(30),age number);

  36. Table created.

  37. SQL> select * from ichangxin;

  38.         ID NAME
  39. ---------- ------------------------------------------------------------
  40.          1 yy
  41.          1 DX
  42.          1 FH

  43. SQL> delete from ichangxin where name='yy';

  44. 1 row deleted.

  45. SQL> select * from ichangxin;

  46.         ID NAME
  47. ---------- ------------------------------------------------------------
  48.          1 DX
  49.          1 FH

  50. SQL> drop table ilvtu;

  51. Table dropped.

  52. session 2:
  53. #update操作后,drop操作前
  54. SQL> select * from ichangxin;

  55.         ID NAME
  56. ---------- ------------------------------------------------------------
  57.          1 yy
  58.          1 DX
  59.          1 FH
  60. #drop操作后
  61. SQL> select * from ichangxin;

  62.         ID NAME
  63. ---------- ------------------------------------------------------------
  64.          1 DX
  65.          1 FH





  66. 四:用一条UPDATE语句把REDO、UNDO、DATA关联起来(通过实验一步步分析)
  67. 事务的过程:
  68. 1.开始时,去绑定一个回滚段(RBS),回滚段对应一个表,找到undo回滚段的段头(header)那个块里面,找到undo块(涉及到UNDO块的分配)
  69. 2.undo回滚段的段头块存放着一张事务表(TX-TABLE),事务表由槽位组成。事务开始时,会分配一个slot
  70. XID=USN+SLOT+SQN

  71. 3.slot会有一把锁,包括一些信息,包含undo块指针,指向undo block实际地址

  72. 4.执行数据修改,即逻辑操作

  73. 5.以上原子操作被记录在redo日志

  74. SQL> select dbms_rowid.rowid_relative_fno(rowid) file#,dbms_rowid.rowid_block_number(rowid) blockid,ichangxin.* from ichangxin;

  75.      FILE# BLOCKID ID NAME
  76. ---------- ---------- ---------- ------------------------------------------------------------
  77.          1 92873 1 YY
  78.          1 92873 1 DX
  79.          1 92873 1 FH

  80. SQL> alter system switch logfile;

  81. System altered.


  82. SQL> select * from v$log;

  83.     GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIV STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME
  84. ---------- ---------- ---------- ---------- ---------- ---------- ------ -------------------------------- ------------- ------------ ------------ ------------
  85.          4 1 13 209715200 512 1 YES INACTIVE 83409942 27-JUN-16 83409961 27-JUN-16
  86.          5 1 14 209715200 512 1 YES ACTIVE 83409961 27-JUN-16 83418585 28-JUN-16
  87.          6 1 15 209715200 512 1 NO CURRENT 83418585 28-JUN-16 2.8147E+14
  88.                                                                         //当前REDO日志组
  89. SQL> select * from v$logfile;

  90.     GROUP# STATUS TYPE MEMBER IS_REC
  91. ---------- -------------- -------------- -------------------------------------------------- ------
  92.          4 ONLINE /u01/oracle/oradata/edus/redo04.log NO
  93.          5 ONLINE /u01/oracle/oradata/edus/redo05.log NO
  94.          6 ONLINE /u01/oracle/oradata/edus/redo06.log NO


  95. #查看v$transaction视图,注解如下:
  96. XIDUSN:回滚段号为7,对应名称为_SYSSMU7_3286610060$的回滚段
  97. XIDSLOT:第5号事务槽
  98. XIDSQN:事务槽复用序列号
  99. UBAFIL:UNDO块所在文件号为3
  100. UBABLK:所使用UNDO块在3号文件第15827号块        
  101. SQL> select XIDUSN,XIDSLOT,XIDSQN,UBAFIL,UBABLK,UBASQN,UBAREC,STATUS from v$transaction;

  102.     XIDUSN XIDSLOT XIDSQN UBAFIL UBABLK UBASQN UBAREC STATUS
  103. ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------------------------------
  104.          7 5 28419 3 15827 575 4 ACTIVE
  105.         

  106. SQL> select * from v$rollname;

  107.        USN NAME
  108. ---------- ------------------------------------------------------------
  109.          0 SYSTEM
  110.          1 _SYSSMU1_3780397527$
  111.          2 _SYSSMU2_2232571081$
  112.          3 _SYSSMU3_2097677531$
  113.          4 _SYSSMU4_1152005954$
  114.          5 _SYSSMU5_1527469038$
  115.          6 _SYSSMU6_2443381498$
  116.          7 _SYSSMU7_3286610060$
  117.          8 _SYSSMU8_2012382730$
  118.          9 _SYSSMU9_1424341975$
  119.         10 _SYSSMU10_3550978943$

  120. 11 rows selected.

  121. ##dump undo段头块
  122. SQL> alter system dump undo header '_SYSSMU7_3286610060$';

  123. System altered.

  124. SQL> select * from v$diag_info;
  125. SQL> select * from v$diag_info where name='Default Trace File';

  126.    INST_ID NAME VALUE
  127. ---------- -------------------- ----------------------------------------------------------------------------------------------------
  128.          1 Default Trace File /u01/oracle/diag/rdbms/edus/edus/trace/edus_ora_5131.trc
  129.         
  130.  index state cflags wrap# uel scn dba parent-xid nub stmt_num cmt
  131.   ------------------------------------------------------------------------------------------------
  132.    0x00 9 0x00 0x6eef 0x0007 0x0000.04f8de47 0x00c03dc2 0x0000.000.00000000 0x00000003 0x00000000 1467124072
  133.    0x01 9 0x00 0x6efb 0x001c 0x0000.04f8dcd4 0x00c03daf 0x0000.000.00000000 0x00000003 0x00000000 1467123537
  134.    0x02 9 0x00 0x6ef7 0x001a 0x0000.04f8de59 0x00000000 0x0000.000.00000000 0x00000000 0x00000000 1467124073
  135.    0x03 9 0x00 0x6ef0 0x0018 0x0000.04f8de68 0x00c03dcf 0x0000.000.00000000 0x00000003 0x00000000 1467124073
  136.    0x04 9 0x00 0x6f05 0x0020 0x0000.04f8de71 0x00c03dd3 0x0000.000.00000000 0x00000003 0x00000000 1467124073
  137. // 0x05 10 0x80 0x6f03 0x0023 0x0000.04f8d0de 0x00c03dd3 0x0000.000.00000000 0x00000001 0x00000000 0
  138. #猜测state=9,表示已经事务,state=10表示事务未提交
  139. SQL> select to_number('3dd3','XXXXXXXXXXXXX') from dual;

  140. TO_NUMBER('3DD3','XXXXXXXXXXXXX')
  141. ---------------------------------
  142.                             15827 //v$transaction中UBABLK字段值对应
  143. SQL> select to_number('6f03','XXXXXXXXXXXXX') from dual;

  144. TO_NUMBER('6F03','XXXXXXXXXXXXX')
  145. ---------------------------------
  146.                             28419 //v$transaction XIDSLOT字段值对应


  147. #DUMP UNDO块                            
  148. SQL> alter system dump datafile 3 block 15827;

  149. System altered.

  150. SQL> select * from v$diag_info where name='Default Trace File';

  151.    INST_ID
  152. ----------
  153. NAME
  154. --------------------------------------------------------------------------------
  155. VALUE
  156. --------------------------------------------------------------------------------
  157.          1
  158. Default Trace File
  159. /u01/oracle/diag/rdbms/edus/edus/trace/edus_ora_5427.trc
  160. #UNDO块DUMP内容
  161. UNDO BLK:
  162. xid: 0x0007.005.00006f03 seq: 0x23f cnt: 0x4 irb: 0x4 icl: 0x0 flg: 0x0000 //XID三部分内容

  163. Array Update of 1 rows:
  164. tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 0
  165. ncol: 2 nnew: 1 size: 0
  166. KDO Op code: 21 row dependencies Disabled
  167.   xtype: XAxtype KDO_KDOM2 flags: 0x00000080 bdba: 0x00416ac9 hdba: 0x00416ac8 //bdba指向记录所在数据块
  168. itli: 2 ispac: 0 maxfr: 4863
  169. vect = 3
  170. col 1: [ 2] 59 59 //更改前的值

  171. SQL> select dump('yy',16) from dual;

  172. DUMP('YY',16)
  173. --------------------------------------
  174. Typ=96 Len=2: 79,79

  175. SQL> select dump('YY',16) from dual;

  176. DUMP('YY',16)
  177. --------------------------------------
  178. Typ=96 Len=2: 59,59



  179. SQL> select object_id from dba_objects where object_name='ICHANGXIN';

  180.  OBJECT_ID
  181. ----------
  182.      91644
  183. #dump redo日志

  184. SQL> alter system dump logfile '/u01/oracle/oradata/edus/redo06.log'
  185.   2 ;

  186. System altered.

  187. SQL> select * from v$diag_info where name='Default Trace File';

  188.    INST_ID
  189. ----------
  190. NAME
  191. --------------------------------------------------------------------------------
  192. VALUE
  193. --------------------------------------------------------------------------------
  194.          1
  195. Default Trace File
  196. /u01/oracle/diag/rdbms/edus/edus/trace/edus_ora_5976.trc

  197. CHANGE #1 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ:0 OP:24.4 ENC:0

  198. #更新后的记录
  199. REDO RECORD - Thread:1 RBA: 0x00000f.00000b6b.0010 LEN: 0x0214 VLD: 0x0d
  200. SCN: 0x0000.04f8dee6 SUBSCN: 1 06/28/2016 07:29:05
  201. CHANGE #1 TYP:2 CLS:1 AFN:1 DBA:0x00416ac9 OBJ:91644 SCN:0x0000.04f8bc2d SEQ:2 OP:11.19 ENC:0 RBL:0
  202. KTB Redo
  203. op: 0x11 ver: 0x01
  204. compat bit: 4 (post-11) padding: 1
  205. op: F xid: 0x0007.005.00006f03 uba: 0x00c03dd3.023f.04
  206. Block cleanout record, scn: 0x0000.04f8dee4 ver: 0x01 opt: 0x02, entries follow...
  207.   itli: 1 flg: 2 scn: 0x0000.04f8bc2d
  208. Array Update of 1 rows:
  209. tabn: 0 slot: 0(0x0) flag: 0x2c lock: 2 ckix: 0
  210. ncol: 2 nnew: 1 size: 0
  211. KDO Op code: 21 row dependencies Disabled
  212.   xtype: XAxtype KDO_KDOM2 flags: 0x00000080 bdba: 0x00416ac9 hdba: 0x00416ac8
  213. itli: 2 ispac: 0 maxfr: 4863
  214. vect = 3
  215. col 1: [ 2] 79 79
  216. CHANGE #2 TYP:0 CLS:29 AFN:3 DBA:0x00c000e0 OBJ:4294967295 SCN:0x0000.04f8de81 SEQ:1 OP:5.2 ENC:0 RBL:0
  217. ktudh redo: slt: 0x0005 sqn: 0x00006f03 flg: 0x0012 siz: 188 fbi: 0
  218.             uba: 0x00c03dd3.023f.04 pxid: 0x0000.000.00000000

  219. #UNDO块更改记录
  220. CHANGE #3 TYP:0 CLS:30 AFN:3 DBA:0x00c03dd3 OBJ:4294967295 SCN:0x0000.04f8de7b SEQ:1 OP:5.1 ENC:0 RBL:0
  221. ktudb redo: siz: 188 spc: 7824 flg: 0x0012 seq: 0x023f rec: 0x04
  222.             xid: 0x0007.005.00006f03
  223. ktubl redo: slt: 5 rci: 0 opc: 11.1 [objn: 91644 objd: 91644 tsn: 0]
  224. Undo type: Regular undo Begin trans Last buffer split: No
  225. Temp Object: No
  226. Tablespace Undo: No
  227.              0x00000000 prev ctl uba: 0x00c03dd3.023f.03
  228. prev ctl max cmt scn: 0x0000.04f8dcc8 prev tx cmt scn: 0x0000.04f8dcca
  229. txn start scn: 0x0000.00000000 logon user: 0 prev brb: 12598697 prev bcl: 0 BuExt idx: 0 flg2: 0
  230. KDO undo record:
  231. KTB Redo
  232. op: 0x04 ver: 0x01
  233. compat bit: 4 (post-11) padding: 1
  234. op: L itl: xid: 0x0001.00f.0000991c uba: 0x00c1866f.0293.1e
  235.                       flg: C--- lkc: 0 scn: 0x0000.04f85ca8
  236. Array Update of 1 rows:
  237. tabn: 0 slot: 0(0x0) flag: 0x2c lock: 0 ckix: 0
  238. ncol: 2 nnew: 1 size: 0
  239. KDO Op code: 21 row dependencies Disabled
  240.   xtype: XAxtype KDO_KDOM2 flags: 0x00000080 bdba: 0x00416ac9 hdba: 0x00416ac8
  241. itli: 2 ispac: 0 maxfr: 4863
  242. vect = 3
  243. col 1: [ 2] 59 59

阅读(2780) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~