1.创建表空间
SQL> create tablespace fda_tbs datafile '/u01/app/oracle/oradata/orcl/fda_tbs01.dbf' size 100m;
Tablespace created.
2.管理FDA
创建FDA
SQL> create flashback archive fda1 tablespace fda_tbs retention 1 year;
删除FDA
SQL> drop flashback archive fda1;
添加表空间
SQL> alter flashback archive fda1 add tablespace fda_tbs2;
移除表空间
SQL> alter flashback archive fda1 remove tablespace fda_tbs2;
修改表空间配额
SQL> alter flashback archive fda1 modify tablespace fda_tbs quota 100m;
修改保留时间
SQL> alter flashback archive fda1 modify retention 2 year;
设置默认闪回归档
SQL> alter flashback archive fda1 set default;
清除FDA里的数据
全部清除
SQL> alter flashback archive fda1 purge all;
基于时间清除
SQL> alter flashback archive fda1 purge before timestamp(systimestamp-interval '2' day);
基于SCN清除
SQL> alter flashback archive fda1 purge before scn 1000893;
3.使用FDA
授权
SQL> grant flashback archive administer to scott;----创建闪回归档的权限
SQL> grant flashback archive on fda1 to scott; ----使用闪回归档的权限
启用闪回归档
创建表时启用
SQL> create table t (id number,name varchar2(10)) flashback archive fda1;
修改现有的表启用
SQL> alter table t1 flashback archive fda1;
关闭表上的闪回归档
SQL> alter table t no flashback archive;
数据字典
dba/user_flashback_archive_tables
dba/user_flashback_archive
dba_flashback_archive_ts
通过查询数据字典
可以看到
SQL> select TABLE_NAME,ARCHIVE_TABLE_NAME from user_flashback_archive_tables;
TABLE_NAME ARCHIVE_TABLE_NAME
------------------------------ -----------------------------------------------------
T SYS_FBA_HIST_74699
用来记录T表闪回日志的闪回归档表叫SYS_FBA_HIST_74699
FDBA进程,异步的把UNDO的数据,定期的复制到该表中,默认时间间隔是5分钟,自动管理
所以,我们创建好了T以后,不会立即出现对应的闪回归档表
4.对DDL的支持
原生的DDL支持
默认支持的DDL有
增加、删除、修改列
删除和截断分区
表的截断和重命名
创建 T表,使用闪回归档
SQL> alter table t flashback archive fda1;
SQL> insert into t select * from emp;
SQL> commit;
SQL> select * from t;
28 rows selected.
对表进行DDL操作----truncate
SQL> truncate table t;
查看,当前生成了闪回归档表
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
SYS_FBA_DDL_COLMAP_74709 TABLE
SYS_FBA_HIST_74709 TABLE
SYS_FBA_TCRV_74709 TABLE
T TABLE
对T表进行闪回版本查询,可以查到数据
SQL> select * from t versions between scn minvalue and maxvalue;
28 rows selected.
再次执行DDL---删除列
SQL> alter table t drop column comm;
对T再次进行闪回版本查询,还是可以查到数据
SQL> select * from t versions between scn minvalue and maxvalue;
28 rows selected.
SQL> select * from t;
no rows selected
使用分离和重新关联的方式,使闪回归档支持所有的DDL
创建表T,使用闪回归档
SQL> create table t as select * from dept;
SQL> alter table t flashback archive fda1;
发现当前,闪回归档表还未生成,FBDA是异步去读取和保存UNDO数据的
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
BONUS TABLE
DEPT TABLE
EMP TABLE
SALGRADE TABLE
T TABLE
通过数据字典,查询T表所使用的闪回归档表是SYS_FBA_HIST_74718
SQL> select TABLE_NAME,ARCHIVE_TABLE_NAME from user_flashback_archive_tables;
TABLE_NAME ARCHIVE_TABLE_NAME
------------------------------ -----------------------------------------------------
T SYS_FBA_HIST_74718
使用SYS对SCOTT授权,使SCOTT可以执行DBMS_FLASHBACK_ARCHIVE包
conn / as sysdba
SQL> grant execute on dbms_flashback_archive to scott;
Grant succeeded.
使用scott,把T表与该表的闪回归档表,进行分离操作
SQL> exec dbms_flashback_archive.disassociate_fba('scott','t');
PL/SQL procedure successfully completed.
在T表,进行DDL操作
修改字段名
SQL> alter table t rename column dname to deptname;
SQL> desc t
Name Null? Type
------------------------------------------------- -------- ---------------------------------
DEPTNO NUMBER(2)
DEPTNAME VARCHAR2(14)
LOC VARCHAR2(13)
闪回归档表,当前未被修改,字段名,还保持和T表未修改前一致
导致闪回归档表与T表,字段名称的不一致
SQL> desc SYS_FBA_HIST_74718
Name Null? Type
------------------------------------------------- -------- ---------------------------------
RID VARCHAR2(4000)
STARTSCN NUMBER
ENDSCN NUMBER
XID RAW(8)
OPERATION VARCHAR2(1)
DEPTNO NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
尝试重新关联基表T与该表的闪回归档表,失败
SQL> exec dbms_flashback_archive.reassociate_fba('scott','t');
BEGIN dbms_flashback_archive.reassociate_fba('scott','t'); END;
*
ERROR at line 1:
ORA-55636: Flashback Data Archive enabled table "SCOTT"."T" has different definition from
its history table
ORA-06512: at "SYS.DBMS_FLASHBACK_ARCHIVE", line 17
ORA-06512: at line 1
报错提示,闪回归档表与基表,结构不致
重新分离
SQL> exec dbms_flashback_archive.disassociate_fba('scott','t');
对闪回归档表也应用相同的DDL操作
SQL> alter table SYS_FBA_HIST_74718 rename column dname to deptname;
此时,两个表,关于表字段名的信息一致了
SQL> desc SYS_FBA_HIST_74718
Name Null? Type
------------------------------------------------- -------- ---------------------------------
RID VARCHAR2(4000)
STARTSCN NUMBER
ENDSCN NUMBER
XID RAW(8)
OPERATION VARCHAR2(1)
DEPTNO NUMBER(2)
DEPTNAME VARCHAR2(14)
LOC VARCHAR2(13)
SQL> desc t
Name Null? Type
------------------------------------------------- -------- ---------------------------------
DEPTNO NUMBER(2)
DEPTNAME VARCHAR2(14)
LOC VARCHAR2(13)
再次尝试重新关联,成功
SQL> exec dbms_flashback_archive.reassociate_fba('scott','t');
通过分离,在基表和闪回归档表上,分别应用相同的DDL,再重新关联的方式,理论上可以使闪回归档支持所有的DDL操作。
来源:51CTO
作者:m18994118189
链接:https://blog.csdn.net/m18994118189/article/details/100182751