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.
如果使用闪回表查询,则会将此表上所有的数据恢复到某一个时间点上,则不符合要求.
推荐使用闪回版本查询和闪回事务查询,过程如下:
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;
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, 后来,查书,原来使用闪回事务查询,需要打开补充日志,命令如下:
alter databaes add supplemental log data;
如果要使用闪回事务查询,建议在数据库创建好之后就把补充日志功能打开吧。好像日志挖掘也需要补充日志,不知道为什么系统默认不打开此功能。是因为性能问题吗?
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
版权声明:本文为博主原创文章,未经博主允许不得转载。
闪回
- 上一篇:DG配置过程中的参数解释
- 下一篇:h3c v7版 二层注册配置