oracle闪回技术

undo数据保留7天
orcl> show parameter undo

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
_optimizer_undo_cost_change string 12.1.0.2
temp_undo_enabled boolean FALSE
undo_management string AUTO
undo_retention integer 604800
undo_tablespace string UNDOTBS1
orcl> select 604800/60/60/24 from dual;

604800/60/60/24
---------------
7

1:闪回查询,利用undo

查询指定时间点的表数据

select * from scott.acct as of timestamp TO_TIMESTAMP('2018-05-20 15:30:00',' yyyy-mm-dd hh24:mi:ss')  WHERE user_id = 1;

2:闪回表

闪回表(Flashback table)是利用undo信息来恢复表对象到以前的某一个时间点(一个快照)

SQL>flashback table test to timestamp to_timestamp('2018-05-20 15:30:00',' yyyy-mm-dd hh24:mi:ss') ;

SQL>flashback table test to timestamp scn 115544;

SQL>flashback table test to timestamp to_timestamp('2018-05-20 15:30:00',' yyyy-mm-dd hh24:mi:ss') enable triggers;

运用闪回表前提 

1)普通用户中需要有Flashback any table的系统权限。命令如: 

  SQL>grant flashback any table to scott; 

2)有该表的select、insert、delete、alter权限。 

3)必须保证该表有row movement(行移动)。

恢复表到过去的某个时间点,恢复test表到刚记录的时间点(或scn),由于表中存在触发器,因此使用了关键字enable triggers;

flashback table test to timestamp to_timestamp('2018-05-20 15:30:00',' yyyy-mm-dd hh24:mi:ss') enable triggers;

3:闪回数据归档

查询过去一段时间的状态

select
versions_startscn, versions_endscn, versions_starttime, versions_endtime, versions_xid, versions_operation,ORDER_ID
from scott.emp
WHERE ORDER_ID in (100827979,100827973,100785947);

猜你喜欢

转载自www.cnblogs.com/elontian/p/9078703.html