方法一:1首先尽可能了解误删除的时间点,数据表
2确定误删除时间点后,找到距此时间点之前最近的备份数据文件
3备份当前数据文件
4还原删除时间点之前最近的数据文件,利用日志挖掘技术恢复误删除的表
5导出误删除的表
6还原步骤3数据文件,并导入误删除的表
方法二:利用Oracle Database 10g 中的闪回表特性恢复删除的数据表(参考楼上楼下的很详细)
方法一操作步骤:
一试验环境准备
1公司开发人员scott,其在数据库帐号亦为scott,scott建的一个表为t_scott 结构如下:
SQL> select * from t_scott;
ID USERNAME SEX
---------- -------------------- ----
1 zhangsan F
2 xiaoxia M
2备份数据文件
alter database begin backup;
cp /oracle/app/oradata/TEST/*.dbf /home/oracle/db_bak/
alter database end backup;
查询系统时间:
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2012-12-03 04:19:02
3 scott误删除表
SQL> show user;
USER is "SCOTT"
SQL> drop table t_scott;
Table dropped.
SQL> commit;
Commit complete.
SQL> select * from t_scott;
select * from t_scott
ERROR at line 1:
ORA-00942: table or view does not exist
查看下当前系统时间(大概了解scott删除t_scott表的时间)
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
TO_CHAR(SYSDATE,'YY
-------------------
2012-12-03 04:30:16
二开始恢复
1查看当前的日志组状态,切换下日志文件(如果不切换scott删除的日志信息可能没有些到归档日志文件里,注:在试验环境下,生产环境下应该不用手动切换日志),手动执行检查点,命令依次如下:
select * from v$log;
alter system switch logfile;
alter system checkpoint;
2建立存储挖掘数据目录
mkdir -pv /home/oracle/logminer
3.修改控制文件
SQL> alter system set utl_file_dir='/home/oracle/logminer' scope=spfile;
System altered.
重启并生效
SQL> shutdown immediate
SQL> startup
4创建存储数据字典文件的文件
SQL> execute dbms_logmnr_d.build('shwdict.ora','/home/oracle/logminer');
PL/SQL procedure successfully completed.
5添加归档日志文件
SQL>execute dbms_logmnr.add_logfile('/oracle/app/flash_recovery_area/TEST/archivelog/2012_12_03/o1_mf_1_1_8cqh0n6y_.arc',dbms_logmnr.new);
PL/SQL procedure successfully completed.
6挖掘数据
SQL> exec dbms_logmnr.start_logmnr (dictfilename=>'/home/oracle/logminer/shwdict.ora');
PL/SQL procedure successfully completed.
7格式化日期
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
8查询删除表的时间点
SQL> select SCN,TIMESTAMP,SQL_REDO from v$LOGMNR_CONTENTS where SQL_REDO like '%drop%';
SCN TIMESTAMP
---------- -------------------
SQL_REDO
--------------------------------------------------------------------------------
955028 2012-12-03 03:36:11
drop table tab_recover AS "BIN$z+O+tA6A3GfgQKjATBIVGA==$0" ;
956144 2012-12-03 04:25:49
drop table t_scott AS "BIN$z+VwRK8Dm77gQKjATBIVjw==$0" ;
9删除库文件
rm -rf /oracle/app/oradata/TEST/*.dbf
10 关库并开启到mount状态
shutdown abort
startup mount
11拷贝备份的数据文件
cp /home/oracle/db_bak/*.dbf .
12恢复至删除的时间点
SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> recover database until time '2012-12-03 04:25:49';
Media recovery complete.
SQL> alter database open resetlogs;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ WRITE
SQL> select * from scott.t_scott;
ID USERNAME SEX
---------- -------------------- ----
1 zhangsan F
2 xiaoxia M