RelationalDBDesign RelationalDBDesign


Recovery with Archiving  «Prev  Next»
Lesson 7 Recovering an open database, initially closed
Objective List the steps to recover an open database, initially closed.

Recovering open Database, initially closed

Suppose a system failure brings down your database. After some quick investigation, you find that the failure damaged disk 4, which contains datafile USR1ORCL.ORA. As a well-organized DBA, you know that the datafile USR1ORCL.ORA. is not a system or rollback segment datafile, and users can still access the database even if this datafile is offline. In this situation, you decide that the appropriate method to use is recover open database, initially closed.
The following simulation walks you through the steps to recover an open database, initially closed. You may also
Preview all Steps.
The following procedure has been deprecated and is no longer in use.
Perform open Database Recovery (Initially Closed)

Performing Open Database Recovery

It is possible for a media failure to occur while the database remains open, leaving the undamaged data files online and available for use. Damaged data files (but not the tablespaces that contain them) are automatically taken offline if the database writer cannot write to them. If the database writer cannot open a data file, an error is still returned. Queries that cannot read damaged files return errors, but the data files are not taken offline because of the failed queries. For example, you may run a SQL query and see output such as:

ERROR at line 1:
ORA-01116: error in opening database file 3
ORA-01110: data file 11: '/oracle/oradata/trgt/cwmlite02.dbf'
ORA-27041: unable to open file
SVR4 Error: 2: No such file or directory
Additional information: 3
You cannot use the procedure in this section to perform complete media recovery on the SYSTEM tablespace while the database is open. If the media failure damages data files of the SYSTEM tablespace, then the database automatically shuts down.

To restore data files in an open database:

  1. Follow these 3 Steps
    To restore and recover damaged or missing data files:
    Step 1:
    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 .
    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
    FROM V$RECOVER_FILE;
    

    Warning: 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.
    Step 2:
    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.
    Warning: 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.
    Step 3:
    If all archived logs are available in the default location, then continue.
    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.
  2. If the database is open, then take all tablespaces containing damaged data files offline. For example, if the tablespaces users and tools contain damaged data files, then execute the following SQL statements:
    ALTER TABLESPACE users OFFLINE TEMPORARY;
    ALTER TABLESPACE tools OFFLINE TEMPORARY;
    
    If you specify TEMPORARY, then Oracle Database creates a checkpoint for all online data files in the tablespace. Files that are offline when you issue this statement may require media recovery before you bring the tablespace back online. If you specify IMMEDIATE, then you must perform media recovery on the tablespace before bringing it back online.
  3. Inspect the media to determine the source of the problem. You can use the DBVERIFY utility to run an integrity check on offline data files. If the hardware problem that caused the media failure was temporary, and if the data was undamaged, then no media recovery is required. You can bring the offline tablespaces online and resume normal operations. If you cannot repair the problem, or if DBVERIFY reports corrupt blocks, then proceed to the Step 4.
  4. If files are permanently damaged, then use operating system commands to restore the most recent backup files of only the data files damaged by the media failure. For example, to restore users01.dbf you might use the cp command on Linux or UNIX as follows:
    % cp /disk2/backup/users01.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
    
    If the hardware problem is fixed and the data files can be restored to their original locations, then do so. Otherwise, restore the data files to an alternative storage device. Do not restore undamaged data files, online redo logs, or control files.
  5. 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 '/disk2/users01.dbf';
    
  6. 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 6 and use the FROM parameter on the RECOVER command as in Step 7. For example, if the logs are staged in /tmp, you can enter the following command:
    RECOVER AUTOMATIC FROM '/tmp' TABLESPACE users, tools;
    
    Warning: In some circumstances, if you do not have a backup of a specific data file, you can use the ALTER DATABASE CREATE DATAFILE statement to create an empty replacement file that is recoverable.
    Note: Overriding the redo log source does not affect the archive redo log destination for online redo log groups being archived.
  7. Connect to the database with administrator privileges, and start offline tablespace recovery of all damaged data files in one or more offline tablespaces using one step. For example, recover users and tools as follows:
    RECOVER AUTOMATIC TABLESPACE users, tools;
    
    The database begins the roll forward phase of media recovery by applying the necessary archived and online redo logs to reconstruct the restored data files. Unless the application of files is automated with the RECOVER AUTOMATIC or SET AUTORECOVERY ON commands, the database prompts for each required redo log file. Recovery continues until all required archived logs have been applied to the data files. The online redo logs are then automatically applied to the restored data files to complete media recovery. If no archived redo logs are required for complete media recovery, then the database does not prompt for any. Instead, all necessary online redo logs are applied, and media recovery is complete.
  8. When the damaged tablespaces are recovered up to the moment that media failure occurred, bring the offline tablespaces online. For example, to bring tablespaces users and tools online, issue the following statements:
    ALTER TABLESPACE users ONLINE;
    ALTER TABLESPACE tools ONLINE;
    
The next lesson wraps up this module.