Oracle的闪回特性之恢复truncate删除表的数据

Oracle的闪回特性之恢复truncate删除表的数据

SQL> show parameter flashback

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

db_flashback_retention_target        integer     1440

flashback功能默认为1440分钟,也就一天时间

数据库闪回状态可以从v$database视图中查询

SQL> select dbid,name,flashback_on,current_scn from v$database;

      DBID NAME      FLASHBACK_ON       CURRENT_SCN

---------- --------- ------------------ -----------

2274326636 RISENET   NO                      997660

flashback_on为NO,也就是没有开flashback功能,当truncate删除数据时,无法使用flashback

启动flashback_on(需要数据库在mount状态下打开)

SQL> shutdown immediate;

数据库已经关闭。

已经卸载数据库。

ORACLE 例程已经关闭。

SQL> startup mount

ORACLE 例程已经启动。

SQL> alter database flashback on;

数据库已更改。

SQL> select dbid,name,flashback_on,current_scn from v$database;

      DBID NAME      FLASHBACK_ON       CURRENT_SCN

---------- --------- ------------------ -----------

2274326636 RISENET   YES                          0

SQL> alter database open;

数据库已更改。

SQL> connect scott/mzl

已连接。

SQL> select table_name from user_tables;

 

TABLE_NAME

------------------------------

SALGRADE

TEST

DEPT_COPY

DEPT_RECOVER

DEPT

 

SQL> select * from dept;

 

    DEPTNO DNAME          LOC

---------- -------------- -------------

        50 support        denver

        10 ACCOUNTING     NEW YORK

   SQL> truncate table dept;

表被截断。

 

SQL> select * from dept;

未选定行

因为truncate是DDL语句,不是DML语句,所以不能闪回查询as of 来恢复

恢复数据:

SQL> connect sys/mzl as sysdba

已连接。

SQL> shutdown immediate

数据库已经关闭。

已经卸载数据库。

ORACLE 例程已经关闭。

SQL> startup mount

ORACLE 例程已经启动。

数据库装载完毕。

SQL> flashback database to timestamp

  2  to_timestamp('2008-06-08 18:22:33','yyyy-mm-dd hh24:mi:ss');

闪回完成。

SQL> alter database open read only;

数据库已更改。

SQL> select * from scott.dept;

 

    DEPTNO DNAME          LOC

---------- -------------- -------------

        50 support        denver

    

如果数据恢复不够理想,可以关闭数据库继续进行恢复。 如果用'alter database open resetlogs'打开,在想关闭数据库用flashback恢复就不行了

SQL> shutdown immediate

数据库已经关闭。

已经卸载数据库。

ORACLE 例程已经关闭。

SQL> startup

ORACLE 例程已经启动。

ORA-01589: 要打开数据库则必须使用 RESETLOGS 或 NORESETLOGS 选项

SQL> alter database open resetlogs;

数据库已更改。

一旦resetlogs之后,将不能再flashback至resetlogs之前的时间点。

posted @ 2013-05-29 16:39  andybox  阅读(602)  评论(0编辑  收藏  举报