rman回复为什么不能恢复被delete的数据

rman恢复为什么不能恢复被delete的数据?
环境:linux下centos6.4,oracle11g

1,备份

RMAN> BACKUP DATABASE PLUS ARCHIVELOG FORMAT '/data/oracle/backup/data/ALL_%U.BKP';


Starting backup at 31-JAN-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=105 RECID=38 STAMP=870380347
input archived log thread=1 sequence=106 RECID=39 STAMP=870386455
input archived log thread=1 sequence=107 RECID=40 STAMP=870404433
input archived log thread=1 sequence=108 RECID=41 STAMP=870418847
input archived log thread=1 sequence=109 RECID=42 STAMP=870440079
input archived log thread=1 sequence=110 RECID=43 STAMP=870458212
input archived log thread=1 sequence=111 RECID=44 STAMP=870458451
input archived log thread=1 sequence=112 RECID=45 STAMP=870458476
input archived log thread=1 sequence=113 RECID=46 STAMP=870458492
channel ORA_DISK_1: starting piece 1 at 31-JAN-15
channel ORA_DISK_1: finished piece 1 at 31-JAN-15
piece handle=/data/oracle/backup/data/ALL_0cpu493s_1_1.BKP tag=TAG20150131T180132 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 31-JAN-15

Starting backup at 31-JAN-15
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/data_ora/powerdes/system01.dbf
input datafile file number=00002 name=/oracle/data_ora/powerdes/sysaux01.dbf
input datafile file number=00003 name=/oracle/data_ora/powerdes/undotbs01.dbf
input datafile file number=00005 name=/oracle/data_ora/powerdes/SBXTAX01.dbf
input datafile file number=00006 name=/oracle/data_ora/powerdes/SMS01.dbf
input datafile file number=00004 name=/oracle/data_ora/powerdes/users01.dbf
channel ORA_DISK_1: starting piece 1 at 31-JAN-15
channel ORA_DISK_1: finished piece 1 at 31-JAN-15
piece handle=/oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_nnndf_TAG20150131T180139_bdsb04jz_.bkp tag=TAG20150131T180139 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 31-JAN-15
channel ORA_DISK_1: finished piece 1 at 31-JAN-15
piece handle=/oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_ncsnf_TAG20150131T180139_bdsb18jn_.bkp tag=TAG20150131T180139 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-JAN-15

Starting backup at 31-JAN-15
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=114 RECID=47 STAMP=870458538
channel ORA_DISK_1: starting piece 1 at 31-JAN-15
channel ORA_DISK_1: finished piece 1 at 31-JAN-15
piece handle=/data/oracle/backup/data/ALL_0fpu495a_1_1.BKP tag=TAG20150131T180218 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 31-JAN-15

RMAN>

2,删除数据
SQL> select * from smst1;

ID NAME
---------- ----------------------------------------
 1 a
 2 b
 3 c

SQL> delete from smst1;

3 rows deleted.

SQL> commit;

Commit complete.

SQL>

3,修复和恢复数据
RMAN> RESTORE DATABASE;

Starting restore at 31-JAN-15
using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oracle/data_ora/powerdes/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /oracle/data_ora/powerdes/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oracle/data_ora/powerdes/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oracle/data_ora/powerdes/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /oracle/data_ora/powerdes/SBXTAX01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /oracle/data_ora/powerdes/SMS01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_nnndf_TAG20150131T180139_bdsb04jz_.bkp
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 01/31/2015 18:09:48
ORA-19870: error while restoring backup piece /oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_nnndf_TAG20150131T180139_bdsb04jz_.bkp
ORA-19573: cannot obtain exclusive enqueue for datafile 1

RMAN> 

解决:需要在mount状态下执行恢复操作:
RMAN> shutdown immediate

database closed
database dismounted
Oracle instance shut down

RMAN> startup mount;

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     835104768 bytes

Fixed Size                     2217952 bytes
Variable Size                624953376 bytes
Database Buffers             201326592 bytes
Redo Buffers                   6606848 bytes

RMAN>
RMAN> RESTORE DATABASE;

Starting restore at 31-JAN-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=63 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /oracle/data_ora/powerdes/system01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /oracle/data_ora/powerdes/sysaux01.dbf
channel ORA_DISK_1: restoring datafile 00003 to /oracle/data_ora/powerdes/undotbs01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /oracle/data_ora/powerdes/users01.dbf
channel ORA_DISK_1: restoring datafile 00005 to /oracle/data_ora/powerdes/SBXTAX01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /oracle/data_ora/powerdes/SMS01.dbf
channel ORA_DISK_1: reading from backup piece /oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_nnndf_TAG20150131T180139_bdsb04jz_.bkp
channel ORA_DISK_1: piece handle=/oracle/app/oracle/flash_recovery_area/POWERDES/backupset/2015_01_31/o1_mf_nnndf_TAG20150131T180139_bdsb04jz_.bkp tag=TAG20150131T180139
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:35
Finished restore at 31-JAN-15

RMAN>
RMAN> RECOVER DATABASE DELETE ARCHIVELOG ;

Starting recover at 31-JAN-15
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:13

Finished recover at 31-JAN-15

RMAN> 
RMAN> ALTER DATABASE OPEN;

database opened

RMAN>

4,去验证
[oracle@powerlong4 ~]$ sqlplus "SMS/SMS@SERVICE_POWERDES"

SQL*Plus: Release 11.2.0.1.0 Production on Sat Jan 31 18:19:50 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from sms.smst1;

no rows selected

SQL> select * from smst1;

no rows selected

SQL>
 
恢复失败,为什么smst1表里面的数据 没有恢复过来?
------解决思路----------------------
要搞清楚一个问题,delete属于正常操作,不属于数据库故障。如果rman恢复会自动恢复所有被delete掉的记录,那么就乱套了
这种情况只能做不完全恢复,恢复到误删数据前的某一点
recover database until scn xxx;
或者不知道scn,用时间戳代替
recover database until time "TO_DATE('2015-1-30 20:01:30','YYYY-MM-DD HH24:MI:SS')";
------解决思路----------------------
做测试的话,要记住时间点,可以使用下面语句查询scn
select timestamp_to_scn(to_timestamp('2015-02-01 00:00:00' ,'yyyy-mm-dd hh24:mi:ss')) from dual;
你可以做两次删除,分别记下两次时间,然后恢复,
就会看到两次时间点的数据结果。
恢复指令:
rman target /;
startup mount;
run
{
set until scn 123456789;
restore database;
recover database;
}
;
alter database open resetlogs;
------解决思路----------------------

-- 这步,你的本意是想恢复一个之前的 0 级备份,但是动作失败了,后面你再 recover 也是徒劳的。
RESTORE DATABASE;