11g r2中对闪回数据归档的增强

11g r1中引入了闪回数据归档新特性,其工作原理是为针对启用了归档方式的表,FBDA进程将创建对应于该表的内部历史表。历史表将拥有原始表的所有列加上某些时间戳列以便跟踪事务处理的变化,具体如下:

SQL> desc SYS_FBA_HIST_75718;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 RID                                                VARCHAR2(4000)
 STARTSCN                                           NUMBER
 ENDSCN                                             NUMBER
 XID                                                RAW(8)
 OPERATION                                          VARCHAR2(1)
 T1                                                 NUMBER(38)
 T2                                                 VARCHAR2(20)
/* 注意其中T1,T2为原始表上的应用数据列 */


当更新或删除被跟踪的原始表的行记录时,FBDA进程将为归档标记事务处理和相应的撤销记录。历史表中将记录所有delete或update事务处理之前的行的前镜像。但如果是insert事务的话则不引起任何记录被添加到历史表中,因为这一新行没有前历史数据。
如同10g中的flashback query一样闪回数据归档依赖于撤销数据,FBDA进程会在系统确定的时间段内被唤醒(默认为5分钟),并将标记了的事务处理的撤销数据复制到历史表中。因此,当一个表发生修改时,变化不会立即体现在历史表中,需要几分钟(>5分钟)时间才能在历史表中看到。当数据库正在产生大量的撤销数据,则它将调整FBDA后台进程的睡眠时间,使用它能够快速地从数据库高速缓冲中读取到撤销数据。在FBDA进程在历史表中完成记录前事务处理(撤销)数据之前,数据库不会重用标记为归档的撤销记录。仅当FBDA进程完成历史记录,这些撤销段才被标示为可再次循环使用。

The ‘fbda’ process intelligently adjusts its sleep interval based on the system undo generation
rate. As transaction activity increases, ‘fbda’ automatically reduces its sleep interval from the
default of 5 minutes. For better performance, ‘fbda’ also adjusts its sleep time in order to
maximize undo data reads from the buffer cache. In addition, Flashback Data Archive uses an
internal partitioning scheme for all the historical data for better peformance, and it uses table
compression to reduce the storage footprint of the historical data.

11g r1中针对启用闪回数据归档的表不能实施truncate,alter table add column等操作,否则会报ORA-55610错误:

55610, 00000, "Invalid DDL statement on history-tracked table"
// *Cause: An attempt was made to perform certain DDL statement that is 
//         disallowed on tables that are enabled for Flashback Archive.
// *Action: No action required.
//

在11g r2中闪回数据归档特性得到了加强,现在支持对被跟踪表的部分DDL操作,最有用的可能还是truncate和alter table操作:

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SQL>  create table orz (t1 int) flashback archive fba;
Table created.


SQL> col owner_name for a15;
SQL> col table_name for a10;
SQL> col flashback_archive_name for a15;
SQL> set linesize 200;

/* 可以看到这里历史记录表式SYS_FBA_HIST_75744,这些历史记录表默认均采用分区且压缩的特性 */

SQL> select * from dba_flashback_archive_tables where table_name = 'ORZ';

TABLE_NAME OWNER_NAME      FLASHBACK_ARCHI ARCHIVE_TABLE_NAME                                    STATUS
---------- --------------- --------------- ----------------------------------------------------- -------------
ORZ        MACLEAN         FBA             SYS_FBA_HIST_75744                                    ENABLED

/* 在正式产生闪回归档前历史表"并不存在"  */

SQL> select * from dba_objects where owner='SYS_FBA_HIST_75744';
no rows selected


SQL> insert into orf values(1);

1 row created.

SQL> commit;

Commit complete.


SQL> set timing on;

/* 很小的一个表,truncate却花了10s */
SQL> truncate table orz;
Table truncated.
Elapsed: 00:00:10.02


SQL> col object_name for a20;
SQL> select object_name,subobject_name,object_type from dba_objects where object_name='SYS_FBA_HIST_75744';

OBJECT_NAME          SUBOBJECT_NAME                 OBJECT_TYPE
-------------------- ------------------------------ -------------------
SYS_FBA_HIST_75744   HIGH_PART                      TABLE PARTITION
SYS_FBA_HIST_75744                                  TABLE

SQL> col rid for a25;
SQL> col t1 for 99;
SQL> select * from maclean.SYS_FBA_HIST_75744;

RID                         STARTSCN     ENDSCN XID              O  T1
------------------------- ---------- ---------- ---------------- - ---
AAASfgAAEAAAAImAAA           1066139    1066237 08001F0028030000 I   1

SQL> insert into orz select object_id from dba_objects;
73064 rows created.

SQL> commit;
Commit complete.

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
    1072650

SQL> truncate table orz;
Table truncated.


SQL> select count(*) from maclean.SYS_FBA_HIST_75744;

  COUNT(*)
----------
     73065

SQL> select count(*) from orz;

  COUNT(*)
----------
         0

SQL> select count(*) from orz as of scn 1072650;
  COUNT(*)
----------
     73064



/* flashback archiver闪回数据归档加强了flashback query闪回查询的功能,这对那些需要检查数据全部历史的应用来说是一个惊喜!*/

/* 遗憾的是闪回数据归档并非需要对跟踪表做任意类型的DDL操作,很明显drop就不行;当然针对drop我们可以用到其他的闪回技术 */

SQL> drop table orz;
drop table orz
           *
ERROR at line 1:
ORA-55610: Invalid DDL statement on history-tracked table

to be continued…………

关注dbDao.com的新浪微博

扫码关注dbDao.com 微信公众号:

Speak Your Mind

TEL/電話+86 13764045638
Email service@parnassusdata.com
QQ 47079569