oracle 闪回技术之闪回查询

 随着oracle10G发布,闪回技术的出现,oracle DBA的上班的心情也得到了许多宽心,闪回技术主要是针对人为出错而设计的。

闪回开启
启动闪回需要在mount状态下执行
alter database flashback on;

闪回的分类
1、闪回查询   2、闪回数据归档  3、闪回事物查询  4、闪回事务 5、闪回表 6、闪回删除 7.闪回数据库


一、 闪回查询介绍(分闪回时间点查询和闪回版本查询)
 
     以表为单位查询过去的时间点数据称为闪回查询,其中利用select 命令的 "as of" 子句,与PL/SQL包DBMS_flashback在过去的一个时间点上查询,称为闪回时间点查询。
处用versions between 子句在过去的一段时间范围查询,称为闪回版本查询。

  之所以能查看过去,是因为闪回查询能够在撤消(UNDO)段内搜索撤消数据,UNDO段数据保留多久决定了闪回查询的时间窗口的在小,撤消数据的保留策略取决于4个因素
1、初始化参数 undo_retention的值,单位秒,默认900秒,例如修改为为建议值1小时
sql> alter system set undo_retention=3600;
能不能保留这么久还要看其它因素。

2、UNDO表空间的数据文件是否启用了自动扩展,若能够自动增长,则undo_retention参数值的建议能够被最大限度采纳哦,例如查找undo表空间数据文件是否为自动扩展脚本如下
sql> select autoextensible,maxbytes/1024/1024/1024 from dba_data_files where tablespace_name=(select value from v$parameter where name='undo_tablespace');
注意:自动增加,加undo_retention设置过大,可能会打造一个很大的undo表空间,小心使用。另外如果让数据库绝对尊重undo_retention的设置可修改默认undo表
表间属性。例如:
sql> alter tablespace undotbs1 retention guarantee;    
建议没特殊需求不设置此属性,如undo表空间空间不够可能会带来事物无法运行。


闪回时间点查询
例子
 
示例1:查询scott.emp表在2015-2-1号上行23点12分47秒时所有行

sql> select * from scott.emp as of timestamp to_timestamp('2015-02-01 23:12:47','YYYY-MM-DD HH24:MI:SS');

示例 2: 查询scott.emp表7844号员工5分钟前的薪水
 sql> select sal from scott.emp as of timestamp (systimestamp - interval '5' minute) where empno=7844;

示列3: 利用scn查询
sql> select job_id from scott.emp as of scn 22424242 where empno=7844;

示列4:将员工编号7844的薪水字段修改15分钟前的值
sql>update scott.emp set sal=(select sal from scott.emp as of timestamp (systimestamp - interval '15' minute) where empno=7844) where empno=7844;

以上能否查询成功跟闪回时间窗口有着密切的关连

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27252036/viewspace-1423117/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27252036/viewspace-1423117/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值