测试环境:Oracle 11gR2 Restart
测试目的:模拟undo header事务表槽被覆盖引起ORA-01555的现象及原理解析
场景介绍:
Session 1:
获取scott.tabnow1表中记录对应的relative_fno和block_number;
Update一条记录,但不commit,记录下所使用的xid、uba信息
Session 2:
以非SYS用户连接执行:set transaction read only;
Session 1:
Commit;
Session 3:
对scott.t1表连续做update+commit操作
Session 2:
成功遍历scott.tabnow1表
select * from scott.tabnow1;
Session 4:
再次对scott.t1表连续做update+commit操作,继续覆盖事务表
Session 2:
再次遍历scott.tabnow1表
得到ORA-01555错误
测试数据库配置:
##为简化测试过程,建立了一个256K的undotbs
SQL> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOSIG
SQL> select d.name,d.bytes from v$datafile d,v$tablespace t where t.ts#=d.ts# and t.name='UNDOSIG';
NAME BYTES
---------------------------------------- ----------
+STESTDG1/stest2/undosig.dbf 262144
##undosig里只有一个undo segment online
SQL> select segment_name,tablespace_name,relative_fno,status from dba_rollback_segs where tablespace_name='UNDOSIG';
SEGMENT_NAME TABLESPACE_NAME RELATIVE_FNO STATUS
------------------------------ ------------------------------ ------------ ----------------
_SYSSMU2$ UNDOSIG 8 ONLINE
##undo segment里extent的分布情况,除去undo header所占据的block 8,block 9~31都可以被事务用来存放修改前内容:
SQL> select segment_name,extent_id,file_id,block_id,blocks from dba_extents where segment_name='_SYSSMU2$';
SEGMENT_NAME EXTENT_ID FILE_ID BLOCK_ID BLOCKS
------------------------------ ---------- ---------- ---------- ----------
_SYSSMU2$ 0 8 8 8
_SYSSMU2$ 1 8 16 8
_SYSSMU2$ 2 8 24 8
##测试用到的两张表初始内容:
SQL> select * from scott.tabnow1;
USERNAME USER_ID CREATED
------------------------------ ---------- ------------
XS$NULLLL 2147483638 21-OCT-11
NEWUSER 84 12-MAR-14
SCOTTTTT 83 21-OCT-11
OWBSYS_AUDIT 82 21-OCT-11
OWBSYS 78 21-OCT-11
APEX 77 21-OCT-11
APEX_PUBLIC 75 21-OCT-11
FLOWS_FILE 74 21-OCT-11
MGMT_VIEW 73 21-OCT-11
DDD 34 28-MAY-14
SQL> select * from scott.t1;
ID
----------
34
34
开始测试过程:
/////////////
//session 1:
/////////////
##确定scott.tabnow1表中的记录所在的块,便于之后对data block作dump;所有的行都在同一个block中
select dbms_rowid.rowid_relative_fno(rowid) rfno,dbms_rowid.rowid_block_number(rowid) blkno from scott.tabnow1;
RFNO BLKNO
---------- ----------
4 1779
4 1779
4 1779
4 1779
4 1779
4 1779
4 1779
4 1779
4 1779
4 1779
##记录一下undo header的初始状态,slot 0x1e将成为下一个要用到的slot
TRN CTL:: seq: 0x187e chd: 0x001e ctl: 0x0000 inc: 0x00000000 nfb: 0x0001
mgc: 0xb000 xts: 0x0068 flg: 0x0001 opt: 2147483646 (0x7ffffffe)
uba: 0x02000010.187e.18 scn: 0x0000.00ae9095
TRN TBL::