Oracle12C闪回技术

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle12C闪回技术相关的知识,希望对你有一定的参考价值。

1.Oracle Flashback Query --闪回查询
ORACLE根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回。
Flashback query(闪回查询)前提:
[email protected]_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的命令如下:
[email protected]_PLUGPDB> alter system set undo_retention = 3600;

System altered.

Elapsed: 00:00:00.06
[email protected]_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,如下:
[email protected]_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
[email protected]_PLUGPDB> conn scott/[email protected]_plug
Connected.
[email protected]_PLUGPDB> select count(*) from emp;

COUNT(*)

    12

Elapsed: 00:00:00.03
[email protected]_PLUGPDB> delete from emp;

12 rows deleted.

Elapsed: 00:00:00.04
[email protected]_PLUGPDB> commit;

Commit complete.

Elapsed: 00:00:00.01
[email protected]_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)的数据,如下:
[email protected]_PLUGPDB> select count(*) from emp;

COUNT(*)

     0

Elapsed: 00:00:00.01
[email protected]_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
恢复
[email protected]_PLUGPDB> insert into emp (select * from emp as of scn 5409876);--也可以用时间

12 rows created.

Elapsed: 00:00:00.04
[email protected]_PLUGPDB> commit;

Commit complete.

Elapsed: 00:00:00.01
[email protected]_PLUGPDB> select count(*) from emp;

COUNT(*)

    12
            局限:

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

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

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

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

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

以上是关于Oracle12C闪回技术的主要内容,如果未能解决你的问题,请参考以下文章

Oracle闪回技术详解

Oracle闪回技术详解

Oracle-闪回技术

Oracle闪回技术--更新ing

Oracle 闪回 找回数据的实现方法

Oracle闪回技术