[20180306]关于DEFERRED ROLLBACK2.txt

简介: [20180306]关于DEFERRED ROLLBACK2.txt --//上午测试DEFERRED ROLLBACK针对表空间offline才有效,我测试回滚一定会写到DEFERRED ROLLBACK段.

[20180306]关于DEFERRED ROLLBACK2.txt

--//上午测试DEFERRED ROLLBACK针对表空间offline才有效,我测试回滚一定会写到DEFERRED ROLLBACK段.
--//但是提交是否会写入会EFERRED ROLLBACK呢?测试看看.

1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.建立测试例子:
--//session 1:
SCOTT@book> create table DEMO   (id number, update_scn number, commit_scn number,vc varchar2(20)) SEGMENT CREATION IMMEDIATE tablespace tea ;
Table created.

SCOTT@book> select current_scn,sysdate from v$database ;
CURRENT_SCN SYSDATE
------------ -------------------
13277394884 2018-03-05 14:53:21

SCOTT@book> insert into DEMO (id )values (1);
1 row created.

SCOTT@book> commit ;
Commit complete.

SCOTT@book> update demo set update_scn=dbms_flashback.get_system_change_number, commit_scn=userenv('commitscn'),vc='aaa1bbb2' where id=1;
1 row updated.

--//session 2:
SCOTT@book> alter tablespace tea offline ;
Tablespace altered.

SCOTT@book> select OWNER,SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK,BYTES from dba_segments where segment_type='DEFERRED ROLLBACK';
OWNER  SEGMENT_NAME         SEGMENT_TYPE        HEADER_FILE HEADER_BLOCK        BYTES
------ -------------------- ------------------ ------------ ------------ ------------
SYS    1.2424               DEFERRED ROLLBACK             1         2424        65536

SCOTT@book> select * from dba_extents where segment_name='1.2424';
OWNER  SEGMENT_NAME         SEGMENT_TYPE       TABLESPACE_NAME                   EXTENT_ID      FILE_ID     BLOCK_ID        BYTES       BLOCKS RELATIVE_FNO
------ -------------------- ------------------ ------------------------------ ------------ ------------ ------------ ------------ ------------ ------------
SYS    1.2424               DEFERRED ROLLBACK  SYSTEM                                    0            1         2424        65536            8            1

SCOTT@book> @ &r/bbvi 1 2424
BVI_COMMAND
----------------------------------------------------------------------------------------------------
bvi -b 19857408 -s 8192 /mnt/ramdisk/book/system01.dbf

--//8192*8 = 65536,执行bvi -b 19857408 -s 65536 /mnt/ramdisk/book/system01.dbf,查询无法找到字符串aaa1bbb2.

SCOTT@book> commit ;
commit
*
ERROR at line 1:
ORA-00376: file 6 cannot be read at this time
ORA-01110: data file 6: '/mnt/ramdisk/book/tea01.dbf'

--//为什么呢?因为调用userenv('commitscn')函数非常特殊,类似触发器在commit时写入新的scn号到块中,而这个时候表空间offline无法读取,报错.
SCOTT@book> alter tablespace tea online ;
Tablespace altered.

3.继续测试:
--//session 1:
SCOTT@book> alter tablespace tea online ;
Tablespace altered.

SCOTT@book> select rowid,demo.* from demo;
ROWID                        ID   UPDATE_SCN   COMMIT_SCN VC
------------------ ------------ ------------ ------------ --------------------
AAAWGSAAGAAAACBAAA            1

SCOTT@book> update demo set update_scn=dbms_flashback.get_system_change_number, vc='AAA1ZZZ2' where id=1;
1 row updated.

--//session 2:
SCOTT@book> alter tablespace tea offline ;
Tablespace altered.

SCOTT@book> select OWNER,SEGMENT_NAME,SEGMENT_TYPE,HEADER_FILE,HEADER_BLOCK,BYTES from dba_segments where segment_type='DEFERRED ROLLBACK';
OWNER  SEGMENT_NAME         SEGMENT_TYPE        HEADER_FILE HEADER_BLOCK        BYTES
------ -------------------- ------------------ ------------ ------------ ------------
SYS    1.2424               DEFERRED ROLLBACK             1         2424        65536

SCOTT@book> select * from dba_extents where segment_name='1.2424';
OWNER  SEGMENT_NAME         SEGMENT_TYPE       TABLESPACE_NAME                   EXTENT_ID      FILE_ID     BLOCK_ID        BYTES       BLOCKS RELATIVE_FNO
------ -------------------- ------------------ ------------------------------ ------------ ------------ ------------ ------------ ------------ ------------
SYS    1.2424               DEFERRED ROLLBACK  SYSTEM                                    0            1         2424        65536            8            1

--//session 1:
SCOTT@book> commit ;
Commit complete.

SCOTT@book> alter system checkpoint;
System altered.

$ bvi -b 19857408 -s 65536 /mnt/ramdisk/book/system01.dbf

--//另存为/tmp/1.2424

--//session 2:
SCOTT@book> alter tablespace tea online ;
Tablespace altered.

SCOTT@book> select ora_rowscn,rowid,demo.* from demo;
  ORA_ROWSCN ROWID                        ID   UPDATE_SCN   COMMIT_SCN VC
------------ ------------------ ------------ ------------ ------------ --------------------
13277396291 AAAWGSAAGAAAACBAAA            1  13277395703              AAA1ZZZ2

select 13277396291,32,trunc(13277396291/power(2,32)) scn_wrap,mod(13277396291,power(2,32))  scn_base from dual
13277396291           32     SCN_WRAP     SCN_BASE
------------ ------------ ------------ ------------
13277396291           32            3    392494403

SCOTT@book> @ &r/10to16 392494403
10 to 16 HEX   REVERSE16
-------------- ------------------
000001764fd43 0x43fd6417

--//在/tmp/1.2424文件中查询1764fd43, 43fd6417都没有找到,说明commit并不写DEFERRED ROLLBACK段.

目录
相关文章
|
缓存 Oracle 关系型数据库
Oracle中控制commit的三个参数 commit_write, commit_logging和 commit_wait
Oracle中控制commit的动作有三个参数 commit_write, commit_logging和 commit_wait,按重要性分别说明如下
309 0
|
Oracle 关系型数据库 测试技术
[20180306]关于DEFERRED ROLLBACK.txt
[20180306]关于DEFERRED ROLLBACK.txt --//在oracle数据库存在一种特殊的ROLLBACK段,叫DEFERRED ROLLBACK.
1078 0
|
Linux Shell 网络安全
|
Shell Linux 网络安全
|
数据库管理
[20160819]什么是DEFERRED ROLLBACK.txt
[20160819]什么是DEFERRED ROLLBACK.txt A "Deferred Rollback" segment is created for a tablespace when a tablespace is taken offline.
908 0
|
数据库
是否遇到过rollback segment的状态为need recovery??
这篇metalink文章讲了,如果由于数据库对象本身出了问题,而不是真正的回滚段的问题的时候,在恢复过程中怎么处理!!! 比较详细,没有登陆metalink的人们可以好好看看! 主题: Rollback Segment Needs Recovery 文档 ID: 注释:28812.
798 0