To determine whether datafiles require media recovery:
Start SQL*Plus and connect to the target database instance. For example, issue the following commands to connect to
trgt:% sqlplus SQL> CONNECT SYS/password@trgt AS SYSDBADetermine the status of the database by executing the following SQL query:
SELECT STATUS FROM V$INSTANCE;
If the status is
OPEN, then the database is open. Nevertheless, some datafiles may require media recovery.Query
V$DATAFILE_HEADERto determine the status of your datafiles. Run the following SQL statements to check the datafile headers:COL FILE# FORMAT 999 COL STATUS FORMAT A7 COL ERROR FORMAT A10 COL TABLESPACE_NAME FORMAT A10 COL NAME FORMAT A30 SELECT FILE#, STATUS, ERROR, RECOVER, TABLESPACE_NAME, NAME FROM V$DATAFILE_HEADER WHERE RECOVER = 'YES' OR (RECOVER IS NULL AND ERROR IS NOT NULL);
Each row returned represents a datafile that either requires media recovery or has an error requiring a restore. Check the
RECOVERandERRORcolumns.RECOVERindicates whether a file needs media recovery, andERRORindicates whether there was an error reading and validating the datafile header.If
ERRORis notNULL, then the datafile header cannot be read and validated. Check for a temporary hardware or operating system problem causing the error. If there is no such problem, you must restore the file or switch to a copy.If the
ERRORcolumn isNULLand theRECOVERcolumn isYES, then the file requires media recovery (and may also require a restore from backup).Optionally, query
V$RECOVER_FILEto list datafiles requiring recovery by datafile number with their status and error information. For example, execute the following query:SELECT FILE#, ERROR, ONLINE_STATUS, CHANGE#, TIME FROM V$RECOVER_FILE;
Note:
You cannot useV$RECOVER_FILEwith a control file restored from backup or a control file that was re-created after the time of the media failure affecting the datafiles. A restored or re-created control file does not contain the information needed to updateV$RECOVER_FILEaccurately.To find datafile and tablespace names, you can also perform useful joins using the datafile number and the
V$DATAFILEandV$TABLESPACEviews. For example:COL DF# FORMAT 999 COL DF_NAME FORMAT A35 COL TBSP_NAME FORMAT A7 COL STATUS FORMAT A7 COL ERROR FORMAT A10 COL CHANGE# FORMAT 99999999 SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name, d.STATUS, r.ERROR, r.CHANGE#, r.TIME FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t WHERE t.TS# = d.TS# AND d.FILE# = r.FILE#;
The
ERRORcolumn identifies the problem for each file requiring recovery.