|
文件: |
闪回技术.rar |
大小: |
212KB |
下载: |
下载 | |
ORACLE 10G 为我们带来了强大的闪回机制。可以轻松恢复被删除,更新,插入的数据甚至drop掉的表。
据说truncate可以通过Flashback database恢复,有待验证。
下面我们来测试几个例子,平台oracle 10.2.0.3.0
闪回测试:
1.创建表table1(a,b),查看table1 versions
SQL> create table table1 as select '1'col1,'2'col2 from dual;
Table created
SQL> select versions_starttime starttime,versions_endtime endtime, versions_xid, versions_operation,col1,col2,versions_endscn endscn,versions_startscn startscn
2 from table1 versions
3 between timestamp minvalue and maxvalue
4 where 1=1 --条件
5 order by versions_starttime;
STARTTIME|ENDTIME|VERSIONS_XID|VERSIONS_OPERATION|COL1|COL2|ENDSCN|STARTSCN
----------------------------------------------------------------------------
1 2
2.插入记录 3,4 查看table1 versions
SQL> insert into table1 select '3'col1,'4'col2 from dual;
1 row inserted
SQL>/*执行上述语句*/
STARTTIME|ENDTIME|VERSIONS_XID|VERSIONS_OPERATION|COL1|COL2|ENDSCN|STARTSCN
----------------------------------------------------------------------------
1 2
2008082914:43:41 000B001900003656 I 3 4 1041672189
3.插入记录 5,6 查看table1 versions
SQL> insert into table1 select '5'col1,'6'col2 from dual;
1 row inserted
SQL>/*执行上述语句*/
STARTTIME|ENDTIME|VERSIONS_XID |VERSIONS_OPERATION|COL1|COL2|ENDSCN |STARTSCN
------------------------------------------------------------------------------
1 2
2008082914:43:41 000B001900003656 I 3 4 1041672189
2008082915:14:28 0019000C00001ADE I 5 6 1041676045
4.更新记录 3,4 -> 9 ,4 查看table1 versions
SQL> update table1 set col1=9 where col1=3;
1 row updated
SQL>/*执行上述语句*/
STARTTIME|ENDTIME|VERSIONS_XID|VERSIONS_OPERATION|COL1|COL2|ENDSCN|STARTSCN
----------------------------------------------------------------------------
1 2
2008082914:43:41|2008082915:17:58|000B001900003656|I|3 4 |1041676272|1041672189
2008082915:14:28 |0019000C00001ADE|I|5 6 1041676045
2008082915:17:58 |00060009000033E0|U|9 4 1041676272
5.删除记录 5,6 查看table1 versions
SQL> delete from table1 where col1=5;
1 row deleted
SQL> select * from table1;
COL1 COL2
---- ----
1 2
9 4
SQL>/*执行上述语句*/
STARTTIME|ENDTIME|VERSIONS_XID|VERSIONS_OPERATION|COL1|COL2|ENDSCN|STARTSCN
----------------------------------------------------------------------------
1 2
2008082914:43:41|2008082915:17:58|000B001900003656|I|3 4 |1041676272|1041672189
2008082915:14:28|2008082915:23:10|0019000C00001ADE|I|5 6 |1041676588|1041676045
2008082915:17:58 |00060009000033E0|U|9 4 1041676272
2008082915:23:10 |001B002000003284|D|5 6 1041676588
6.现在我们闪回到 2008082915:14:28 这个时间点 是insert事物开始的时间
SQL> flashback table table1 to timestamp to_timestamp('2008-08-29 15:14:28','yyyy-mm-dd hh24:mi:ss');
flashback table table1 to timestamp to_timestamp('2008-08-29 15:14:28','yyyy-mm-dd hh24:mi:ss')
ORA-08189: 因为未启用行移动功能, 不能闪回表
SQL> alter table table1 enable row movement;
Table altered
我们可以先用闪回查询看看记录:
SQL> select * from table1 as of timestamp to_timestamp('2008-08-29 15:14:28','yyyy-mm-dd hh24:mi:ss');
COL1 COL2
---- ----
1 2
3 4
SQL> flashback table table1 to timestamp to_timestamp('2008-08-29 15:14:28','yyyy-mm-dd hh24:mi:ss');
Done
SQL> select * from table1;
COL1 COL2
---- ----
1 2
3 4
SQL> drop table table1;
Table dropped
SQL> flashback table table1 to before drop;
Done
SQL> select * from table1;
COL1 COL2
---- ----
1 2
3 4
6.闪回表方式无法应付truncate操作
SQL> truncate table table1;
Table truncated
SQL>/*执行上述语句*/
STARTTIME|ENDTIME|VERSIONS_XID|VERSIONS_OPERATION|COL1|COL2|ENDSCN|STARTSCN
----------------------------------------------------------------------------
记录全无无法恢复据说可以通过flashback database的方式恢复。没有试过。
最后列举出一下命令:
例:执行Flashback Database命令格式。
SQL>flashback database to time to_timestamp(xxx);
SQL>flashback database to scn xxx
例:执行将test表闪回到2005年5月7日下午3点。
SQL>flashback table test to timestamp to_timestamp(’2005-05-07 15:00:00’,’yyyy-mm-dd hh24:mi:ss’);
例:表被drop后恢复
SQL>select * from recyclebin;
SQL>flashback table "BIN$b+XkkO1RS5K10uKo9BfmuA==$0" to before drop; --回收站表名
或
SQL>flashback table test_drop to before drop --真实表名
例:闪回查询
SQL>select * from t as of timestamp to_timestamp('2006-09-06 12:47:12','yyyy-mm-dd hh24:mi:ss');
最后补上2篇别人的文档,同时我这篇文章的文档也补上。
阅读(2220) | 评论(0) | 转发(0) |