This section describes steps to perform complete recovery while the database is not open. You can recover either all damaged data files in one operation or perform
individual recovery of each damaged data file in separate operations. To restore and recover damaged or missing data files:
- If the database is open, query V$RECOVER_FILE to determine which data files must be recovered and why they must be recovered.
If you are planning to perform complete recovery rather than point-in-time recovery, then you can recover only those data files that require recovery, rather than the whole database. For point-in-time recovery, you must restore and recover all data files, unless you perform TSPITR "Performing RMAN Tablespace Point-in-Time Recovery (TSPITR)".
You can also use Flashback Database, but this procedure affects all data files and returns the entire database to a past time.
You can query the V$RECOVER_FILE view to list data files requiring recovery by data file number with their status and error information.
SELECT FILE#, ERROR, ONLINE_STATUS, CHANGE#, TIME
Note: You cannot use V$RECOVER_FILE with a control file restored from backup or a control file that was re-created after the time of the media failure affecting the data files.
A restored or re-created control file does not contain the information needed to update V$RECOVER_FILE accurately.
You can also perform useful joins by using the data file number and the V$DATAFILE and V$TABLESPACE views to get the data file and tablespace names. Use the following SQL*Plus commands to format the output of the query:
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 ERROR column identifies the problem for each file requiring recovery.
- Query the V$ARCHIVED_LOG and V$RECOVERY_LOG views to determine which archived redo log files are needed. V$ARCHIVED_LOG lists file names for all archived redo logs, whereas V$RECOVERY_LOG lists only the archived redo logs that the database needs to perform media recovery.
The latter view also includes the probable names of the files based on the naming convention specified by using the LOG_ARCHIVE_FORMAT parameter.
Note: V$RECOVERY_LOG is only populated when media recovery is required for a data file. Thus, this view is not useful for a planned recovery, such as recovery from a user error.
If a data file requires recovery, but no backup of the data file exists, then you need all redo generated starting from the time when the data file was added to the database.
- If all archived logs are available in the default location, then skip to the Step 4. If some archived logs must be restored, and if sufficient space is available,
then restore the required archived redo log files to the location specified by LOG_ARCHIVE_DEST_1.
The database locates the correct log automatically when required during media recovery. For example, you might enter a command such as the following on Linux or UNIX:
% cp /disk2/arch/* $ORACLE_HOME/oradata/trgt/arch
If sufficient space is not available, then restore some or all of the required archived redo log files to an alternative location.
- If the database is open, then shut it down.
- Inspect the media to determine the source of the problem. If the hardware problem that caused the media failure was temporary,
and if the data was undamaged (for example, a disk or controller power failure occurred), then no media recovery is required: start the database and resume normal operations. If you cannot repair the problem, then proceed to the Step 6.
- If the files are permanently damaged, then identify the most recent backups for the damaged files. Restore only the data files damaged by the media failure: do not restore undamaged data files or any online redo log files.
For example, if ORACLE_HOME/oradata/trgt/users01.dbf is the only damaged file, then you may find that /backup/users01_10_24_02.dbf is the most recent backup of this file.
If you do not have a backup of a specific data file, then you may be able to create an empty replacement file that can be recovered.
- Use an operating system utility to restore the data files to their default location or to a new location. For example, a Linux or UNIX user restoring users01.dbf to its default location might enter:
% cp /backup/users01_10_24_06.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
Use the following guidelines when determining where to restore data file backups:
- If the hardware problem is repaired and you can restore the data files to their default locations, then restore the data files to their default locations and begin media recovery.
- If the hardware problem persists and you cannot restore data files to their original locations, then restore the data files to an alternative storage device.
Indicate the new location of these files in the control file with the ALTER DATABASE RENAME FILE statement. See Oracle Database Administrator's Guide.
- If you are restoring a data file to a raw disk or partition, then the technique is basically the same as when you are restoring to a file on a file system. Be aware of the naming conventions for files on raw devices (which differ depending on the operating system), and use an operating system utility that supports raw devices.
- Connect to the database with administrator privileges. Then start a new instance and mount, but do not open, the database. For example, enter:
- If you restored one or more damaged data files to alternative locations, then update the control file of the database to reflect the new data file names.
For example, to change the file name of the data file in tablespace users you might enter:
ALTER DATABASE RENAME FILE '?/oradata/trgt/users01.dbf' TO
- Obtain the data file names and statuses of all data files by checking the list of data files that normally accompanies the current control file or by querying the V$DATAFILE view. For example, enter:
SELECT NAME,STATUS FROM V$DATAFILE;
- Ensure that all data files requiring recovery are online. The only exceptions are data files in an offline tablespace that was taken offline normally or data files in a read-only tablespace.
For example, to guarantee that a data file named /oracle/dbs/tbs_10.f is online, enter the following:
ALTER DATABASE DATAFILE '/oracle/dbs/tbs_10.f' ONLINE;
If a specified data file is already online, then the database ignores the statement. If you prefer, create a script to bring all data files online at once, as in the following example:
SELECT 'ALTER DATABASE DATAFILE '''||name||''' ONLINE;' FROM V$DATAFILE;
- If you restored archived redo logs to an alternative location, then you can specify the location before media recovery with the LOGSOURCE parameter of the SET command in SQL*Plus.
For example, if the logs are staged in /tmp, you can enter the following command:
SET LOGSOURCE /tmp
Alternatively, you can skip Step 12 and use the FROM parameter on the RECOVER command as in Step 13. For example, if the logs are staged in /tmp, you can enter the following command:
RECOVER AUTOMATIC FROM '/tmp' DATABASE
Note: Overriding the redo log source does not affect the archive redo log destination for online redo log groups being archived.
Issue a statement to recover the database, tablespace, or data file. For example, enter one of the following RECOVER commands:
RECOVER AUTOMATIC DATABASE # whole database
RECOVER AUTOMATIC TABLESPACE users # specific tablespace
RECOVER AUTOMATIC DATAFILE '?/oradata/trgt/users01.dbf'; # specific data file
If you choose not to automate the application of archived redo logs, then you must accept or reject each prompted log. If you automate recovery, then the database
applies the logs automatically. Recovery continues until all required archived and online redo logs have been applied to the restored data files. The database notifies
you when media recovery is complete:
Media recovery complete.
If no archived redo logs are required for complete media recovery, then the database applies all necessary online redo log files and terminates recovery.
- After recovery terminates, open the database for use:
ALTER DATABASE OPEN;
- After archived logs are applied, and after making sure that a copy of each archived log group still exists in offline storage, delete the restored copy of the archived redo log file to free disk space.
% rm /tmp/*.arc