闪回技术之事物级闪回特别篇3

来源:互联网 发布:nginx 修改路径 编辑:程序博客网 时间:2024/04/29 09:13

事物级别闪回
所谓闪回表就是将数据倒退到历史上的某个时间点,操作的语句是DML语句哈,千万要记到哈,DML操作的才叫事物级别的闪回。
闪回表利用UNDO表空间记录的数据旧映像,如果闪回表超过了und0_retention所指定的值,从而导致该undo数据库被其他事物覆盖,

就不能恢复到指定的位置了。

show parameter undo;  --查看闪回表的参数
NAME                                 TYPE        VALUE
------------------------------------ ----------- ----------------------
undo_management                      string      AUTO
undo_retention                       integer     3600
undo_tablespace                      string      UNDOTBS1
我这儿的设置3600秒哈,只是一个小时,我们可以在设置大一点点


启动实验

create table test(id number, name varchar2(20));


begin
for i in 1..100 loop
    insert into test values(i,'小牟');
end loop;
end;
/
循环插入1到100

commit;

SQL> select count(*) from test;

  COUNT(*)
----------
       100

delete from test where id<80;
commit;

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2013-10-06 15:09:16
我们查看删除时候的时间大概是在15:07:00

使用闪回特性
flashback table test to timestamp to_date('2013-10-06 15:07:16','yyyy-mm-dd hh24:mi:ss');                *
第 1 行出现错误:
ORA-08189: 因为未启用行移动功能, 不能闪回表
为什么报错呢,关键时刻来了
闪回表的操作会修改表里的数据,从而可能引起数据行的移动,比如某一行数据当前在A数据库里,而在表闪回到以前的某个时间点上

时,在那个时间点上该行数据位于B数据库里面,因此在闪回表之前需要启用数据行的移动特性。

alter table test enable row movement;

flashback table test to timestamp to_date('2013-10-06 15:07:16','yyyy-mm-dd hh24:mi:ss'); 我闪
SQL> select count(*)  from test;

  COUNT(*)
----------
       100
你看,事物级别的闪回成功

 

 


 

原创粉丝点击