oracle闪回查询
一、引言
程序中用到需要同步oracle更新和删除数据,于是考虑利用oracle的闪回查询机制来实现。
利用该机制首先需要oracle启用撤销表空间自动管理回滚信息,并根据实际情况设置对数据保存的有效期,即对数据的操作保存多久?
查看撤销表信息undo: show parameter undo;
设置撤销表信息:
alter system set undo_managerment=auto;设置为auto才可以使用闪回查询 alter system set undo_retention=900;最长保留时间(单位秒) alter system set undo_tablespace=undotbs1;
二、闪回查询的使用
参考:
http://www.oracle-developer.net/display.php?id=320
http://www.oracle-developer.net/display.php?id=210
flashback version query 通过where字句扩展VERSION BETWEEN来实现。
Flashback version query is invoked using the new VERSIONS BETWEEN extension to the FROM clause. It takes two forms as follows
VERSIONS BETWEEN TIMESTAMP [lower bound] AND [upper bound]; or
VERSIONS BETWEEN SCN [lower bound] AND [lower bound].
例子:
在表上执行了一次插入、两次更新、一次删除
SELECT x, y, z
FROM fbt VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
ORDER BY y;
结果:
X Y Z
---------- ------------------------- -----------------------
1 10-AUG-2005 18:00:57.078 Initial population
1 10-AUG-2005 18:01:07.109 First update
1 10-AUG-2005 18:01:17.125 Second update
1 10-AUG-2005 18:01:17.125 Second update 4 rows selected.
三、闪回查询机制实现原理
As stated above, Oracle provides a variety of metadata with each version of our data. The metadata is exposed via a number of pseudo-columns that we can use with our flashback version queries. These pseudo-columns are as follows:
就像上面显示的,oracle对于我们数据的每个版本提供了一个元信息。这些元信息通过一些伪列显示出来,我们可以在闪回查询中使用这些伪列。这些伪列如下: VERSIONS_STARTTIME (start timestamp of version); 版本开始时间戳
VERSIONS_STARTSCN (start SCN of version); 版本开始系统更改号(SCN:system change number)
VERSIONS_ENDTIME (end timestamp of version); 版本结束时间
VERSIONS_ENDSCN (end SCN of version); 版本结束系统更改号
VERSIONS_XID (transaction ID of version); and 版本
VERSIONS_OPERATION (DML operation of version). 版本操作类型(包括增、删、改)
We can now include some of these pseudo-columns in our flashback version query as follows. Note the SCN metadata is excluded as we are using timestamps for the examples.
现在我们可以在下面的闪回查询sql语句中包含这些伪列,没有包括SCN元信息的原因是我们使用了时间戳在这个例子中。 SQL> SELECT z
, VERSIONS_STARTTIME
, VERSIONS_ENDTIME
, VERSIONS_XID
, VERSIONS_OPERATION
FROM fbt VERSIONS BETWEEN TIMESTAMP MINVALUE AND MAXVALUE
ORDER BY
VERSIONS_ENDTIME;
Z VERSIONS_STARTTIME VERSIONS_ENDTIME VERSIONS_XID VERSIONS_OPERATION
-------------------- ------------------------- ------------------------- ---------------- ------------------
Initial population -AUG- ::53.000 -AUG- ::05.000 040026008A010000 I
First update -AUG- ::05.000 -AUG- ::14.000 040029008A010000 U
Second update -AUG- ::14.000 -AUG- ::26.000 040027008A010000 U
Second update -AUG- ::26.000 040028008A010000 D rows selected.
This explains why we were seeing the second update row twice. If we look at the VERSIONS_OPERATION column, we can see that the second appearance of the final update record is actually the delete operation against it (specified by 'D'). Without the versions metadata, the Y timestamp column was actually confusing us into thinking we had two versions of the same record at the same time.
这里解释了为什么在上面我们看到了两行更新操作。如果我们看一下VERSION_OPERATION列,我们就可以看到第二次更新实际上是以操作类型D即delete来记录的。除了元信息,Y列的时间戳也使我们很迷惑,两次版本的时间是一样的。 The metadata also gives us an indication that the delete operation was the final version of this data. The end timestamp of the version is NULL which tells us that there is no superceding record.
元信息也告诉我们删除操作是关于这个数据的最后一个版本。这个版本的结束时间戳是NULL也告诉了我们这是一个没有后续操作的记录。 Interestingly, if we had not included a sleep between creating the FBT table and adding the single record, it would be likely (based on observations) that all VERSIONS_* pseudo-columns (except the ENDTIME and ENDSCN) would be NULL for the insert record.
有趣的是,如果我们没有在创建fbt表和插入一个记录时间做休眠,它就可能会显示出(根据观察)所有以VERSIONS_开头的伪列(除了ENDTIME和ENDSCN)可能都是NULL对于这次插入。
oracle闪回查询的更多相关文章
- Oracle闪回查询恢复delete删除数据
Flashback query(闪回查询)原理 Oracle根据undo信息,利用undo数据,类似一致性读取方法,可以把表置于一个删除前的时间点(或SCN),从而将数据找回. Flashback q ...
- 【转】FlashBack总结之闪回查询与闪回表
本文主要介绍利用UNDO表空间的闪回技术,主要包括:闪回表,闪回版本查询,闪回事务查询,闪回查询.这些闪回技术实现从回滚段中读取表中一定时间内操作过的数据,可用来进行数据比对,或者修正意外提交造成的错 ...
- Oracle Flashback Technologies - 闪回查询
Oracle Flashback Technologies - 闪回查询 查看表中,某行数据的修改记录 #创建一个表,并插入和修改数据 SQL> create table y3(id )); T ...
- Oracle的回收站和闪回查询机制(二)
上一篇中讲诉了Oracle中一些闪回查询(Flashback Query),这是利用回滚段信息来恢复一个或一些表到以前的一个时间点(一个快照).要注意的是,Flashback Query仅仅是查询以前 ...
- Oracle的回收站和闪回查询机制(一)
实际工作中,我们经常会遇到一些情况,误删除某些表或某些表的某些记录,这时候就需要我们将这些记录重新插入进去.如何才能解决这个问题呢? Oracle的Flashback query(闪回查询)为我们解决 ...
- Oracle 中利用闪回查询确定某表在某时间点之后的修改内容,并恢复至该时间点
Oracle 中利用闪回查询确定某表在某时间点之后的修改内容: 1.查看 DELETE 及 UPDATE 操作修改的数据: SQL> SELECT * FROM tab AS OF TIMEST ...
- Oracle 修改 新增 触发器 针对字段修改 触发器 误删Oracle表、数据、触发器找回 闪回查询
emmmm 写这个博客心情很复杂,,,本来这个触发器早就写好了,后来发生点事就写个博客当个备份吧,就当留纪念了:话不多数上问题以及SQL: 问题: 在ABONPB表上增加一个触发器,针对车牌号字段做u ...
- 闪回查询(SELECT AS OF)
使用Flashback Query的场景包括如下: 摘自官档 Recovering lost data or undoing incorrect, committed changes. For exa ...
- Oracle闪回技术详解
概述: 闪回技术是Oracle强大数据库备份恢复机制的一部分,在数据库发生逻辑错误的时候,闪回技术能提供快速且最小损失的恢复(多数闪回功能都能在数据库联机状态下完成).需要注意的是,闪回技术旨在快速 ...
随机推荐
- [transferred] javascript exception handling.
my error handling clause: window.onerror = function (errorMessage, scriptURI, lineNumber, columnNumb ...
- Java SE series:1. environment configure and Hello world! [We use compiler and packager to create an application!]
1. cli (command line interface) and gui (graphic user interface) use javahome path, search classpath ...
- 认识javascript
javascript小知识 www.phonegap.com(跨平台开发框架) Cocos2d-Html5(WebGL渲染 javascript语言) creatjs.com(融合了flash动画的 ...
- Git 代码管理常用命令
1) 远程仓库相关命令 检出仓库:$ git clone git://github.com/jquery/jquery.git查看远程仓库:$ git remote -v添加远程仓库:$ git re ...
- php扩展的基本安装
phpize ./config --with-php-config=.. make&make install php.ini
- SQL 基础语法(创建表空间、用户、并授予权限、数据的增删改查) --(学习笔记)[转]
--创建表空间 名:lyayzh_test create tablespace lyayzh_test --创建表数据文件 名:lyayzh_test_data.dbf 必须以dbf为后缀 dataf ...
- ALTFP_CONVERT IP使用与仿真
ALTFP_CONVERT IP使用与仿真 近期项目要使用到整型数据转浮点型数据,将16位的整数转换为单精度浮点数(32bit).本打算自己写逻辑实现的,不过考虑到本身项目时间紧,能力也有限,就没 ...
- PHP程序员如何突破成长瓶颈
PHP因为简单而使用,但不能因为它的简单而限制我们成长!文章给PHP工程师突破成长瓶颈提了一些建议,希望PHPer能够突破自己,有更好的发展. AD: 作为Web开发中应用最广泛的语言之一,PHP有着 ...
- ug-Assertion failure in [MyClass layoutSublayersOfLayer:]
这是在iOS7上,tableview 的sectionHeaderView中报错 *** Assertion failure in -[****.****UITVSectionHeader_Team ...
- asp.net中调用javascript自定义函数的方法(包括引入JavaScript文件)总结
通常javascript代码可以与HTML标签一起直接放在前 端页面中,但如果JS代码多的话一方面不利于维护,另一方面也对搜索引擎不友好,因为页面因此而变得臃肿:所以一般有良好开发习惯的程序员都会把 ...