UNDO表空间记录的回滚信息虽然可以提供回闪查询,但时间久了,这些信息会被覆盖掉,其实只要事务一提交,他们就变成可覆盖的对象了,所
flashback data archive(闪回数据归档)
undo表空间记录的回滚信息虽然可以提供回闪查询,但时间久了,这些信息会被覆盖掉,其实只要事务一提交,他们就变成可覆盖的对象了,所以经常在做回闪查询时,我们会因为找不到undo block而收到1555错误,11g里面引入了flashback data archive ,他用于存储数据的所有改变,时间由你自己设定,消耗的是更多的磁盘空间,现在来看下这个特性。
一、创建闪回数据归档
1、为了创建闪回数据归档,必须拥有dba角色或拥有系统权限flashback archive administer。
sys@mydb> select * from dba_sys_privs where privilege like '%flash%';
grantee privilege adm
------------------------------ ---------------------------------------- ---
sys flashback any table no
dba flashback any table yes
sys flashback archive administer no
dba flashback archive administer yes
sys@mydb> grant flashback archive administer to gyj;
grant succeeded.
2、创建表空间
sys@mydb> create tablespace flash_tbs1 datafile '/u01/app/oracle/oradata/mydb/flash_tbs1.dbf' size 20480m;
tablespace created.
3、创建闪回归档
sys@mydb> create flashback archive flash1 tablespace flash_tbs1 quota 1024m retention 5 year;
flashback archive created.
二、更改闪回数据归档
sys@mydb> alter flashback archive flash1 set default;
flashback archive altered.
sys@mydb> alter flashback archive flash1 add tablespace tp1; --添加表空间
flashback archive altered.
sys@mydb> alter flashback archive flash1 remove tablespace tp1;--删除表空间
flashback archive altered.
sys@mydb> alter flashback archive flash1 modify tablespace flash_tbs1 quota 2048m;--添加配额
flashback archive altered.
sys@mydb> alter flashback archive flash1 modify retention 3 year;
flashback archive altered.
sys@mydb> alter flashback archive flash1 purge all; -- 清除所有
flashback archive altered.
sys@mydb> alter flashback archive flash1 purge before timestamp (systimestamp - interval '2' day);--清除2天前的
flashback archive altered.
sys@mydb> alter flashback archive flash1 purge before scn 123344;
flashback archive altered.
三、启用和禁用闪回数据归档
1、在建表的同时就启用表的闪回日志
gyj@mydb> create table t1(id int,name varchar2(10)) flashback archive flash1;
table created.
2、也可以在建表后,再启用表的闪回日志
alter table t1 flashback archive;--为表启用闪回数据归档,没指定表示使用数据库默认的
alter table t1 flashback archive flash1; ;--为表启用闪回数据归档,指定在特定的闪回数据归档中存储表的变化
3、数据库将把t1表的数据归档到默认的闪回数据归档中
gyj@mydb> select * from dba_flashback_archive_tables;
table_name owner_name flashback_archive_name archive_table_name status
----------- ----------- ---------------------- ---------------- -------------
t1 gyj flash1 sys_fba_hist_17877 enabled
4、在使用闪回数据归档前,,必须设置默认闪回数据归档
gyj@mydb> select flashback_archive_name,status from dba_flashback_archive;
flashback_archive_name status ------------------------------------
flash1 default
5、禁用闪回数据归档
gyj@mydb> alter table t1 no flashback archive;
table altered.

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号