【大胆的实验】Oracle的不一致性,未commit数据变成实际数据并被其他回话查询

操作系统版本:
  1. [oracle@oracle zkm]$ uname -a
  2. Linux oracle.example.com 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
  3. [oracle@oracle zkm]$ lsb_release -a
  4. LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
  5. Distributor ID: RedHatEnterpriseServer
  6. Description:    Red Hat Enterprise Linux Server release 6.5 (Santiago)
  7. Release:        6.5
  8. Codename:       Santiago

数据库版本:
  1. SYS@proc> select * from v$version where rownum=1;

  2. BANNER
  3. --------------------------------------------------------------------------------
  4. Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

环境构造:
  1. SYS@proc> drop table tt purge;

  2. Table dropped.

  3. SYS@proc> create table tt (id int,name varchar2(2000)) tablespace users;

  4. Table created.

  5. SYS@proc> begin
  6.               for i in 1..10000 loop
  7.                   insert into tt values(i,rpad('a',2000,'+'));
  8.               end loop;
  9.               commit;
  10.           end;
  11.           /

  12. PL/SQL procedure successfully completed.

实验过程:
  1. SYS@proc> begin
  2.               for i in 1..10000 loop
  3.                   update tt set name=rpad('b',2000,'-') where id=i;
  4.               end loop;
  5.           end;
  6.           /

  7. PL/SQL procedure successfully completed.

  8. SYS@procshutd abort;
  9. ORACLE instance shut down.
  10. SYS@proc> exit
  11. Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
  12. With the Partitioning, OLAP, Data Mining and Real Application Testing options
  13. [oracle@oracle ~]$ ll un*
  14. -rw-r-----. 1 oracle oinstall 104865792 Jul 19 11:19 undotbs1.dbf
  15. [oracle@oracle ~]$ rm -fr undotbs1.dbf
  16. [oracle@oracle ~]$ sqlplus / as sysdba

  17. SQL*Plus: Release 11.2.0.4.0 Production on Wed Jul 19 11:20:17 2017

  18. Copyright (c) 1982, 2013, Oracle. All rights reserved.

  19. Connected to an idle instance.

  20. SYS@proc> startup;
  21. ORACLE instance started.

  22. Total System Global Area 521936896 bytes
  23. Fixed Size                 2254824 bytes
  24. Variable Size            306186264 bytes
  25. Database Buffers         209715200 bytes
  26. Redo Buffers               3780608 bytes
  27. Database mounted.
  28. ORA-01157: cannot identify/lock data file 3 - see DBWR trace file
  29. ORA-01110: data file 3: '/home/oracle/undotbs1.dbf'


  30. SYS@proc> alter database datafile 3 offline drop;

  31. Database altered.

  32. SYS@proc> alter database open;

  33. Database altered.

  34. SYS@proc> create undo tablespace undotbs2 datafile '/home/oracle/undotbs2.dbf' size 100m autoextend on;

  35. Tablespace created.

  36. SYS@proc> alter system set undo_tablespace=undotbs2;

  37. System altered.

  38. SYS@proc> show parameter undo_tablespace

  39. NAME                 TYPE     VALUE
  40. ------------------------------------ ----------- ------------------------------
  41. undo_tablespace          string     UNDOTBS2
  42. SYS@proc> select count(*) from tt;
  43. select count(*) from tt
  44.                      *
  45. ERROR at line 1:
  46. ORA-00376: file 3 cannot be read at this time
  47. ORA-01110: data file 3: '/home/oracle/undotbs1.dbf'


  48. SYS@proc> drop tablespace undotbs1 including contents and datafiles;
  49. drop tablespace undotbs1 including contents and datafiles
  50. *
  51. ERROR at line 1:
  52. ORA-01548: active rollback segment '_SYSSMU7_1076253125$' found, terminate dropping tablespace


  53. SYS@proc> --查询回滚段信息
  54.     select rownum,
  55.         sys.dba_rollback_segs.segment_name Name,
  56.         v$rollstat.extents Extents,
  57.         v$rollstat.rssize Size_in_Bytes,
  58.         v$rollstat.xacts XActs,
  59.         v$rollstat.gets Gets,
  60.         v$rollstat.waits Waits,
  61.         v$rollstat.writes Writes,
  62.         sys.dba_rollback_segs.status status
  63.    from v$rollstat, sys.dba_rollback_segs, v$rollname
  64.   where v$rollname.name(+) = sys.dba_rollback_segs.segment_name
  65.     and v$rollstat.usn(+) = v$rollname.usn
  66.   order by rownum;

  67.     ROWNUM NAME                              EXTENTS SIZE_IN_BYTES      XACTS       GETS      WAITS     WRITES STATUS
  68. ---------- ------------------------------ ---------- ------------- ---------- ---------- ---------- ---------- ----------------
  69.          1 SYSTEM                                  6        385024          0        293          0      39796 ONLINE
  70.          2 _SYSSMU17_2390902301$                   2        122880          0          2          0          0 ONLINE
  71.          3 _SYSSMU18_1669837494$                   2        122880          0          2          0          0 ONLINE
  72.          4 _SYSSMU39_929646464$                    2        122880          0          4          0        138 ONLINE
  73.          5 _SYSSMU40_3450336478$                   2        122880          0          4          0        430 ONLINE
  74.          6 _SYSSMU41_3787558531$                   2        122880          0          4          0        232 ONLINE
  75.          7 _SYSSMU42_2640506269$                   2        122880          0          4          0        214 ONLINE
  76.          8 _SYSSMU43_391677854$                    2        122880          0          4          0        158 ONLINE
  77.          9 _SYSSMU44_2493446996$                   2        122880          0          7          0        900 ONLINE
  78.         10 _SYSSMU45_2356950286$                   2        122880          0          4          0       3482 ONLINE
  79.         11 _SYSSMU46_275930757$                    2        122880          0          4          0        114 ONLINE

  80.     ROWNUM NAME                           EXTENTS    SIZE_IN_BYTES      XACTS       GETS      WAITS     WRITES STATUS
  81. ---------- ------------------------------ ---------- ------------- ---------- ---------- ---------- ---------- ----------------
  82.         12 _SYSSMU12_1668912051$                                                                               NEEDS RECOVERY
  83.         13 _SYSSMU7_1076253125$                                                                                NEEDS RECOVERY
  84.         14 _SYSSMU16_2690255195$                                                                               NEEDS RECOVERY
  85.         15 _SYSSMU11_3130810267$                                                                               NEEDS RECOVERY
  86.         16 _SYSSMU13_492329380$                                                                                NEEDS RECOVERY
  87.         17 _SYSSMU9_2756025465$                                                                                NEEDS RECOVERY
  88.         18 _SYSSMU15_3752757294$                                                                               NEEDS RECOVERY
  89.         19 _SYSSMU10_146814648$                                                                                NEEDS RECOVERY
  90.         20 _SYSSMU8_4280284895$                                                                                NEEDS RECOVERY
  91.         21 _SYSSMU14_3551377741$                                                                               NEEDS RECOVERY

  92. 21 rows selected.

  93. SYS@proc> shutdown immediate;
  94. Database closed.
  95. Database dismounted.
  96. ORACLE instance shut down.
  97. SYS@proc> create pfile from spfile;

  98. File created.


  99. [oracle@oracle dbs]$ cat initproc.ora | grep offline_rollback_segments
  100. *._offline_rollback_segments='_SYSSMU12_1668912051$','_SYSSMU7_1076253125$','_SYSSMU16_2690255195$','_SYSSMU11_3130810267$','_SYSSMU13_492329380$','_SYSSMU9_2756025465$','_SYSSMU15_3752757294$','_SYSSMU10_146814648$','_SYSSMU8_4280284895$','_SYSSMU14_3551377741$'

  101. SYS@proc> create spfile from pfile;

  102. File created.

  103. SYS@proc> startup;
  104. ORACLE instance started.

  105. Total System Global Area 521936896 bytes
  106. Fixed Size                 2254824 bytes
  107. Variable Size            306186264 bytes
  108. Database Buffers         209715200 bytes
  109. Redo Buffers               3780608 bytes
  110. Database mounted.
  111. Database opened.
  112. SYS@proc> show parameter offline_roll

  113. NAME                                 TYPE        VALUE
  114. ------------------------------------ ----------- ------------------------------
  115. _offline_rollback_segments           string     _SYSSMU12_1668912051$, _SYSSMU
  116.                                                 7_1076253125$, _SYSSMU16_26902
  117.                                                 55195$, _SYSSMU11_3130810267$,
  118.                                                  _SYSSMU13_492329380$, _SYSSMU
  119.                                                 9_2756025465$, _SYSSMU15_37527
  120.                                                 57294$, _SYSSMU10_146814648$,
  121.                                                 _SYSSMU8_4280284895$, _SYSSMU1
  122.                                                 4_3551377741$
  123. SYS@proc> select count(*) from tt;
  124. select count(*) from tt
  125.                      *
  126. ERROR at line 1:
  127. ORA-00376: file 3 cannot be read at this time
  128. ORA-01110: data file 3: '/home/oracle/undotbs1.dbf'

  129. SYS@proc> drop tablespace undotbs1 including contents and datafiles;

  130. Tablespace dropped.

  131. SYS@proc> select count(*) from tt;

  132.   COUNT(*)
  133. ----------
  134.      10000

  135. SYS@proc>
  1. SYS@proc> alter system reset "_offline_rollback_segments";

  2. System altered.

  3. SYS@proc> startup force;
  4. ORACLE instance started.

  5. Total System Global Area 521936896 bytes
  6. Fixed Size                 2254824 bytes
  7. Variable Size            306186264 bytes
  8. Database Buffers         209715200 bytes
  9. Redo Buffers               3780608 bytes
  10. Database mounted.
  11. Database opened.
  12. SYS@proc> show parameter _offline_rollback_segments
  13. SYS@proc>

查询结果:
select * from tt;(在PLSQL Developer 12 (64 bit)工具中执行)


总结:
需要注意的是,不是每次结果都能看到有a和b结果的混合,很大几率只能看到都是b---..的情况,不过b--..都是未commit的数据,已经达到目的。
至于为什么会这样,这涉及到oracle实例恢复原理,读一致性原理,ITL等等知识,这里就不详述了。




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

转载于:http://blog.itpub.net/30174570/viewspace-2142281/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值