flashback与timestamp

一、简介:
1、flashback query是利用多版本读一致性的特性从undo表空间读取操作前的数据记录。那么什么是多版本一致性。是指在不同事务在写数据时,会将数据的前镜像写入undo segment,而事务查询的记录由undo表空间中的数据前镜像来构造,不需要等待事务提交或回滚。
2、undo占用的空间并非用完就释放,其根据一定的规则(比如undo_retention参数、事务提交频繁程度、undo表空间大小决定)自动清理undo表空间的undo数据。同一条记录的修改操作在undo表空间中对应多个记录,而flashback正好利用这一个特点。
 
二、undo_retention参数的查询、修改:
用show parameter undo;命令查看当时的数据库参数undo_retention设置。
显示如下:
undo_management                       string       AUTO
    undo_retention                        integer      10800
    undo_suppress_errors                  boolean      FALSE
    undo_tablespace                       string       UNDOTBS1
undo_retention(保持力),10800单位是秒。即3个小时。
修改默认的undo_retention参数设置:
ALTER SYSTEM SET undo_retention=10800 SCOPE=BOTH;
 
三、Oracle误删除表数据后的的快速恢复功能方法(实验):
1、创建一个t表
2、插入数据并commit
3、记录当前时间点
4、delete t表数据
5、通过闪回恢复
 
-------------------------------------------------------------------------------------------
1、创建一个t表
idle> CREATE TABLE t
     (
      ID NUMBER
     )  tablespace users;
Table created.
-------------------------------------------------------------------------------------------
2、插入数据并commit
idle> insert into t values(1);
1 row created.
idle> insert into t values(2);
1 row created.
idle> insert into t values(3);
1 row created.
idle> insert into t values(4);
1 row created.
idle> insert into t values(5);
1 row created.
idle> commit
  2  ;
Commit complete.
-------------------------------------------------------------------------------------------
3、记录当前时间点
SYSDATE
    -------------------
    2013/10/25 15:46:02
-------------------------------------------------------------------------------------------
4、delete t表数据
idle> select * from t;
     ID
    ----------
         3
         4
         5
         1
         2
idle> delete from t;
5 rows deleted.
idle> commit;
Commit complete.
idle> select * from t;
no rows selected
-------------------------------------------------------------------------------------------
5、通过闪回恢复(方法一:)
idle> begin
     dbms_flashback.enable_at_time(to_date('2013/10/25 15:46:02', 'yyyy-mm-dd hh24:mi:ss'));
    end;
    /
PL/SQL procedure successfully completed.
idle> DECLARE r_temp t%ROWTYPE;
    CURSOR c_temp IS SELECT * FROM t;
    BEGIN
    OPEN c_temp;
    dbms_flashback.disable;
    LOOP
    FETCH c_temp INTO r_temp;
    EXIT WHEN c_temp%NOTFOUND;
    insert into t  values (r_temp.id);
    commit;
    END LOOP; 
    CLOSE c_temp; 
    END;
    /
PL/SQL procedure successfully completed.
idle> select * from t;
     ID
    ----------
         3
         4
         5
         1
         2
-------------------------------------------------------------------------------------------
方法二:(timestamp)
idle> delete from t;
5 rows deleted.
idle> commit;
Commit complete.
idle> select * from t;
no rows selected
idle> insert into t
    select * from t as of timestamp to_timestamp('2013/10/25 15:46:02', 'yyyy-mm-dd hh24:mi:ss');
5 rows created.
idle> select * from t;
     ID
     ----------
         1
         2
         3
         4
         5

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29076828/viewspace-1196306/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29076828/viewspace-1196306/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值