本文主要是介绍闪回数据归档实验(Flashback Data Archive),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
闪回数据归档实验(Flashback Data Archive)使用环境
--11g开始有此功能
--12c需要数据库没有插件库或版本为12.1.0.2及以后的版本
实验--创建表空间用来存放闪回数据归档
SYS@PROD1> create tablespace fda datafile '/u01/app/oracle/oradata/PROD1/fda01.dbf' size 10m autoextend on;Tablespace created.--建立闪回数据归档,并指定保留时间
SYS@PROD1> create flashback archive fda tablespace fda quota 10m retention 1 month;Flashback archive created.--赋予权限,可以通过sys直接赋予表FDA权限或者给予用户FDA权限
SYS@PROD1> alter table scott.emp flashback archive fda;Table altered.SYS@PROD1> grant flashback archive administer to scott;Grant succeeded.--通过视图查看是否打开闪回视图归档
SCOTT@PROD1> desc user_flashback_archive_tables Name Null? Type----------------------------------------------------- -------- ------------------------------------TABLE_NAME NOT NULL VARCHAR2(30)OWNER_NAME NOT NULL VARCHAR2(30)FLASHBACK_ARCHIVE_NAME NOT NULL VARCHAR2(255)ARCHIVE_TABLE_NAME VARCHAR2(53)STATUS VARCHAR2(13)SCOTT@PROD1> select * from user_flashback_archive_tables where table_name='EMP';TABLE_NAME OWNER_NAME
------------------------------ ------------------------------
FLASHBACK_ARCHIVE_NAME
----------------------------------------------------------------------------------------------------
ARCHIVE_TABLE_NAME STATUS
----------------------------------------------------- -------------
EMP SCOTT
FDA
SYS_FBA_HIST_75315 ENABLED--即使截断表也能闪回查询记录
SCOTT@PROD1> select * from emp as of timestamp sysdate-1/1440;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------7934 MILLER CLERK 7782 23-JAN-82 1301 107902 FORD ANALYST 7566 03-DEC-81 3001 207900 JAMES CLERK 7698 03-DEC-81 951 307876 ADAMS CLERK 7788 23-MAY-87 1101 207844 TURNER SALESMAN 7698 08-SEP-81 1501 0 307839 KING PRESIDENT 17-NOV-81 5001 107788 SCOTT ANALYST 7566 19-APR-87 3001 207782 CLARK MANAGER 7839 09-JUN-81 2451 107698 BLAKE MANAGER 7839 01-MAY-81 2851 307654 MARTIN SALESMAN 7698 28-SEP-81 1251 1400 307566 JONES MANAGER 7839 02-APR-81 2976 207521 WARD SALESMAN 7698 22-FEB-81 1251 500 307499 ALLEN SALESMAN 7698 20-FEB-81 1601 300 307369 SMITH CLERK 7902 17-DEC-80 801 2014 rows selected.SCOTT@PROD1> truncate table emp;Table truncated.SCOTT@PROD1> select * from emp as of timestamp sysdate-1/1440;EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------7934 MILLER CLERK 7782 23-JAN-82 1301 107902 FORD ANALYST 7566 03-DEC-81 3001 207900 JAMES CLERK 7698 03-DEC-81 951 307876 ADAMS CLERK 7788 23-MAY-87 1101 207844 TURNER SALESMAN 7698 08-SEP-81 1501 0 307839 KING PRESIDENT 17-NOV-81 5001 107788 SCOTT ANALYST 7566 19-APR-87 3001 207782 CLARK MANAGER 7839 09-JUN-81 2451 107698 BLAKE MANAGER 7839 01-MAY-81 2851 307654 MARTIN SALESMAN 7698 28-SEP-81 1251 1400 307566 JONES MANAGER 7839 02-APR-81 2976 207521 WARD SALESMAN 7698 22-FEB-81 1251 500 307499 ALLEN SALESMAN 7698 20-FEB-81 1601 300 307369 SMITH CLERK 7902 17-DEC-80 801 2014 rows selected.--直接插入就可恢复
SCOTT@PROD1> insert into emp select * from emp as of timestamp sysdate-1;14 rows created.--一旦表被放到FDA,将不允许直接把表删除,除非关闭FDA
SCOTT@PROD1> drop table emp;
drop table emp*
ERROR at line 1:
ORA-55610: Invalid DDL statement on history-tracked tableSCOTT@PROD1> alter table emp no flashback archive;Table altered.SCOTT@PROD1> drop table emp;Table dropped.
这篇关于闪回数据归档实验(Flashback Data Archive)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!