mardi 30 août 2011

Oracle 11g: Recover loss of datafile in NOARCHIVELOG database

Using SQLplus
First of all, you have to identify the missing or corrupted file using the alert log or the v$recover_file view.

Once the datafile identified, you need to stop the database :
SQL>shutdown immediate;

Copy your backup of the file at the same place of your missing datafile.

Startup your database :
SQL>startup;
ORACLE instance started.

Total System Global Area  728199168 bytes
Fixed Size                  1338924 bytes
Variable Size             213909972 bytes
Database Buffers          503316480 bytes
Redo Buffers                9633792 bytes
Database mounted.
ORA-01113: file 44 needs media recovery
ORA-01110: data file 44: '/database/VOLATI/data/DATA_TEST.dbf'
SQL>

As you can see the file you copy need media recovery.

if you check the status of the database, you can see that the database is not opened but stay MOUNT state:
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL>

Now copy the corrupted file or missing one from your last backup to the previous location of the file.

Here you can ask for media recovery on datafile with file id 44 :
SQL>recover datafile 44;

May be you may need to set the datafile online :
SQL>alter database datafile '/database/VOLATI/data/DATA_TEST.dbf' online;
or
SQL>alter database datafile 44 online;

If the recovery on a unique file fails, then try to recover the entire database by restoring all the data files and also the control files from the last backup of your database (remember as your database is in noarchive log, may be you lost some data).


Using RMAN
$>rman target /
RMAN>sql 'alter database datafile 44 offline';
RMAN>restore datafile 44;
RMAN>recover datafile 44;
RMAN>sql 'alter database datafile 44 online';