[20120813]11GR2下flashback data archive的测试.txt

[20120813]11GR2下flashback data archive的测试.txt

        oracle 11GR2有一个新特性,就是flashback data archive,就是通过一个表空间记录表的一些变化,查询历史数据.自己知道这个特性,从来
也没有测试过.实际上这个就是flashback table的扩展(个人认为)!.

测试如下:

1.测试环境:

SQL> select * from v$version ;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--建立表空间,并且flashback archive保留1年.
create tablespace fratable datafile '/u01/app/oracle11g/oradata/test/fratable01.dbf' size 100M;
create flashback archive fra_1year tablespace fratable retention 1 year;
2.建立测试表
create table nofra (id number, ins_date date, ins_scn number);
create table   fra   (id number, ins_date date, ins_scn number);
insert into  nofra select 1,sysdate,current_scn from v$database ;
insert into    fra select 101,sysdate,current_scn from v$database ;
commit;
SQL> select * from nofra ;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
         1 2012-08-13 11:22:19   16006875
SQL> select * from fra ;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       101 2012-08-13 11:22:19   16006889

3.开始测试:

alter table fra flashback archive fra_1year;
SQL> column x new_value x format a30
SQL> select sysdate x from dual;
X
------------------------------
2012-08-13 11:28:45

--删除了nofra表记录
delete from nofra;
commit;
SQL> select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from nofra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
         1 2012-08-13 11:22:19   16006875
--删除了fra表记录
delete from fra;
commit;
SQL> select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from fra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       101 2012-08-13 11:22:19   16006889

--这个受undo的影响,我这里是测试环境,估计要等上一阵子,下午再测!
--解决方法是切换undo,删除旧undo,或者建立一个小的undo并且不扩展.做一些大事务就覆盖原来的undo了.

SQL> show parameter undo
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------------------------------------
undo_management                      string      AUTO
undo_retention                       integer     900
undo_tablespace                      string      UNDOTBS1
4.看看执行计划如何!
SQL>  select * from nofra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss');
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
         1 2012-08-13 11:22:19   16006875
