sitemap

RSS地图

收藏本站

设为首页

Oracle研究中心

当前位置:Oracle研究中心 > 运维DBA > Oracle性能优化 >

【学习笔记】Oracle 11gR2新特性之Flashback archive data增强笔记

时间:2016-11-21 19:32   来源:Oracle研究中心   作者:网络   点击:

天萃荷净 Oracle研究中心学习笔记:分享一篇关于Oracle数据库11.2.0.1新特性笔记,深入分析11gR2新特性之Flashback archive data增强特性。

本站文章除注明转载外,均为本站原创: 转载自love wife & love life —Roger 的Oracle技术博客
本文链接地址: 11gR2 新特性之一—Flashback archive data增强

该特性是11gR1就引入了,只是在11gR1中限制太多,本文主要是讲解11gR2中关于该特性所增加的一些功能。

SQL> SELECT name,description FROM v$bgprocess WHERE name LIKE 'F%';

NAME  DESCRIPTION
----- ---------------------------------------------
FMON  File Mapping Monitor Process
FBDA  Flashback DATA Archiver Process
FSFP  DATA Guard Broker FSFO Pinger

SQL> CREATE flashback archive test_ht
  2  tablespace "ROGER"
  3  quota 100m
  4  retention 3 DAY
  5  /

Flashback archive created.

SQL> conn roger/roger
Connected.

SQL> CREATE TABLE ht05(id NUMBER PRIMARY KEY,name varchar2(8)) flashback archive test_ht;
TABLE created.

SQL> INSERT INTO ht05 VALUES(1,'aaaa');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(5,'eeee');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(2,'bbbb');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(3,'cccc');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(4,'dddd');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(6,'ffff');
1 ROW created.

SQL> INSERT INTO ht05 VALUES(7,'gggg');
1 ROW created.

SQL> commit;
Commit complete.

SQL> SELECT * FROM ht05 ORDER BY id;

   ID NAME
----- --------
    1 aaaa
    2 bbbb
    3 cccc
    4 dddd
    5 eeee
    6 ffff
    7 gggg

7 ROWS selected.

SQL> GRANT flashback archive administer TO roger;
GRANT succeeded.

如下是摘自官方文档的说明,关于11gR2中新增加的特性:

Oracle Database 11g Release 2 (11.2) users can now use most DDL commands on tables that are
being tracked with Flashback Data Archive. This includes:

Add, Drop, Rename, Modify Column
Drop, Truncate Partition
Rename, Truncate Table
Add, Drop, Rename, Modify Constraint

For more complex DDL (for example, upgrades and split table), the Disassociate and Associate
PL/SQL procedures can be used to temporarily disable Total Recall on specified tables. The
Associate procedure enforces schema integrity after association; the base table and history
table schemas must be the same.

This feature makes it much easier to use the Total Recall option with complex applications
that require the ability to modify the schema.

下面来进行一系列关于上述表述的测试。

'------添加列'

SQL>  ALTER TABLE ht05 ADD (addr varchar2(20));

TABLE altered.

/** alert如下:
Sun Sep 04 01:26:53 2011
Starting background process FBDA
Sun Sep 04 01:26:53 2011
FBDA started with pid=33, OS id=8225 --FBDA进程启动了 */

'------删除列'                                                                                                                                           
SQL> ALTER TABLE ht05 DROP COLUMN addr;

TABLE altered.

'------重命名表名'

SQL> RENAME ht05 TO ht05_old;

TABLE renamed.

SQL> DESC ht05_old

Name                     NULL     TYPE                                                  
------------------------ -------- --------------------------
ID                       NOT NULL NUMBER                  
NAME                              VARCHAR2(8)             

'------修改列'    

SQL> ALTER TABLE ht05_old MODIFY (name varchar2(6));                                                            
TABLE altered.

SQL> SET timing ON
SQL> ALTER TABLE ht05_old MODIFY (Oracleоname varchar2(4));  

Elapsed: 00:00:16.38

'----我靠 这么简单的一个操作需要要16s才能完成。'

'-------重命名列'

SQL> ALTER TABLE ht05_old RENAME COLUMN name TO name_old;
TABLE altered.
Elapsed: 00:00:18.48

'我们来看看正常情况下修改列:'

SQL> CREATE TABLE ht06 AS SELECT * FROM ht05_old;
TABLE created.

SQL> ALTER TABLE ht06 ADD CONSTRAINT pk_ht06 PRIMARY KEY(id);
TABLE altered.

SQL> SELECT COUNT(*) FROM ht06;

  COUNT(*)
----------
         7

SQL>  ALTER TABLE ht06  MODIFY (name varchar2(4));
TABLE altered.

Elapsed: 00:00:00.06

'-- 这个时间跟前面简直没法比'

'#####下面来测试partition table'

SQL> CREATE TABLE ht07 partition BY hash(object_id) partitions 5  AS SELECT * FROM dba_objects;
TABLE created.

SQL> ALTER TABLE ht07 flashback archive test_ht;
TABLE altered.

SQL> ;
  1  SELECT TABLE_OWNER,TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME FROM
  2  dba_tab_partitions WHERE TABLE_OWNER='ROGER'
  3* AND TABLE_NAME='HT07'
SQL> /

