Restor datafile danneggiato dalla Flash Recovery Area

Supponiamo di avere un datafile danneggiato e di volerlo recuperare.

Il datafile è recuperato da una copia immagine  (no backup) e quindi lo stato del datafile risale a quando è stata effettuata la copia. Non prevede nè il restore della copia del datafile nè l'applicazione degli incremental backup pertanto è molto veloce.

Supponiamo che il tablespace danneggiato sia TS_PEPT_DATA (datafile 5) e di avere a disposizione una copia  immagine fatta precedentemente.

RMAN> report schema;

Report of database schema for database with db_unique_name TEST1
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    700      SYSTEM               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/system01.dbf
2    600      SYSAUX               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/sysaux01.dbf
3    875      UNDOTBS1             ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/undotbs01.dbf
4    5        USERS                ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/users01.dbf
5    1        TS_PEPT_DATA         ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_pept_data01.dbf
6    1        TS_PEPT_INDEX        ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_index_data01.dbf

List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    64       TEMP                 32767       /u01/app/oracle/oradata/TEST1/TEST1/datafile/temp01.dbf


Verifichiamo che esiste una copia immagine nella flash recovery area.

RMAN> list copy of datafile 5;

List of Datafile Copies
=======================
Key     File S Completion Time Ckp SCN    Ckp Time
------- ---- - --------------- ---------- ---------------
13      5    A 14-JAN-19       1239577    14-JAN-19
        Name: /u01/app/oracle/fast_recovery_area/TEST1/TEST1/datafile/o1_mf_ts_pept__g3s6xop6_.dbf
        Tag: TAG20190114T152453


Mettiamo offline il datafile.

RMAN> sql 'alter database datafile 5 offline';

sql statement: alter database datafile 5 offline


Impostiamo la copia presente nella FRA come il datafile di produzione.

RMAN> switch datafile 5 to copy;

datafile 5 switched to datafile copy "/u01/app/oracle/fast_recovery_area/TEST1/TEST1/datafile/o1_mf_ts_pept__g3s6xop6_.dbf"

Con il seguente comando notiamo che ora il database sta usando il datafile 5 all'interno della FRA e non nella sua posizione naturale.

RMAN> report schema;

Report of database schema for database with db_unique_name TEST1

List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    700      SYSTEM               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/system01.dbf
2    600      SYSAUX               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/sysaux01.dbf
3    875      UNDOTBS1             ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/undotbs01.dbf
4    5        USERS                ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/users01.dbf
5    1        TS_PEPT_DATA         ***     /u01/app/oracle/fast_recovery_area/TEST1/TEST1/datafile/o1_mf_ts_pept__g3s6xop6_.dbf
6    1        TS_PEPT_INDEX        ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_index_data01.dbf


Recuperiamo lo stato del datafile 5 con quello corrente del database:

RMAN> recover datafile 5;

Starting recover at 14-JAN-19
using channel ORA_DISK_1
starting media recovery
media recovery complete, elapsed time: 00:00:01
Finished recover at 14-JAN-19

RMAN> sql  'alter database datafile 5 online';



Per ripristinare la situazione originaria occorre cancellare il file 5 presente sotto $ORACLE_BASE/oradata/<SID> perché non essendo usato non ha effetti sul funzionamento del db.

rm /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_pept_data01.dbf

Creare una immagine copia del datafile 5 presente nella FRA nella originale location.

RMAN> backup as copy datafile 5 format='/u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_pept_data01.dbf';

RMAN> sql 'alter database datafile 5 offline';

using target database control file instead of recovery catalog
sql statement: alter database datafile 5 offline

RMAN> switch datafile 5 to copy;

datafile 5 switched to datafile copy "/u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_pept_data01.dbf"


Con il seguente comando verifichiamo che il datafile è sotto la sua originaria directory.
RMAN> report schema;

Report of database schema for database with db_unique_name TEST1
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    700      SYSTEM               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/system01.dbf
2    600      SYSAUX               ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/sysaux01.dbf
3    875      UNDOTBS1             ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/undotbs01.dbf
4    5        USERS                ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/users01.dbf
5    1        TS_PEPT_DATA         ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_pept_data01.dbf
6    1        TS_PEPT_INDEX        ***     /u01/app/oracle/oradata/TEST1/TEST1/datafile/ts_index_data01.dbf


RMAN> recover datafile 5;

Starting recover at 14-JAN-19
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=20 device type=DISK
starting media recovery
media recovery complete, elapsed time: 00:00:00
Finished recover at 14-JAN-19

RMAN>  sql 'alter database datafile 5 online';


Effettuare una nuova copia nella FRA.

RMAN> backup as copy datafile 5;


Post popolari in questo blog

Create e Drop Pluggable Database

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione