zoukankan      html  css  js  c++  java
  • ORACLE数据恢复方法(提交事务也可以)

    今天在操作数据库的时候,发现数据操作错误,想要恢复,但是没有用事务,按理说,设置成不默认提交事务,此时所做的各种操作都没有反应到数据库中。这时,你可以rollback事务,撤销所有未提交的修改。不过,一旦commit了的话,就真没办法撤销了。好在oracle还有时间戳方法。

    第一种方法:

    1.打开Flash存储的权限
    ALTER TABLE tablename ENABLE row movement ;
    2.把表还原到指定时间点
    flashback table tablename to timestamp to_timestamp(''2011-02-28 10:40:00'',''yyyy-mm-dd hh24:mi:ss'');
    后面的参数为要还原的时间点

    第二种:利用ORacle的快照进行查找某个时间点的数据
    select * from tablename AS OF TIMESTAMP  (SYSTIMESTAMP - INTERVAL '100' MINUTE)

    or

    select * from tablename as of timestamp to_timestamp(2011-05-21 11:40:00','YYYY-MM-DD HH24:MI:SS');

    这样可以查询到指定的时间段的数据,再把查询到的数据复制到原来的表中。

    例:

    如果我们在前5分钟误删除了表emp中的数据,我们可以进行如下操作:

    找回原始数据

    Select * from emp as of timestamp sysdate  -  6/1440

    删除原来的表   删掉后创建一个备份表

    Create table emp as (select * from emp as of timestamp sysdate - 6/1440);

    可以做差,找到删除的记录=6分钟前的原始数据—现在表中的记录 再插入原来的表中提交

    Insert into emp 

    Select * From

    (

    select * From emp as of timestamp sysdate - 6/1440 Minus Select * from emp)

    --timestamp(ags) 方法

    --interval(时间间隔)类型用来存储两个时间戳之间的时间间隔

    --当要回复被删除的数据的时候

    --查询500分钟之前的数据

    select * from emp as of timestamp(systimestamp - interval '500' minute)

    --查询600秒之前的数据

    select * from emp as of timestamp(systimestamp - interval '600' second)

    --查询5小时之前的数据

    select * from emp as of timestamp(systimestamp - interval '5' hour)

    --查询一天之前的数据

    select * from emp as of timestamp(systimestamp - interval '1' day)

    --查询1分钟前的数据 (1天=1440分钟) date-number=date

    select * from emp as of timestamp sysdate - 1/1440

    --查询5小时前的数据

    select * from emp as of timestamp sysdate - 5/24

    --查询 5小时内数据=内前删除的5小时前表中的数据-现在表中的数据

    --minus减去

    select * from

    (select * from emp as of timestamp sysdate -5000/1440 minus select * from emp)

    从9i开始,oracle提供了闪回(flashback)功能。使用flashback table语句从撤销段中(undo segmeng)读取改表的过去映像,同时利用oracle9i中引入的回闪查询功能重建表行。Undo_retention给出了回闪支持的最小时间。也就是说flashback最少可以支持undo_retention给出的时间,如果系统比较闲,则可以回闪更长的时间。如果系统处于忙时,有可能重用还没有达到undo_retention时间吸纳是的数据空间。注意:使用闪回的一个前提是表不能进行ddl操作,不但不能对ddl操作进行回闪,而且,无法闪回到ddl操作以前的数据了。

    注意:不启动行移动功能,不能闪回表

    Alter table emp enable row movement;

    这个命令的作用就是允许ORACLE修改分配给行的rowid。在ORACLE中,插入一行时就会为它分配一个rowid,而且这一行永远拥有这个rowid。闪回表处理时会对EMP表完成DELETE 操作,并且重新插入行,这样就会为这些行分配一个新的rowid。要支持闪回功能就必须允许ORACLE执行这个操作。

    原文:http://blog.csdn.net/jiajane/article/details/49280277

  • 相关阅读:
    Vue根据URL传参来控制全局 console.log 的开关
    原来你是这样的毛玻璃
    CSS3边框会动的信封
    判断当前系统当前浏览器是否安装启用 Adobe Flash Player,检查在chrome中的状态
    随笔一个正则
    PHP实现栈数据结构
    php实现一个单链表
    php中按值传递和按引用传递的一个问题
    利用shell脚本或者php移动某个文件夹下的文件到各自的日期组成的目录下
    php中DateTime、diff
  • 原文地址:https://www.cnblogs.com/langtianya/p/8006373.html
Copyright © 2011-2022 走看看