(1):
在测试数据库上面玩telete 、flashback
首先要确定数据库是否 启用了闪回(flashback)功能
数据库的Flashback Database功能缺省是关闭的
[oracle@oracle10 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Jul 7 15:56:11 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn /as sysdba;
Connected.
SQL> select name,log_mode from v$database;
NAME LOG_MODE
--------- ------------
TESTDB ARCHIVELOG
SQL> select name,current_scn,flashback_on from v$database;
NAME CURRENT_SCN FLASHBACK_ON
--------- ----------- ------------------
TESTDB 1057096 NO
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 88082000 bytes
Database Buffers 192937984 bytes
Redo Buffers 2973696 bytes
Database mounted.
SQL> alter database flashback on;
Database altered.
SQL> alter database open;
Database altered.
SQL> select name,current_scn,flashback_on from v$database;
NAME CURRENT_SCN FLASHBACK_ON
--------- ----------- ------------------
TESTDB 1057096 YES
这样就说明数据库启用的了flashback功能。
然后执行测试操作:
SQL> select * from viewt;
ID NAME ADDRESS
---------- ---------------- ----------------
1 jestoo shanghai
2 yahoo beijing
SQL> delete from viewt where id=001;
1 row deleted
SQL> commit;
Commit complete
SQL> select * from viewt;
ID NAME ADDRESS
---------- ---------------- ----------------
2 yahoo beijing
可以通过这条SQL 查询到:
SQL> select * from viewt as of timestamp to_timestamp('2010-07-07 15:20:00', 'yyyy-mm-dd hh24:mi:ss');
ID NAME ADDRESS
---------- ---------------- ----------------
1 jestoo shanghai
2 yahoo beijing
然后执行恢复:
SQL> flashback table viewt to TIMESTAMP to_timestamp('2010-07-07 16:00:00','yyyy-mm-dd hh24:mi:ss');
Done
#说明Ok,也可以恢复到系统的多少分钟前,命令如下:
SQL> flashback table viewt to timestamp systimestamp - interval '30' minute;
SQL> flashback table viewt to TIMESTAMP to_timestamp('2010-07-07 15:20:00','yyyy-mm-dd hh24:mi:ss');
flashback table viewt to TIMESTAMP to_timestamp('2010-07-07 15:20:00','yyyy-mm-dd hh24:mi:ss')
#这里可能会提示下面问题:说明数据库没有启用 flashback 功能
ORA-08189: cannot flashback the table because row movement is not enabled
这里还说明一个问题:
基于 undo 的表恢复,被恢复的表必须启用 row movement ,不然会报 ORA-08189 错误。
要查看某表是否启用 row movement ,可以到 user_tables 中查询 ( 或 all_tables,dba_tables) ,例如:
select row_movement from user_tables where table_name=‘VIEWT’;
ROW_MOVE
--------
ENABLED
要启用或禁止某表 row movement ,可以通过下列语句:
-- 启用
ALTER TABLE VIEWT ENABLE ROW MOVEMENT;
表已更改。
-- 禁止
ALTER TABLE VIEWT DISABLE ROW MOVEMENT;
表已更改。
查询当前的scn
删除表这个好恢复:
SQL> drop table viewt;
Table dropped
SQL> commit;
Commit complete
SQL> flashback table viewt to before drop;
Done
SQL> select * from viewt;
ID NAME ADDRESS
---------- ---------------- ----------------
3 sina shenzhen
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15713890/viewspace-667474/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15713890/viewspace-667474/