Recovery with Archiving  «Prev  Next»

```html
Lesson 4 The Complete Recovery Operation
Objective List the steps and commands for complete media recovery using log files, assuming the current control file remains intact.

Complete Media Recovery in Oracle AI Database 26ai

Complete media recovery restores damaged or lost datafiles and applies the recovery information needed to bring them to the current required consistency point. In Oracle AI Database 26ai, this information can include archived redo, surviving online redo, and applicable incremental backups.

The essential sequence is to diagnose the failure, establish the required database state, restore the affected files, recover them, and verify that normal operation can resume. RMAN is the preferred tool for coordinating physical backup restoration and recovery. SQL*Plus also supports user-managed media recovery by applying redo to restored datafiles.

This lesson assumes an ARCHIVELOG primary database with a surviving current control file, usable startup configuration, and sufficient backups and redo. The main example concerns a single-instance multitenant container database, or CDB, with an administrative connection to its root. Recovery using a backup control file, point-in-time recovery, and specialized RAC or PDB procedures require additional decisions.

Understand the Goal Before Restoring Files

Complete recovery is different from choosing an earlier time to undo an unwanted transaction. Its goal is to preserve the changes needed for the current consistent state. Applying the last archived log you happen to have does not prove that this goal has been reached.

For example, a restored morning datafile backup may need the day's archived redo and changes still present in an online redo log. Losing that final required redo can prevent complete recovery, even though ARCHIVELOG mode was enabled.

Also distinguish media recovery from an ordinary instance crash. If the database files and required online redo remain intact, Oracle normally performs automatic instance recovery during reopening. Restoring an older backup merely because the instance stopped can introduce unnecessary recovery work.

Steps in a Complete Recovery Operation

1. Diagnose the Failure and Identify the Affected Scope

Read the alert log and reported errors. Determine whether files are missing, temporarily inaccessible, or damaged, and identify their container and tablespace. Correct an underlying storage or access problem before assuming a backup must be restored.

Use file metadata, datafile-header checks, and appropriate RMAN diagnostics to establish what needs attention. In RMAN, the following command reports database file information:

REPORT SCHEMA;

Choose the smallest appropriate recovery scope. A lost application datafile does not automatically require restoring every file in the CDB. Conversely, files supporting SYSTEM or active undo cannot be treated like an ordinary application file that can simply remain offline.

2. Confirm the Recovery Inputs

Identify usable backups for the affected files and the redo needed to advance them. Preserve good current control files and online redo logs. A recovery catalog helps locate backups through metadata; it does not contain the backup data itself.

Check backup-media access, available restore space, and required credentials. For encrypted data or backups, ensure the necessary keystores, keys, or backup passwords are available and opened or supplied as required by the encryption method.

For a whole-database restore, this RMAN command previews backup selection:

RESTORE DATABASE PREVIEW;

Preview examines repository information. It does not read the backup contents to establish their integrity. Restore validation provides that additional check without writing restored datafiles:

RESTORE DATABASE VALIDATE;

Use a scope appropriate to the incident and account for the I/O and time required. Successful backup validation still does not replace verifying the complete recovery procedure and application result.

3. Establish the Required Database State

Whole-CDB datafile restoration and recovery require the database to be mounted, not open. If the instance is already stopped and its current control file and startup configuration are usable, STARTUP MOUNT establishes this state directly.

If the database is open, determine whether to close it or isolate eligible affected files for recovery while other data remains available. Files being restored to their active locations must be offline when the database remains open. Use the appropriate mounted procedure for critical-file recovery.

Shutdown behavior depends on the incident. Do not make an abort shutdown a routine recovery step. Similarly, do not restore the control file simply because a datafile was lost; the surviving current control file is valuable recovery information.

4. Restore the Files That Require Restoration

Restoration retrieves a suitable earlier copy of each affected file. It does not by itself bring that file current. RMAN selects backups using its repository and the applicable restore criteria.

For user-managed backups, the DBA restores valid physical file copies using the appropriate storage or operating-system procedure. SQL*Plus RECOVER cannot unpack an RMAN backup set; use RMAN to restore that backup format.

If the original storage location is unavailable, file relocation requires the corresponding metadata update. RMAN supports SET NEWNAME and SWITCH for suitable relocation workflows. Keep relocation decisions explicit rather than silently restoring a file somewhere the database will not use.

5. Apply the Required Recovery Information

RMAN RECOVER advances restored datafiles using the recovery information needed for consistency. It can restore required archived redo from backup and use applicable incremental backups. Surviving online redo may supply the most recent required changes.

Run the complete-recovery example in a session without an earlier point-in-time restriction such as SET UNTIL. Inspect errors and completion messages before continuing. Exhausting the logs in one directory is not the same as completing media recovery.

If a required archived log is missing, search other copies and backups. Applicable incrementals may also help advance datafiles. An unresolved gap in the selected recovery path means the intended complete-recovery endpoint has not been reached.

6. Open Normally or Return Recovered Files Online

After successful complete recovery using the current control file, the whole-database example opens with ALTER DATABASE OPEN. RESETLOGS is not the routine final step for this scenario.

Recovery using a backup control file requires RESETLOGS even when all required redo is applied. Deliberate database point-in-time recovery also has different opening requirements. Neither operation should be substituted silently for the current-control-file procedure.

For partial recovery while the database stays open, return the successfully recovered files or tablespace online as appropriate. Confirm the recovered scope before restoring dependent application access.

7. Verify Service and Resume Backup Protection

Check file status, expected PDB availability, application services, and representative business operations. Review the alert log for new errors. Restore scheduled backup protection and document the files, backups, and recovery information used.

RMAN Example: Whole-Database Complete Recovery

The following RMAN example assumes the instance is stopped, diagnosis has established that whole-database restoration is appropriate, and backup access is configured. Connect to the target CDB root with suitable administrative privileges. Run each stage only after the preceding stage succeeds:

STARTUP MOUNT;
RESTORE DATABASE;
RECOVER DATABASE;
ALTER DATABASE OPEN;

For a smaller recovery scope, select the corresponding datafile or tablespace operations and establish their required offline state. Do not run this whole-database example and a partial recovery example consecutively as though both are required.

Oracle's complete database recovery guide provides procedures for individual recovery scopes and alternative storage locations.

Worked Scenario: Recovery Needs Another Log

Suppose a storage failure at 14:00 destroys the database's datafiles. The current control file and online redo survive on separate storage. A usable overnight backup and the required archived redo are available, but some archived logs have been removed from their original disk destination after backup.

After repairing the storage and mounting the database, the DBA uses RMAN to restore the datafiles. At this stage, the restored files contain older data. The fact that RESTORE succeeded does not establish that transactions committed during the morning are present.

During RECOVER, RMAN applies available recovery information and requests another archived sequence. If that sequence exists in an accessible backup known to RMAN, recovery can restore and apply it. If the backup is on unavailable media, the DBA must restore access to that media or locate another usable copy before continuing.

With SQL*Plus user-managed recovery, the DBA instead supplies the required log file after retrieving it through the appropriate restoration procedure. Enabling AUTOMATIC does not perform that retrieval. This is the practical difference between automatic filename selection and RMAN's coordination of backup restoration.

Finally, recovery may need changes that were still in online redo when the failure occurred. Preserving those surviving logs can therefore make the difference between complete recovery and losing the latest changes. Once media recovery succeeds with the current control file, the DBA opens normally and verifies application access.

If required redo is permanently unavailable and no usable backup or incremental recovery path can bridge the gap, the complete-recovery plan cannot simply skip it. Keep the affected data unavailable while evaluating alternatives. Choosing an earlier recoverable endpoint changes the recovery objective and requires planning for the resulting data loss and consistency across the affected scope.

Three Basic SQL*Plus Recovery Commands

SQL*Plus provides three common recovery scopes. The examples below are alternatives. They assume suitable file backups have already been restored and the necessary redo is available.

The tablespace name users and datafile number 7 are illustrative. Verify the actual object, file number, and container before using a command.

SQL*Plus Complete Media Recovery Scopes
Command example Files addressed Required state
RECOVER AUTOMATIC DATABASE Online datafiles requiring database recovery; address offline files separately where required. Database mounted, not open.
RECOVER AUTOMATIC TABLESPACE users Datafiles belonging to the named tablespace. Tablespace offline; database mounted or open as supported.
RECOVER AUTOMATIC DATAFILE 7 The specified datafile; a quoted full filename can also identify it. Appropriate mounted recovery state, or eligible affected file offline while the database remains open.

A tablespace is identified by its name, while a datafile is identified by its file number or filename. Do not use a tablespace name as though it were a datafile identifier.

These are SQL*Plus commands. RMAN uses its own RECOVER syntax and does not accept the SQL*Plus AUTOMATIC option. The server SQL statement ALTER DATABASE RECOVER is another interface; it is not an Enterprise Manager prefix to add indiscriminately. See the SQL*Plus RECOVER reference.

Automatic Selection of Redo Logs

During user-managed recovery, SQL*Plus can suggest archived-log filenames and apply accessible logs with the expected names. Three related controls reduce repeated filename entry:

  • Enter AUTO when an interactive recovery prompt requests a log.
  • Specify AUTOMATIC in the SQL*Plus RECOVER command.
  • Enable SQL*Plus autorecovery before issuing RECOVER.

The third approach can be expressed as:

SET AUTORECOVERY ON
RECOVER DATABASE

These controls select expected archived-log filenames. They do not retrieve missing backups and do not guarantee that SQL*Plus will locate required online redo automatically. Resolve a missing required log or supply the appropriate full filename when necessary.

If the final required redo remains in an online log, identify the correct surviving member for the requested thread and sequence. Continue until recovery reports successful completion, rather than stopping merely because the last archived file was applied.

CANCEL stops a recovery attempt. It does not prove completion or automatically determine that RESETLOGS is required. Recovery can be resumed after missing information becomes available. Intentionally accepting an earlier endpoint requires a separately planned incomplete-recovery procedure.

Specifying Alternate Archived-Log Locations

Archived logs may have been restored to a temporary directory because their original destination is unavailable. Point the recovery session to that location rather than changing the database's ongoing archiving configuration merely to find existing files.

In SQL*Plus, the FROM clause identifies the source for one recovery command:

RECOVER AUTOMATIC FROM '/restore/archivelogs' DATABASE

Alternatively, set the SQL*Plus log source before starting recovery:

SET LOGSOURCE /restore/archivelogs
RECOVER AUTOMATIC DATABASE

The directory is illustrative and must contain accessible required logs. Use these as separate alternatives; do not combine FROM with an active SET LOGSOURCE setting. An individual fully qualified filename can also be entered at a recovery prompt.

RMAN has a separate control for the destination of restored archived logs. Within an appropriate RUN block, SET ARCHIVELOG DESTINATION directs their staging. RMAN can restore logs as recovery proceeds, so manually staging every log before starting is optional.

Backups on tape or other SBT storage still require functioning media-management access and enough disk space for restored logs. The SQL*Plus SET reference explains LOGSOURCE and AUTORECOVERY.

Locating Files and Logs Needed for Recovery

Dynamic performance views help identify affected files and recorded recovery information. Their contents describe database metadata and state; they do not replace checking that physical files and backups can actually be read.

Views Used During Media-Recovery Diagnosis
View Information and limitations
V$RECOVER_FILE Reports datafiles requiring recovery and related status/error information. A restored or re-created control file may lack information needed for accurate results.
V$DATAFILE Maps file numbers to filenames and container identifiers; useful while the database is mounted.
V$DATAFILE_HEADER Reports header state and recovery requirements. Header checks do not detect every corrupt data block.
V$RECOVERY_LOG Reports archived-log requirements associated with media recovery; it is not a complete backup inventory.
V$ARCHIVED_LOG Records archived-log metadata and names. Multiple records may represent different copies of the same redo.
V$LOG_HISTORY Records log history. It does not provide filesystem locations or prove that a log remains available.

Example Diagnostic Queries

Use a suitably privileged administrative connection to the CDB root after mounting or opening as appropriate. First inspect recorded recovery requirements:

SELECT file#, error, online_status, change#, time
FROM v$recover_file;

The column is ONLINE_STATUS, not STATUS. Then map file numbers to their names and containers:

SELECT con_id, file#, name
FROM v$datafile
ORDER BY con_id, file#;

For recovery-log requirements, inspect:

SELECT *
FROM v$recovery_log;

Results depend on the recovery context and container visibility. V$DATAFILE is preferable to DBA_DATA_FILES for mounted-database work. If combining container-aware views, include container identity in joins where appropriate.

Use V$DATAFILE_HEADER and the alert log to investigate further. Empty recovery-view results do not guarantee that every data block is healthy or that the application is operating correctly.

Verify Recovery and Protect the Result

After recovery, verify the affected files and intended application service. Where additional integrity checking is appropriate, RMAN VALIDATE checks database files, while CHECK LOGICAL can extend validation to supported block-level logical checks. Choose the scope and timing according to the incident and workload.

These checks do not establish business correctness. Confirm that expected PDBs and services are available and that representative application operations succeed. Record any intentionally offline files or closed PDBs so that an OPEN database is not mistaken for complete service availability.

A post-recovery backup may be appropriate under the backup policy. In RMAN, the following command protects database files and archived redo:

BACKUP DATABASE PLUS ARCHIVELOG;

If taken online, this is a recoverable online backup, not a shutdown-consistent backup. Preserve the associated recovery information and confirm backup completion. A tested recovery procedure includes usable backups, required logs, keys, credentials, and application verification.

Complete DB Recovery Basics - Quiz

Test your understanding of recovery scope, redo application, diagnostic views, and the opening requirements for complete recovery.

Complete DB Recovery Basics - Quiz

The next lesson demonstrates how to perform a closed database recovery.


SEMrush Software 4 SEMrush Banner 4