您好,欢迎访问一九零五行业门户网

Oracle的Flashback用法汇总

欢迎进入oracle社区论坛,与200万技术人员互动交流 >>进入 ? 6.进行数据恢复 ? 禁止表上的触发器 alter trigger sphsy.t_ins_login_table disable ; ? 恢复数据 insert into sphsy.login_table select * from sphsy.login_table as of timestamp to_timestam
欢迎进入oracle社区论坛,与200万技术人员互动交流 >>进入
    ? 6.进行数据恢复
    ? 禁止表上的触发器
    alter trigger sphsy.t_ins_login_table disable ;
    ? 恢复数据
    insert into sphsy.login_table
    select * from sphsy.login_table
    as of timestamp to_timestamp(’2012-04-17 17:20:30′,’yyyy-mm-dd hh24:mi:ss’)
    where id > 201204171078
    and id
    ? 恢复触发器
    alter trigger sphsy.t_ins_login_table enable ;
    ? 7.晚于区间的数据回来了3130 = 3016 +62 + 后来的数据。实现了区间恢复误删除。
    select program,count(*)
    from sphsy.login_table a
    where a.id >= 201204171078
    group by program ;
    ? d. flashback table 恢复表到先前状态
    /*
    flashback查询可以用于恢复被误删除的表行数据,但是用户在表上执行了其他的dml语句误操作(insert或update),则不能直接使用flashback查询将表数据恢复到先前时间点,从oracle10g开始,使用flashback table语句可以将表恢复到先前时间点,通过使用该特征,可以避免执行基于时间点的不完全恢复,注意如果要在某个表上使用flashback table特征,则要求必须具有以下条件:
    a.用户必须具有flashback any table系统权限或flashback对象权限
    b.用户必修在表上具有select insert delete和alter权限
    c.必须合理设置初始化参数undo_retention,以确保undo信息保留足够时间
    d.必须激活行移动特征:alter table table_name enable row movement;
    */
    ? 1.查原始记录 ,区间内有62 行
    select *
    from sphsy.login_table a
    where a.id > 201204171078
    and a.id
    order by a.id ;
    ? 2.晚于区间的有 3074
    select count(*)
    from sphsy.login_table a
    where a.id >= 201204171141;
    ?3. 删除 ,先记下时间点,2012-04-17 17:43:46
    select to_char(sysdate,’yyyy-mm-dd hh24:mi:ss’) from dual ;
    delete from sphsy.login_table a
    where a.id > 201204171078
    and a.id
    ? 4.删除之后表 sphysy.login_table继续有修改 ,行3082
    select count(*)
    from sphsy.login_table a
    where a.id >= 201204171141;
    ?5.激活行移动特征
    alter table sphsy.login_table enable row movement
    ?6.利用闪回特性,直接恢复到删除时间点前
    flashback table sphsy.login_table to timestamp to_timestamp(’2012-04-17 17:43:46′,’yyyy-mm-dd hh24:mi:ss’);
    ? 7.晚于区间的数据 回到了3080 ,说明时间点之后的修改丢失。
    select count(*)
    from sphsy.login_table a
    where a.id >= 201204171141
    ? 8.往前推1分,恢复到删除之前,删除的62条也回来了。
    flashback table sphsy.login_table to timestamp to_timestamp(’2012-04-17 17:40:46′,’yyyy-mm-dd hh24:mi:ss’);
    ? 62 行
    select count(*)
    from sphsy.login_table a
    where a.id > 201204171078
    and a.id
    ? 删除之后的数据为3074,代表还有修改丢失。
    select count(*)
    from sphsy.login_table a
    where a.id >= 201204171141
    /*
    总结:方法c,方法d均可以用数据恢复。
    方法c安全,恢复麻烦。方法d简单,有可能数据丢失。
    */
  [1] [2]
其它类似信息

推荐信息