TABLE_OWNER     TABLE_NAME      PARTITION_NAME  TABLESPACE_NAME
--------------- --------------- --------------- ---------------
ROGER           HT07            SYS_P21         USERS
ROGER           HT07            SYS_P22         USERS
ROGER           HT07            SYS_P23         USERS
ROGER           HT07            SYS_P24         USERS
ROGER           HT07            SYS_P25         USERS 

SQL> SELECT * FROM dba_flashback_archive_tables;

TABLE_NAME OWNER_NAME     FLASHBACK_ARCHIVE_NAME  ARCHIVE_TABLE_NAME  STATUS
---------- -------------- ----------------------- ------------------- --------
HT05_OLD   ROGER          TEST_HT                 SYS_FBA_HIST_73555  ENABLED
HT07       ROGER          TEST_HT                 SYS_FBA_HIST_73574  ENABLED

SQL> SET timing ON
SQL> ALTER TABLE ht07 TRUNCATE partition SYS_P25;
TABLE truncated.
Elapsed: 00:00:18.23

SQL> ALTER TABLE ht07 DROP partition SYS_P24;
ALTER TABLE ht07 DROP partition SYS_P24
                                *
ERROR at line 1:
ORA-14255: TABLE IS NOT partitioned BY Range, List, Composite Range OR Composite List method

Elapsed: 00:00:06.43

SQL> SET timing off
SQL> CREATE TABLE ht08 partition  BY range(object_id)
  2  (partition ht08_p1 VALUES less than (10000),
  3   partition ht08_p2 VALUES less than (20000),
  4   partition ht08_p3 VALUES less than (30000),
  5   partition ht08_p4 VALUES less than (40000),
  6   partition ht08_p5 VALUES less than (maxvalue)) AS SELECT * FROM ht07 WHERE 1=1;

TABLE created.

SQL> ALTER TABLE ht08  flashback archive test_ht;
TABLE altered.

SQL> SET timing ON
SQL> ALTER TABLE ht08  TRUNCATE partition ht08_p5;
TABLE truncated.
Elapsed: 00:00:24.66

SQL>  ALTER TABLE ht08  DROP partition  ht08_p4;
TABLE altered.
Elapsed: 00:00:19.21 

SQL> ALTER TABLE ht08 ADD CONSTRAINT pk_ht08 PRIMARY KEY(object_id);
TABLE altered.
Elapsed: 00:00:10.61

SQL> ALTER TABLE ht08 DROP CONSTRAINT PK_HT08;
TABLE altered.

Elapsed: 00:00:00.42

SQL> ALTER TABLE ht08 ADD CONSTRAINT pk_ht08 PRIMARY KEY(object_id);
TABLE altered.

Elapsed: 00:00:10.27

SQL> ALTER TABLE ht08 RENAME CONSTRAINT pk_ht08 TO pk_ht08_old;
TABLE altered.

Elapsed: 00:00:00.17

SQL> ALTER TABLE ht08 MODIFY CONSTRAINT disable validate ;
ALTER TABLE ht08 MODIFY CONSTRAINT disable validate
*
ERROR at line 1:
ORA-55610: Invalid DDL statement ON history-tracked TABLE

Elapsed: 00:00:00.05

'-- 从上看,不支持约束的modify操作'  

SQL> ALTER TABLE ht08 split partition ht08_p5 at (40000) INTO (partition HT08_P4,partition HT08_P5);
ALTER TABLE ht08 split partition ht08_p5 at (40000) INTO (partition HT08_P4,partition HT08_P5)
*
ERROR at line 1:
ORA-55610: Invalid DDL statement ON history-tracked TABLE

Elapsed: 00:00:00.12
SQL> ALTER TABLE ht08 ADD partition HT08_P4 VALUES less than (40000);
ALTER TABLE ht08 ADD partition HT08_P4 VALUES less than (40000)
*
ERROR at line 1:
ORA-55610: Invalid DDL statement ON history-tracked TABLE

Elapsed: 00:00:00.13  

'-- 从上看也不支持分区表的add和split操作。'

最后根据前面所做的测试,进行一下简单的总结:
1. 支持表列的add,rename,drop以及modify操作;
2. 支持分区表的truncate,drop操作(仅限于rang分区、list分区以及rang-list、list_rang复合分区),
不支持hash分区表的drop操作;
3. 支持约束的add,rename,drop操作,不支持modify操作。

总的来说,部分测试跟官方文档的描述有出入,另外就是大家可以也发现了,那就是如果使用了
flashback archive data特性,那么几乎所有ddl操作都非常慢之慢,简直是慢的出奇。
我们知道ddl也会产生锁,那么对于高并发负载较高的系统来讲,如此之慢的操作,我想有点够呛的。
最后补充一点的是,为啥oracle的官方文档经常跟实际测试有出入呢?欺骗大众吗?

--------------------------------------ORACLE-DBA----------------------------------------

最权威、专业的Oracle案例资源汇总之【学习笔记】Oracle 11gR2新特性之Flashback archive data增强笔记

本文由大师惜分飞原创分享,网址:http://www.oracleplus.net/arch/1304.html

Oracle研究中心

关键词:

11gR2新特性之Flashback archive data

Oracle 11G新特性flashback深入研究笔记