签到成功

知道了

CNDBA社区CNDBA社区

oracle 11g闪回版本实验

2018-08-22 14:38 3785 0 原创 oracle
作者: tianxiadishi

1.创建测试表scott.t1,并手工产生几个事务:

drop table scott.t1;
create table scott.t1 as select * from scott.emp;
update scott.t1 set sal=1050 where empno=7369;
commit;   #事务1
update scott.t1 set sal=2000 where empno=7499;
update scott.t1 set sal=3000 where empno=7369;
commit;  #事务2
update scott.t1 set sal=5000 where empno=7521;
commit;  #事务3

此时,我假设事务2搞错了,需要把事务2回退,但不能影响事务1和事务3.
如果使用闪回表查询,则会将此表上所有的数据恢复到某一个时间点上,则不符合要求.

推荐使用闪回版本查询和闪回事务查询,过程如下:

http://www.cndba.cn/tianxiadishi/article/2958

1.1 查scott.t1表,确定要撤回事务的版本号:

select empno,sal,versions_operation,VERSIONS_STARTSCN ,VERSIONS_ENDSCN,versions_xid,to_char(versions_starttime,'yyyy/mm/dd hh24:mi:ss') from scott.t1 versions between timestamp minvalue and maxvalue order by VERSIONS_STARTSCN ;

假设要撤回的事务,版本号为05000A0088070000;http://www.cndba.cn/tianxiadishi/article/2958

1.2 根据事务号,撤回事务,有两种方法,推荐使用第二种

1.2.1 使用flashback_transaction_query,过程如下:
select logon_user,table_name,table_owner,to_char(start_timestamp,'yyyy/mm/dd hh24:mi:ss') starttime,to_char(commit_timestamp,'yyyy/mm/dd hh24:mi:ss') endtime,undo_sql from flashback_transaction_query where table_owner='SCOTT' and xid=hextoraw('05000A0088070000');

updo_sql字段就是回退语句,直接复制出来确认无问题后,粘到sql中执行即可,但在这里,我发现没有产生undo_Sql, 后来,查书,原来使用闪回事务查询,需要打开补充日志,命令如下:

http://www.cndba.cn/tianxiadishi/article/2958
http://www.cndba.cn/tianxiadishi/article/2958
http://www.cndba.cn/tianxiadishi/article/2958
http://www.cndba.cn/tianxiadishi/article/2958

alter databaes add supplemental log data;

如果要使用闪回事务查询,建议在数据库创建好之后就把补充日志功能打开吧。好像日志挖掘也需要补充日志,不知道为什么系统默认不打开此功能。是因为性能问题吗?http://www.cndba.cn/tianxiadishi/article/2958http://www.cndba.cn/tianxiadishi/article/2958http://www.cndba.cn/tianxiadishi/article/2958http://www.cndba.cn/tianxiadishi/article/2958

1.2.2 使用dbms_flashback.transaction_backout包,
Execute dbms_flashback.transaction_backout (numtxns=>1, xids=>sys.xid_array('05000A0088070000'),options=>dbms_flashback.cascade);

1.3 最后,确认恢复结果

select * from scott.t1

版权声明:本文为博主原创文章,未经博主允许不得转载。

闪回

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
tianxiadishi

tianxiadishi

关注
  • 17
    原创
  • 0
    翻译
  • 3
    转载
  • 14
    评论
  • 访问:110235次
  • 积分:96
  • 等级:注册会员
  • 排名:第31名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