If the required archive is lost during the recover datafile process, the recover cannot be performed. You can use the bbed tool to skip the Lost Archive for recover datafile.
The experiment process is as follows:
SYS @ ORCL> select * from v $ version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Prod
PL/SQL Release 10.2.0.1.0-Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0-Production
NLSRTL Version 10.2.0.1.0-Production
SYS @ ORCL> create tablespace bbed_test_tbs
2 datafile '/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf' size 20 M;
Tablespace created.
SYS @ ORCL> create table bbed_test1 tablespace bbed_test_tbs as select * from dba_objects;
Table created.
SYS @ ORCL> create table bbed_test2 tablespace bbed_test_tbs as select * from dba_objects;
Table created.
SYS @ ORCL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2
Next log sequence to archive 4
Current log sequence 4
SYS @ ORCL> select file # | ''| name |'' | bytes from v $ datafile;
FILE # | ''| NAME |'' | BYTES
--------------------------------------------------------------------------------
1/u01/app/oracle/oradata/ORCL/system01.dbf 503316480
2/u01/app/oracle/oradata/ORCL/undotbs01.dbf 36700160
3/u01/app/oracle/oradata/ORCL/sysaux01.dbf 262144000
4/u01/app/oracle/oradata/ORCL/users01.dbf 5242880
5/u01/app/oracle/oradata/ORCL/example01.dbf 104857600
6/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf 20971520
6 rows selected.
Use rman to back up datafile 6
[Oracle @ jp bbed] $ rman target/
Recovery Manager: Release 10.2.0.1.0-Production on Thu Jun 19 21:33:16 2014
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected to target database: ORCL (DBID = 1356549586)
RMAN> backup datafile 6;
Starting backup at 19-jun14
Using target database control file instead of recovery catalog
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: sid = 143 devtype = DISK
Channel ORA_DISK_1: starting full datafile backupset
Channel ORA_DISK_1: specifying datafile (s) in backupset
Input datafile fno = 00006 name =/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf
Channel ORA_DISK_1: starting piece 1 at 19-jun14
Channel ORA_DISK_1: finished piece 1 at 19-jun14
Piece handle =/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_06_19/blank _. bkp tag = TAG20140619T213426 comment = NONE
Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 19-jun14
Then modify the data stored in datafile 6 in the library.
SYS @ ORCL> delete from bbed_test1;
50316 rows deleted.
SYS @ ORCL> commit;
Commit complete.
SYS @ ORCL> alter system switch logfile;
System altered.
SYS @ ORCL> alter system switch logfile;
System altered.
SYS @ ORCL> alter system switch logfile;
System altered.
Disable the database and delete datafile 6.
SYS @ ORCL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
[Oracle @ jp ORCL] $ ls
Bbed_test_tbs01.dbf control03.ctl redo02.log system01.dbf users01.dbf
Control01.ctl example01.dbf redo03.log temp01.dbf
Control02.ctl redo01.log sysaux01.dbf undotbs01.dbf
[Oracle @ jp ORCL] $ mv bbed_test_tbs01.dbf bbed_test_tbs01.dbf.bak
Start the database:
SYS @ ORCL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218992 bytes
Variable Size 83887696 bytes
Database Buffers 197132288 bytes
Redo Buffers 2973696 bytes
Database mounted.
ORA-01157: cannot identify/lock data file 6-see DBWR trace file
ORA-01110: data file 6: '/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf'
The database cannot be started because datafile 6 is lost at this time. Use rman backup to restore the data file and try to open the database.
RMAN> restore datafile 6;
Starting restore at 19-jun14
Using target database control file instead of recovery catalog
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: sid = 155 devtype = DISK
Channel ORA_DISK_1: starting datafile backupset restore
Channel ORA_DISK_1: specifying datafile (s) to restore from backup set
Restoring datafile 00006 to/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf
Channel ORA_DISK_1: reading from backup piece/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_06_19/o1_mf_nnndf_tag20140619t2131__9t73x2s8 _. bkp
Channel ORA_DISK_1: restored backup piece 1
Piece handle =/u01/app/oracle/flash_recovery_area/ORCL/backupset/2014_06_19/o1_mf_nnndf_tag20140619t2131__9t73x2s8 _
Channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 19-jun14
SYS @ ORCL> alter database open;
Alter database open
*
ERROR at line 1:
ORA-01113: file 6 needs media recovery
ORA-01110: data file 6: '/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf'
In this case, datafile 6 requires a recover.
In this case, we delete the archive and try recover datafile 6.
[Oracle @ jp archivelog] $ cd 2014_06_19/
[Oracle @ jp 2014_06_19] $ ls
O1_mf_1_3_9t73hdco _. arc o1_mf_rj5_9t740dxd _. arc
O1_mf_00004_9t74035o _. arc o1_mf_00006_9t740sv7 _. arc
[Oracle @ jp 2014_06_19] $ rm-f *
[Oracle @ jp 2014_06_19] $ ls
SYS @ ORCL> recover datafile 6;
ORA-00279: change 507768 generated at 06/19/2014 21:34:26 needed for thread 1
ORA-00289: suggestion:
/U01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_06_19/o1_mf_1_4 _ % u _. arc
ORA-00280: change 507768 for thread 1 is in sequence #4
Specify log: {<RET> = suggested | filename | AUTO | CANCEL}
ORA-00308: cannot open archived log
'/U01/app/oracle/flash_recovery_area/ORCL/archivelog/2014_06_19/o1_mf_1_4_9t7403
5o _. arc'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Unable to recover, prompting that the required archive file does not exist
Dump output file header:
SYS @ ORCL> alter session set events 'immediate trace name file_hdrs level 10 ';
Session altered.
SYS @ ORCL> oradebug setmypid;
Statement processed.
SYS @ ORCL> oradebug tracefile_name
/U01/app/oracle/admin/ORCL/udump/orcl_ora_9065.trc
View the dump file:
Data file #1:
(Name #7)/u01/app/oracle/oradata/ORCL/system01.dbf
Creation size = 0 block size = 8192 status = 0xe head = 7 tail = 7 dup = 1
Tablespace 0, index = 1 krfil = 1 prev_file = 0
Unrecoverable scn: 0x0000.00000000 01/01/1988 00:00:00
Checkpoint cnt: 56 scn: 0x0000. 0007c39c 06/19/2014 21:37:19
Stop scn: 0x0000. 0007c39c 06/19/2014 21:37:19
Creation Checkpointed at scn: 0x0000.00000009 06/30/2005 19:10:11
Thread: 0 rba :( 0x0. 0.0)
Then we use bbed to change the scn of datafile 6 to the same as that of the system data file.
BBED> set dba 6, 1
DBA 0x01800001 (25165825)
BBED> map
File:/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf (6)
Block: 1 Dba: 0x01800001
------------------------------------------------------------
Data File Header
Struct kcvfh, 676 bytes @ 0
Ub4 tailchk @ 8188
BBED> p kcvfhckp
Struct kcvfhckp, 36 bytes @ 484
Struct kcvcpscn, 8 bytes @ 484
Ub4 kscnbas @ 484 0x0007bf78
Ub2 kscnwrp @ 488 0x0000
Ub4 kcvcptim@ 492 0x32b46ee2
Ub2 kcvcpthr @ 496 0x0001
Union u, 12 bytes @ 500
Struct kcvcprba, 12 bytes @ 500
Ub4 kcrbaseq @ 500 0x00000004
Ub4 kcrbabno @ 504 0x0000a54a
Ub2 kcrbabof @ 508 0x0010
Ub1 kcvcpetb [0] @ 512 0x02
Ub1 kcvcpetb [1] @ 513 0x00
Ub1 kcvcpetb [2] @ 514 0x00
Ub1 kcvcpetb [2] @ 515 0x00
Ub1 kcvcpetb [4] @ 516 0x00
Ub1 kcvcpetb [5] @ 517 0x00
Ub1 kcvcpetb [6] @ 518 0x00
Ub1 kcvcpetb [7] @ 519 0x00
BBED & gt; m/v 9cc3 offset 484
BBED-00201: invalid switch)
BBED & gt; m/x 9cc3 offset 484
Warning: contents of previous BIFILE will be lost. Proceed? (Y/N) Y
File:/u01/app/oracle/oradata/ORCL/bbed_test_tbs01.dbf (6)
Block: 1 Offsets: 484 to 995 Dba: 0x01800001
------------------------------------------------------------------------
9cc30700 rje7b7 e26eb432 0100f50d 04000000 4aa50000 10000000 02000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
0a000a00 0a000100 00000000 00000000 00000000 02008001 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000
<32 bytes per line>
BBED> sum apply
Check value for File 6, Block 1:
Current = 0x862e, required = 0x862e
Return to database recover datafile 6 and try to open the database.
SYS @ ORCL> recover datafile 6;
Media recovery complete.
SYS @ ORCL> alter database open;
Database altered.