码迷,mamicode.com
首页 > 数据库 > 详细

Oracle12C闪回技术

时间:2018-01-17 16:02:45      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:created   授权   mil   timestamp   query   false   ash   integer   line   

1.Oracle Flashback Query --闪回查询
ORACLE根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回。
Flashback query(闪回查询)前提:
sys@CLONEPDB_PLUGPDB> show parameter undo

NAME TYPE VALUE


temp_undo_enabled boolean FALSE
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
其中undo_management = auto,设置自动管理
Undo_retention = n(秒),设置决定undo最多的保存时间,其值越大,就需要越多的undo表空间的支持。修改undo_retention的命令如下:
sys@CLONEPDB_PLUGPDB> alter system set undo_retention = 3600;

System altered.

Elapsed: 00:00:00.06
sys@CLONEPDB_PLUGPDB> show parameter undo

NAME TYPE VALUE


temp_undo_enabled boolean FALSE
undo_management string AUTO
undo_retention integer 3600
undo_tablespace string UNDOTBS1
获取数据删除前的一个时间点或scn,如下:
sys@CLONEPDB_PLUGPDB> select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘) time, to_char(dbms_flashback.get_system_change_number) scn from dual;

TIME SCN


2018-01-17 14:16:00 5409876

Elapsed: 00:00:00.11
sys@CLONEPDB_PLUGPDB> conn scott/tiger@clonepdb_plug
Connected.
scott@CLONEPDB_PLUGPDB> select count(*) from emp;

COUNT(*)

    12

Elapsed: 00:00:00.03
scott@CLONEPDB_PLUGPDB> delete from emp;

12 rows deleted.

Elapsed: 00:00:00.04
scott@CLONEPDB_PLUGPDB> commit;

Commit complete.

Elapsed: 00:00:00.01
scott@CLONEPDB_PLUGPDB> select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘) time, to_char(dbms_flashback.get_system_change_number) scn from dual;
select to_char(sysdate, ‘yyyy-mm-dd hh24:mi:ss‘) time, to_char(dbms_flashback.get_system_change_number) scn from dual
*
ERROR at line 1:
ORA-00904: DBMS_FLASHBACK: invalid identifier

Elapsed: 00:00:00.02
查询该时间点(或scn)的数据,如下:
scott@CLONEPDB_PLUGPDB> select count(*) from emp;

COUNT(*)

     0

Elapsed: 00:00:00.01
scott@CLONEPDB_PLUGPDB> select from emp as of timestamp to_timestamp(‘2018-01-17 14:16:00‘, ‘yyyy-mm-dd hh24:mi:ss‘);--或select from emp as of scn 5409876;

 EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO

  7369 SMITH      CLERK           7902 1980-12-17 00:00:00        800                    20
  7499 ALLEN      SALESMAN        7698 1981-02-20 00:00:00       1600        300         30
  7521 WARD       SALESMAN        7698 1981-02-22 00:00:00       1250        500         30
  7566 JONES      MANAGER         7839 1981-04-02 00:00:00       2975                    20
  7654 MARTIN     SALESMAN        7698 1981-09-28 00:00:00       1250       1400         30
  7698 BLAKE      MANAGER         7839 1981-05-01 00:00:00       2850                    30
  7782 CLARK      MANAGER         7839 1981-06-09 00:00:00       2450                    10
  7839 KING       PRESIDENT            1981-11-17 00:00:00       5000                    10
  7844 TURNER     SALESMAN        7698 1981-09-08 00:00:00       1500          0         30
  7900 JAMES      CLERK           7698 1981-12-03 00:00:00        950                    30
  7902 FORD       ANALYST         7566 1981-12-03 00:00:00       3000                    20

 EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO

  7934 MILLER     CLERK           7782 1982-01-23 00:00:00       1300                    10

12 rows selected.

Elapsed: 00:00:00.15
恢复
scott@CLONEPDB_PLUGPDB> insert into emp (select * from emp as of scn 5409876);--也可以用时间

12 rows created.

Elapsed: 00:00:00.04
scott@CLONEPDB_PLUGPDB> commit;

Commit complete.

Elapsed: 00:00:00.01
scott@CLONEPDB_PLUGPDB> select count(*) from emp;

COUNT(*)

    12
            局限:

| 不能Falshback到5天以前的数据。

| 闪回查询无法恢复到表结构改变之前,因为闪回查询使用的是当前的数据字典。

| 受到undo_retention参数的影响,对于undo_retention之前的数据,Flashback不保证能Flashback成功。

| 对drop,truncate等不记录回滚的操作,不能恢复。

| 普通用户使用dbms_flashback包,必须通过管理员授权。
2.闪回

Oracle12C闪回技术

标签:created   授权   mil   timestamp   query   false   ash   integer   line   

原文地址:http://blog.51cto.com/shurk/2062041

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!