SQL> @dpc
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  d93pfbuxp0n5c, child number 7
-------------------------------------
 select * from nofra as of timestamp to_timestamp('2012-08-13
11:28:45','yyyy-mm-dd:hh24:mi:ss')
Plan hash value: 1697631366
---------------------------------------------------------
| Id  | Operation         | Name  | E-Rows | Cost (%CPU)|
---------------------------------------------------------
|   0 | SELECT STATEMENT  |       |        |     2 (100)|
|   1 |  TABLE ACCESS FULL| NOFRA |     82 |     2   (0)|
---------------------------------------------------------
Note
-----
   - Warning: basic plan statistics not available. These are only collected when:
       * hint 'gather_plan_statistics' is used for the statement or
       * parameter 'statistics_level' is set to 'ALL', at session or system level

20 rows selected.
SQL>  select * from fra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss');
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       101 2012-08-13 11:22:19   16006889
SQL> @dpc
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  dqqz4d9kzjmxj, child number 5
-------------------------------------
 select * from fra as of timestamp to_timestamp('2012-08-13
11:28:45','yyyy-mm-dd:hh24:mi:ss')
Plan hash value: 3129699971
----------------------------------------------------------------------------------------------------------
| Id  | Operation                 | Name                | E-Rows | Cost (%CPU)|  OMem |  1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |                     |        |    13 (100)|       |       |          |
|   1 |  VIEW                     |                     |     21 |    13   (8)|       |       |          |
|   2 |   UNION-ALL               |                     |        |            |       |       |          |
|*  3 |    FILTER                 |                     |        |            |       |       |          |
|   4 |     PARTITION RANGE SINGLE|                     |      1 |     3   (0)|       |       |          |
|*  5 |      TABLE ACCESS FULL    | SYS_FBA_HIST_104229 |      1 |     3   (0)|       |       |          |
|*  6 |    FILTER                 |                     |        |            |       |       |          |
|*  7 |     HASH JOIN OUTER       |                     |     20 |    10  (10)|   823K|   823K|  189K (0)|
|*  8 |      TABLE ACCESS FULL    | FRA                 |     20 |     6   (0)|       |       |          |
|*  9 |      TABLE ACCESS FULL    | SYS_FBA_TCRV_104229 |      1 |     3   (0)|       |       |          |
----------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   3 - filter("TIMESTAMP_TO_SCN"(TIMESTAMP' 2012-08-13 11:28:45.000000000')
   5 - filter(("ENDSCN""TIMESTAMP_TO_SCN"(TIMESTAMP' 2012-08-13
              11:28:45.000000000') AND ("STARTSCN" IS NULL OR "STARTSCN"
              2012-08-13 11:28:45.000000000'))))
   6 - filter(("STARTSCN"
              "STARTSCN" IS NULL))
   7 - access("T".ROWID=CHARTOROWID("RID"))
   8 - filter("T"."VERSIONS_STARTSCN" IS NULL)
   9 - filter((("ENDSCN" IS NULL OR "ENDSCN">16393765) AND ("STARTSCN" IS NULL OR
              "STARTSCN"
Note
-----
   - dynamic sampling used for this statement (level=2)
   - Warning: basic plan statistics not available. These are only collected when:
       * hint 'gather_plan_statistics' is used for the statement or
       * parameter 'statistics_level' is set to 'ALL', at session or system level

43 rows selected.

select table_name from dba_tables  where tablespace_name='FRATABLE';
TABLE_NAME
------------------------------
SYS_FBA_DDL_COLMAP_104229
SYS_FBA_TCRV_104229
以及一个分区表 SYS_FBA_HIST_104229.

5.做一些DDL操作看看.

SQL> insert into    fra select 102,sysdate,current_scn from v$database ;
1 row created.
SQL> insert into   nofra select 2,sysdate,current_scn from v$database ;
1 row created.
SQL> commit ;
Commit complete.
SQL> select * from nofra ;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
         2 2012-08-13 15:34:26   16406037
SQL> select * from fra ;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       102 2012-08-13 15:34:18   16406033
alter table nofra add (pad  varchar2(32));
alter table   fra add (pad  varchar2(32));
SQL> select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from nofra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
         1 2012-08-13 11:22:19   16006875
SQL> select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from fra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       101 2012-08-13 11:22:19   16006889

--查询历史数据正常!        不过多了1个PAD字段(原来没有).

--删除字段看看!

SQL> alter table nofra drop column pad;
Table altered.
SQL> alter table fra drop column pad;
Table altered.
SQL> select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from nofra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from nofra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
select * from nofra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed
SQL> select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from fra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       101 2012-08-13 11:22:19   16006889

--表nofra删除了字段,出现ORA-01466: unable to read data - table definition has changed.
--而表fra字段我做了add再delete.查询这个时间点,应该还没有pad字段.看来oracle还是存在一些问题.

SQL> column type format a30
SQL> column HISTORICAL_COLUMN_NAME format a30
SQL> column column_name format a30
SQL> select * from SYS_FBA_DDL_COLMAP_104229;
  STARTSCN     ENDSCN XID              O COLUMN_NAME                    TYPE                           HISTORICAL_COLUMN_NAME
---------- ---------- ---------------- - ------------------------------ ------------------------------ ------------------------------
  16406145   16406275                    D_16406275_PAD                 VARCHAR2(32)                   PAD
  16006837                               ID                             NUMBER                         ID
  16006837                               INS_DATE                       DATE                           INS_DATE
  16006837                               INS_SCN                        NUMBER                         INS_SCN

--oracle有点问题,startscn=16406145仅仅是插入字段pad的scn,ENDSCN=16406275是删除字段pad.记录的仅仅是scn,而不包括对应的时间点.
--如果查询当时的scn应该没有pad字段.

SQL> select * from fra as of scn  16006889;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       101 2012-08-13 11:22:19   16006889

--查询scn再建表以前或者时间呢时间很久呢?不知道这种情况算bug吗?不知道scn小到一定程度又可以查询.

SQL> select * from fra as of scn   880;
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       101 2012-08-13 11:22:19   16006889

SQL> select * from fra as of timestamp to_timestamp('2012-08-01 11:22:19','yyyy-mm-dd:hh24:mi:ss');
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       101 2012-08-13 11:22:19   16006889

--查询scn在SYS_FBA_DDL_COLMAP_104229记录的scn.

SQL> select * from fra as of scn   16006837;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       101 2012-08-13 11:22:19   16006889
SQL> select * from fra as of scn   16006836;
select * from fra as of scn   16006836
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed

6.做一个truncate看看.

SQL> column y new_value y format a30
SQL> select sysdate y,current_scn from v$database ;
Y                              CURRENT_SCN
------------------------------ -----------
2012-08-13 16:09:29               16407378
SQL> truncate table nofra;
Table truncated.
SQL> truncate table fra;
Table truncated.
--注:truncate 表fra有点慢!
SQL> select * from nofra as of timestamp to_timestamp('&y','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from nofra as of timestamp to_timestamp('&y','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from nofra as of timestamp to_timestamp('2012-08-13 16:09:29','yyyy-mm-dd:hh24:mi:ss')
select * from nofra as of timestamp to_timestamp('2012-08-13 16:09:29','yyyy-mm-dd:hh24:mi:ss')
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed

SQL> select * from fra as of timestamp to_timestamp('&y','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from fra as of timestamp to_timestamp('&y','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from fra as of timestamp to_timestamp('2012-08-13 16:09:29','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       102 2012-08-13 15:34:18   16406033
SQL> select * from fra as of  scn  16407378;
        ID INS_DATE               INS_SCN
---------- ------------------- ----------
       102 2012-08-13 15:34:18   16406033
SQL> select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss');
old   1: select * from fra as of timestamp to_timestamp('&x','yyyy-mm-dd:hh24:mi:ss')
new   1: select * from fra as of timestamp to_timestamp('2012-08-13 11:28:45','yyyy-mm-dd:hh24:mi:ss')
        ID INS_DATE               INS_SCN PAD
---------- ------------------- ---------- --------------------------------
       101 2012-08-13 11:22:19   16006889

--时间点X,Y都可以查询.不过truncate fra表确实很慢.

SQL> select * from fra;
no rows selected
SQL> select table_name from dba_tables  where tablespace_name='FRATABLE';
TABLE_NAME
------------------------------
SYS_FBA_DDL_COLMAP_104229
SYS_FBA_TCRV_104229
SQL> select object_name,object_id,data_object_id from dba_objects  where object_name='FRA';
OBJECT_NAME    OBJECT_ID DATA_OBJECT_ID
------------- ---------- --------------
FRA               104229         104244

7.最后一点,具有flashback data archive的表是不能drop的.要drop先取消flashback data archive特性.

SQL> drop table fra ;
drop table fra
           *
ERROR at line 1:
ORA-55610: Invalid DDL statement on history-tracked table
SQL> drop table nofra ;
Table dropped.
--取消flashback data archive特性.
SQL> alter table fra no flashback archive ;
Table altered.
SQL> drop table fra ;
Table dropped.

8.总结:
11GR2 又前进了1步,我的记忆里面11GR1版本是不支持删除列以及truncate的操作的.

时间: 2024-10-23 00:21:45

[20120813]11GR2下flashback data archive的测试.txt的相关文章

Oracle 11g 新特性 Flashback Data Archive 使用实例_oracle

Flashback Data Archive(闪回日志归档)其实理解为长时间的保存undo数据,对于某些重要的表可以自定义它的历史记录保存期限,它的的种种行为与undo表空间十分相似,使用的时候也是完全透明的,用户不知道它的查询一致性视图数据是来自undo还是Flashback Data Archive,现来分析它与undo的几点不同: 1.Flashback Data Archive仅记录UPDATE和DELETE语句,不记录INSERT语句. 2.Flashback Data Archive

Oracle闪回(flashback)功能详解 闪回数据归档(Flashback Data Archive)

Oracle闪回(flashback)功能详解  闪回数据归档(Flashback Data Archive)                     > > > > > > > >           > > >                               >                                           >                                 

[20140425]11GR2 truncate后恢复测试.txt

[20140425]11GR2 truncate后恢复测试.txt --做一个truncate后恢复测试在11GR2下,我的测试环境使用使用dataguard.备用库打开flashback. --可以利用在备用库flashback到truncate前,然后在传输到主库的方式看看. 1.建立测试环境: -- 我的测试环境:primary的tnsnames别名test,standby主机的tnsnames别名testdg.数据库版本:11GR2. -- 备用库打开在read only模式,并且rea

服务器-WIN2003下安装Data Protector Express 4.00sp1 出错

问题描述 WIN2003下安装Data Protector Express 4.00sp1 出错 安装环境:WINDOWS 2003 SERVER 安装软件:Data Protector Express 4.00sp1(HP 以前发布的备份软件DPE,现在HP已经不代理这个软件了) 出现问题:在一台WIN 2003的主服务器上,原来的DPE运行的好好的,有次清理病毒后,DPE软件的备份功能老是不能启动服务,DPE上的擦除,格式化,识别功能都没问题的,后来决定重装DPE. 用DPE自带的卸载功能卸

[20120927]11GR2下建立dblink.txt

[20120927]11GR2下建立dblink.txt SQL> select * from v$version ; BANNER--------------------------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit ProductionPL/SQL Release 11.2.0.1.0 -

cpu-linux下MCP2515驱动开发及测试

问题描述 linux下MCP2515驱动开发及测试 CPU采用ATMEL的9g25,通过MCP2515扩展CAN总线,linux下MCP2515驱动加载成功,采用Socketcan测试,发不了数据也读不了数据.请高手指教!!

我用.net 开发的框架、网站在 linux下全部移植编译调试测试完毕,非常爽!

问题描述 我用.net开发的框架.网站在linux下全部移植编译调试测试完毕,非常爽!我快爽晕了,哈哈!特提供一个典型的测试网站供大家观摩http://wwww.bwsyq.com看清楚是4个w啊不能访问可以通过下面的地址进行访问由于是测试,所以用的是ADSL,IP地址经常变化,域名不能用可参考下面提供的最新的IP地址!用的是我的笔记本,带宽只有2MB!部署环境ubuntu10.10+mysql5.1+apache2+mono2.67开发环境ubuntu10.10+mono2.67+mono-d

[20161216]toad下显示真实的执行计划.txt

[20161216]toad下显示真实的执行计划.txt --大家都应该知道使用explain plan看执行计划,有时候显示的执行计划不是真实的执行计划.现在我虽然使用它看,仅仅作为参考. --昨天看链接: http://www.toadworld.com/platforms/oracle/b/weblog/archive/2016/12/13/toad-explain-plan-tip-returning-actual-sql-execution-explain-plan --才知道toad

[20170428]延迟块清除测试.txt

[20170428]延迟块清除测试.txt --//做一个延迟块清除测试,前面的测试太乱了,思路非常不清楚. 1.环境: SCOTT@book> @ &r/ver1 PORT_STRING                    VERSION        BANNER ------------------------------ -------------- ------------------------------------------------------------------