Oracle® Database Backup and Recovery Advanced User's Guide 10g Release 1 (10.1) Part Number B10734-01 |
|
|
View PDF |
This chapter describes how to restore and recover a database. It includes the following topics:
Oracle's flashback features, which let you undo damage to your database after logical data corruption, include the following:
DROP TABLE
operation;All of these operations are available within SQL*Plus, and none of them require the use of Recovery Manager. More details about using the flashback features of Oracle in data recovery situations are provided in "Oracle Flashback Technology: Overview".
The SQL*Plus FLASHBACK DATABASE
command performs the same function as the RMAN FLASHBACK DATABASE
command: it returns the database to a prior state.
Note that using Flashback Database requires that you create a flash recovery area for your database and enable the collection of flashback logs. See "Oracle Flashback Database: Alternative to Point-In-Time Recovery" for more details about how the Flashback Database feature works, requirements for using Flashback Database , and how to enable collection of flashback logs required for Flashback Database. The requirements and preparations are the same whether you use RMAN or user-managed backup and recovery.
To perform the FLASHBACK DATABASE
operation:
SQL> SELECT CURRENT_SCN FROM V$DATABASE; SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG;
FLASHBACK DATABASE
statement to return the database to a prior TIMESTAMP
or SCN
. For example:
FLASHBACK DATABASE TO SCN 46963; FLASHBACK DATABASE TO TIMESTAMP (SYSDATE-1/24); FLASHBACK DATABASE TO TIMESTAMP timestamp'2002-11-05 14:00:00'; FLASHBACK DATABASE TO TIMESTAMP to_timestamp('2002-11-11 16:00:00', 'YYYY-MM-DD HH24:MI:SS');
Open the database read-only to examine the results of the Flashback Database operation. When the operation completes, you can open the database read-only and perform some queries to make sure you have recovered the data you need. If you find that you need to perform Flashback Database again to a different target time, then use RECOVER DATABASE
to return the database back to the present time, and then try another FLASHBACK DATABASE
statement.
If you are satisfied with the results of Flashback Database, then you can re-open your database with the RESETLOGS option. If appropriate, you can also use an Oracle export utililty like Data Pump Export to save lost data, use RECOVER DATABASE
to return the database to the present, and re-import the lost object.
To restore a file is to replace it with a backup file. Typically, you restore a file when a media failure or user error has damaged or deleted the original file. The following files are candidates for restore operations:
In each case, the loss of a primary file and the restore of a backup has the following implications for media recovery.
Note: Restore and recovery of Oracle-managed files is no different from restore and recovery of user-named files. |
You can use the dynamic performance view V$RECOVER_FILE
to determine which files to restore in preparation for media recovery. This view lists all files that need to be recovered and explains why they need to be recovered.
The following query displays the file ID numbers of datafiles that require media recovery as well as the reason for recovery (if known) and the SCN and time when recovery needs to begin:
SELECT * FROM V$RECOVER_FILE; FILE# ONLINE ERROR CHANGE# TIME ---------- ------- ------------------ ---------- --------- 14 ONLINE 0 15 ONLINE FILE NOT FOUND 0 21 OFFLINE OFFLINE NORMAL 0
Query V$DATAFILE
and V$TABLESPACE
to obtain filenames and tablespace names for datafiles requiring recovery. For example, enter:
SELECT d.NAME, t.NAME AS tablespace_name FROM V$DATAFILE d, V$TABLESPACE t WHERE t.TS# = d.TS# AND d.FILE# IN (14,15,21); # use values obtained from V$RECOVER_FILE query
You can combine these queries in the following SQL*Plus script (sample output show in the following example):
COL df# FORMAT 999 COL df_name FORMAT a20 COL tbsp_name FORMAT a10 COL status FORMAT a7 COL error FORMAT a10 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# /
This section contains the following topics:
If a media failure permanently damages one or more datafiles of a database, then you must restore backups of these datafiles before you can recover the damaged files. If you cannot restore a damaged datafile to its original location (for example, you must replace a disk, so you restore the files to an alternate disk), then you must indicate the new locations of these files to the control file.
If you are restoring a database file on a raw disk or partition, then the procedure is basically the same as when restoring to a file on a file system. However, 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.
See Also:
"Making User-Managed Backups to Raw Devices" for an overview of considerations when backing up and restoring files on raw devices |
To restore backup datafiles to their default location:
ALTER TABLESPACE users OFFLINE IMMEDIATE;
users01.dbf
you might issue:
% cp /disk2/backup/users01.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
RECOVER TABLESPACE users
ALTER TABLESPACE users ONLINE;
All archived redo logs generated between the time a restored backup was created and the target recovery time are required for the pending recovery. The archived logs will eventually need to be on disk so that they are available to the database.
To restore necessary archived redo logs:
V$ARCHIVED_LOG
and V$RECOVERY_LOG
. If a datafile requires recovery, but no backup of the datafile exists, then you need all redo generated starting from the time when the datafile was added to the database.
LOG_ARCHIVE_DEST_1
. The database locates the correct log automatically when required during media recovery. For example, enter:
% cp /disk2/arch/* $ORACLE_HOME/oradata/trgt/arch
LOGSOURCE
parameter of the SET
statement in SQL*Plus or the RECOVER
...
FROM
parameter of the ALTER
DATABASE
statement in SQL. For example, enter:
SET LOGSOURCE /tmp # set location using SET statement DATABASE RECOVER FROM '/tmp'; # set location in RECOVER statement
% rm /tmp/*.dbf
See Also:
Oracle Database Reference for more information about the data dictionary views, and "About User-Managed Media Recovery" for an overview of log application during media recovery |
This section contains the following topics:
Use the following procedures to recover a database if a permanent media failure has damaged one or more control files of a database and at least one control file has not been damaged by the media failure.
If the disk and file system containing the lost control file are intact, then you can simply copy one of the intact control files to the location of the missing control file. In this case, you do not have to alter the CONTROL_FILES
initialization parameter setting.
To replace a damaged control file by copying a multiplexed control file:
SHUTDOWN ABORT
bad_cf.f
with good_cf.f
, you might enter:
% cp /oracle/good_cf.f /oracle/dbs/bad_cf.f
STARTUP
Assuming that the disk and file system containing the lost control file are not intact, then you cannot copy one of the good control files to the location of the missing control file. In this case, you must alter the CONTROL_FILES
initialization parameter to indicate a new location for the missing control file.
To restore a control file to a nondefault location:
SHUTDOWN ABORT
control01.dbf
to a new disk location you might issue:
% cp $ORACLE_HOME/oradata/trgt/control01.dbf /new_disk/control01.dbf
CONTROL_FILES
parameter reflects the current locations of all control files and excludes all control files that were not restored. Assume the initialization parameter file contains:
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/bad_disk/control02.dbf'
Then, you can edit it as follows:
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf','/new_disk/control02.dbf'
STARTUP
Use the following procedures to restore a backup control file if a permanent media failure has damaged all control files of a database and you have a backup of the control file. When a control file is inaccessible, you can start the instance, but not mount the database. If you attempt to mount the database when the control file is unavailable, then you receive this error message:
ORA-00205: error in identifying controlfile, check alert log for more info
You cannot mount and open the database until the control file is accessible again. If you restore a backup control file, then you must open RESETLOGS
.
As indicated in Table 17-1, the procedure for restoring the control file depends on whether the online redo logs are available.
If possible, restore the control file to its original location. In this way, you avoid having to specify new control file locations in the initialization parameter file.
To restore a backup control file to its default location:
SHUTDOWN ABORT
CONTROL_FILES
parameter. For example, if ORACLE_HOME
/oradata/trgt/control01.dbf
and ORACLE_HOME
/oradata/trgt/control02.dbf
are the control file locations listed in the server parameter file, then use an operating system utility to restore the backup control file to these locations:
% cp /backup/control01.dbf ORACLE_HOME/oradata/trgt/control01.dbf % cp /backup/control02.dbf ORACLE_HOME/oradata/trgt/control02.dbf
STARTUP MOUNT
RECOVER
command with the USING
BACKUP
CONTROLFILE
clause. Specify UNTIL
CANCEL
if you are performing incomplete recovery. For example, enter:
RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL
For example, assume that you see the following:
ORA-00279: change 55636 generated at 11/08/2002 16:59:47 needed for thread 1 ORA-00289: suggestion : /oracle/work/arc_dest/arcr_1_111.arc ORA-00280: change 55636 for thread 1 is in sequence #111 Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
You can specify the name of an online redo log and press Enter (you may have to try this a few times until you find the correct log):
ORACLE_HOME/oradata/redo01.dbf Log applied. Media recovery complete.
If the online logs are inaccessible, then you can cancel recovery without applying them. If all datafiles are current, and if redo in the online logs is required for recovery, then you cannot open the database without applying the online logs. If the online logs are inaccessible, then you must re-create the control file (refer to "Losing All Current and Backup Control Files").
RESETLOGS
option after finishing recovery:
ALTER DATABASE OPEN RESETLOGS;
If you cannot restore the control file to its original place because the media damage is too severe, then you must specify new control file locations in the server parameter file. A valid control file must be available in all locations specified by the CONTROL_FILES
initialization parameter. If not, then the database prevents you from the mounting the database.
To restore a control file to a nondefault location:
Follow the steps in "Restoring a Backup Control File to the Default Location", except after step 2 add the following step:
Edit all locations specified in the CONTROL_FILES
initialization parameter to reflect the new control file locations. For example, if the control file locations listed in the server parameter file are as follows, and both locations are inaccessible:
CONTROL_FILES='/oracle/oradata/trgt/control01.dbf', '/oracle/oradata/trgt/control01.dbf'
Then, you can edit the initialization parameter file as follows:
CONTROL_FILES='/good_disk/control01.dbf','/good_disk/control02.dbf'
If all control files have been lost in a permanent media failure, but all online redo log members remain intact, then you can recover the database after creating a new control file. The advantage of this tactic is that you are not required to open the database with the RESETLOGS
option.
Depending on the existence and currency of a control file backup, you have the options listed in Table 17-2 for generating the text of the CREATE
CONTROLFILE
statement. Note that changes to the database are recorded in the alert_
SID.log
, so check this log when deciding which option to choose.
If you . . . | Then . . . |
---|---|
Executed |
Use the |
Performed your most recent execution of |
Edit the output of |
Backed up the control file with the |
Use the control file copy to obtain SQL output. Create a temporary database instance, mount the backup control file, and then run |
Do not have a control file backup in either |
Execute the |
To create a new control file:
NOMOUNT
mode. For example, enter:
STARTUP NOMOUNT
CREATE
CONTROLFILE
statement, specifying the NORESETLOGS
option (refer to Table 17-2 for options). The following example assumes that the character set is the default US7ASCII:
CREATE CONTROLFILE REUSE DATABASE SALES NORESETLOGS ARCHIVELOG MAXLOGFILES 32 MAXLOGMEMBERS 2 MAXDATAFILES 32 MAXINSTANCES 16 MAXLOGHISTORY 1600 LOGFILE GROUP 1 ( '/diska/prod/sales/db/log1t1.dbf', '/diskb/prod/sales/db/log1t2.dbf' ) SIZE 100K GROUP 2 ( '/diska/prod/sales/db/log2t1.dbf', '/diskb/prod/sales/db/log2t2.dbf' ) SIZE 100K, DATAFILE '/diska/prod/sales/db/database1.dbf', '/diskb/prod/sales/db/filea.dbf';
After creating the control file, the instance mounts the database.
USING
BACKUP
CONTROLFILE
clause):
RECOVER DATABASE
RESETLOGS
option not required):
ALTER DATABASE OPEN;
/backup/control01.dbf
:
ALTER DATABASE BACKUP CONTROLFILE TO '/backup/control01.dbf' REUSE;
See Also:
"Backing Up the Control File to a Trace File", and "Recovering Through RESETLOGS with Created Control File: Scenario" |
During complete or incomplete media recovery, the database applies redo log files to the datafiles during the roll forward phase of media recovery. Because changes to undo segments are recorded in the online redo log, rolling forward regenerates the corresponding undo segments. Rolling forward proceeds through as many redo log files as necessary to bring the database forward in time.
To perform recovery, Oracle Corporation recommends that you use the RECOVER
SQL statement in SQL*Plus. You can also use the SQL statement ALTER
DATABASE
RECOVER
, but the RECOVER statement is simpler in most cases.
To start any type of media recovery, you must adhere to the following restrictions:
Oracle Corporation recommends that you use the SQL*Plus RECOVER
command rather than the ALTER
DATABASE
RECOVER
statement to perform media recovery. In almost all cases, the SQL*Plus method is easier.
When using SQL*Plus to perform media recovery, the easiest strategy is to perform automatic recovery. Automatic recovery initiates recovery without manually prompting SQL*Plus to apply each individual archived log.
When using SQL*Plus, you have two options for automating the application of the default filenames of archived redo logs needed during recovery:
SET
AUTORECOVERY
ON
before issuing the RECOVER
commandAUTOMATIC
keyword as an option of the RECOVER
commandIn either case, no interaction is required when you issue the RECOVER
command if the necessary files are in the correct locations with the correct names. The filenames used when you use automatic recovery are derived from the concatenated values of LOG_ARCHIVE_FORMAT
with LOG_ARCHIVE_DEST_
n
, where n
is the highest value among all enabled, local destinations.
For example, assume the following initialization parameter settings are in effect in the database instance:
LOG_ARCHIVE_DEST_1 = "LOCATION=/arc_dest/loc1/" LOG_ARCHIVE_DEST_2 = "LOCATION=/arc_dest/loc2/" LOG_ARCHIVE_DEST_STATE_1 = DEFER LOG_ARCHIVE_DEST_STATE_2 = ENABLE LOG_ARCHIVE_FORMAT = arch_%t_%s.arc
In this case, SQL*Plus automatically suggests the filename /arc_dest/loc2/arch_%t_%s.arc
(where %t
is the thread and %s
is the sequence).
If you run SET
AUTORECOVERY
OFF
, which is the default option, then you must enter the filenames manually, or accept the suggested default filename by pressing the Enter key.
Run the SET
AUTORECOVERY
ON
command to enable on automatic recovery.
To automate the recovery using SET AUTORECOVERY:
% cp /backup/datafiles/*.dbf $ORACLE_HOME/oradata/trgt/
STARTUP MOUNT
SET AUTORECOVERY ON
RECOVER DATABASE
The database automatically suggests and applies the necessary archived logs.
ALTER DATABASE OPEN;
Besides using SET
AUTORECOVERY
to turn on automatic recovery, you can also simply specify the AUTOMATIC
keyword in the RECOVER
command.
To automate the recovery with the RECOVER AUTOMATIC command:
% cp /backup/datafiles/*.dbf $ORACLE_HOME/oradata/trgt/
STARTUP MOUNT
AUTOMATIC
keyword. This example performs automatic recovery on the whole database:
RECOVER AUTOMATIC DATABASE
The database automatically suggests and applies the necessary archived logs.
ALTER DATABASE OPEN;
If you use an Oracle Real Application Clusters configuration, and if you are performing incomplete recovery or using a backup control file, then the database can only compute the name of the first archived redo log file from the first redo thread. You may have to manually apply the first log file from the other redo threads. After the first log file in a given thread has been supplied, the database can suggest the names of the subsequent logs in this thread.
Recovering when the archived logs are in their default location is the simplest case. As a log is needed, the database suggests the filename. If you are running nonautomatic media recovery with SQL*Plus, then the output is displayed in this format:
ORA-00279: Change #### generated at DD/MM/YY HH:MM:SS needed for thread# ORA-00289: Suggestion : logfile ORA-00280: Change #### for thread # is in sequence # Specify log: [<RET> for suggested | AUTO | FROM logsource | CANCEL ]
For example, SQL*Plus displays output similar to the following:
ORA-00279: change 53577 generated at 11/26/02 19:20:58 needed for thread 1 ORA-00289: suggestion : /oracle/oradata/trgt/arch/arcr_1_802.arc ORA-00280: change 53577 for thread 1 is in sequence #802 Specify log: [<RET> for suggested | AUTO | FROM logsource | CANCEL ]
Similar messages are returned when you use an ALTER
DATABASE
...
RECOVER
statement. However, no prompt is displayed.
The database constructs suggested archived log filenames by concatenating the current values of the initialization parameters LOG_ARCHIVE_DEST_
n
(where n
is the highest value among all enabled, local destinations) and LOG_ARCHIVE_FORMAT
and using log history data from the control file. The following are possible settings:
LOG_ARCHIVE_DEST_1 = 'LOCATION = /oracle/oradata/trgt/arch/' LOG_ARCHIVE_FORMAT = arcr_%t_%s.arc SELECT NAME FROM V$ARCHIVED_LOG; NAME ---------------------------------------- /oracle/oradata/trgt/arch/arcr_1_467.arc /oracle/oradata/trgt/arch/arcr_1_468.arc /oracle/oradata/trgt/arch/arcr_1_469.arc
Thus, if all the required archived log files are mounted at the LOG_ARCHIVE_DEST_1
destination, and if the value for LOG_ARCHIVE_FORMAT
is never altered, then the database can suggest and apply log files to complete media recovery automatically.
Performing media recovery when archived logs are not in their default location adds an extra step. You have the following mutually exclusive options:
LOG_ARCHIVE_DEST_
n
parameter that specifies the location of the archived redo logs, then recover as usual.SET
statement in SQL*Plus to specify the nondefault log location before recovery, or the LOGFILE
parameter of the RECOVER
commandYou can edit the initialization parameter file or issue ALTER
SYSTEM
statements to change the default location of the archived redo logs.
To change the default archived log location before recovery:
% cp /backup/arch/* /tmp/
ALTER
SYSTEM
statements while the instance is started, or edit the initialization parameter file and then start the database instance. For example, while the instance is shut down edit the parameter file as follows:
LOG_ARCHIVE_DEST_1 = 'LOCATION=/tmp/' LOG_ARCHIVE_FORMAT = arcr_%t_%s.arc
STARTUP MOUNT
RECOVER DATABASE
In some cases, you may want to override the current setting for the archiving destination parameter as a source for redo log files.
To recover archived logs in a nondefault location with SET LOGSOURCE:
% cp $ORACLE_HOME/oradata/trgt/arch/* /tmp
LOGSOURCE
parameter of the SET
statement or the RECOVER
...
FROM
clause of the ALTER
DATABASE
statement. For example, start SQL*Plus and run:
SET LOGSOURCE "/tmp"
users
do the following:
RECOVER AUTOMATIC TABLESPACE users
SET
LOGSOURCE
and simply run:
RECOVER AUTOMATIC TABLESPACE users FROM "/tmp"
If you are using SQL*Plus's recovery options (not SQL statements), then each time the database successfully applies a redo log file, the following message is returned:
Log applied.
You are then prompted for the next log in the sequence or, if the most recently applied log is the last required log, terminates recovery.
If the suggested file is incorrect or you provide an incorrect filename, then the database returns an error message. For example, you may see something like:
ORA-00308: cannot open archived log "/oracle/oradata/trgt/arch/arcr_1_811.arc" ORA-27037: unable to obtain file status SVR4 Error: 2: No such file or directory Additional information: 3
Recovery cannot continue until the required redo log is applied. If the database returns an error message after supplying a log filename, then the following responses are possible.
If you start media recovery and must then interrupt it, for example, because a recovery operation must end for the night and resume the next morning, then take either of the following actions:
CANCEL
when prompted for a redo log file.After recovery is canceled, you can resume it later with the RECOVER
command. Recovery resumes where it left off when it was canceled.
When you perform complete recovery, you recover the backups to the current SCN. You can either recover the whole database at once or recover individual tablespaces or datafiles. Because you do not have to open the database with the RESETLOGS
option after complete recovery as you do after incomplete recovery, you have the option of recovering some datafiles at one time and the remaining datafiles later.
This section describes the steps necessary to complete media recovery operations, and includes the following topics:
See Also:
Oracle Database Backup and Recovery Basics for basic information about media recovery concepts, which apply in both user-managed and RMAN-based backup and recovery. |
See Also: Oracle Database Backup and Recovery Basics to familiarize yourself with fundamental recovery concepts and strategies: |
This section describes steps to perform complete recovery while the database is not open. You can recover either all damaged datafiles in one operation, or perform individual recovery of each damaged datafile in separate operations.
Perform the media recovery in the following stages:
In this stage, you shut down the instance and inspect the media device that is causing the problem.
To prepare for closed database recovery:
SHUTDOWN IMMEDIATE
In this stage, you restore all necessary backups.
To restore the necessary files:
For example, if ORACLE_HOME/
oradata/trgt/users01.dbf
is the only damaged file, then you may determine 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 datafile, then you may be able to create an empty replacement file that can be recovered.
users01.dbf
to its default location might enter:
% cp /backup/users01_10_24_02.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
Use the following guidelines when determining where to restore datafile backups.
If . . . | Then . . . |
---|---|
The hardware problem is repaired and you can restore the datafiles to their default locations |
Restore the datafiles to their default locations and begin media recovery. |
The hardware problem persists and you cannot restore datafiles to their original locations |
Restore the datafiles to an alternative storage device. Indicate the new location of these files in the control file with |
In the final stage, you recover the datafiles that you have restored.
To recover the restored datafiles:
STARTUP MOUNT
V$DATAFILE
view. For example, enter:
SELECT NAME,STATUS FROM V$DATAFILE;
/oracle/dbs/tbs_10.f
is online, enter the following:
ALTER DATABASE DATAFILE '/oracle/dbs/tbs_10.f' ONLINE;
If a specified datafile is already online, then the database ignores the statement. If you prefer, create a script to bring all datafiles online at once as in the following:
SPOOL onlineall.sql SELECT 'ALTER DATABASE DATAFILE '''||name||''' ONLINE;' FROM V$DATAFILE; SPOOL OFF SQL> @onlineall
RECOVER
command:
RECOVER DATABASE # recovers whole database RECOVER TABLESPACE users # recovers specific tablespace RECOVER DATAFILE '?/oradata/trgt/users01.dbf'; # recovers specific datafile
Follow these guidelines when deciding which statement to execute:
Media recovery complete.
If no archived redo log files are required for complete media recovery, then the database applies all necessary online redo log files and terminates recovery.
ALTER DATABASE OPEN;
See Also:
"About User-Managed Media Recovery" for more information about applying redo log files |
It is possible for a media failure to occur while the database remains open, leaving the undamaged datafiles online and available for use. Damaged datafiles--but not the tablespaces that contain them--are automatically taken offlineif the database writer is unable to write to them. Queries that cannot read damaged files return errors, but the datafiles are not taken offline because of the failed queries. For example, you may run a 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
The procedure in this section cannot be used to perform complete media recovery on the datafiles of the SYSTEM
tablespace while the database is open. If the media failure damages datafiles of the SYSTEM
tablespace, then the database automatically shuts down.
Perform media recovery in these stages:
See Also:
|
In this stage, you take affected tablespaces offline and inspect the media device that is causing the problem.
To prepare for datafile recovery when the database is open:
users
and tools
contain damaged datafiles, enter:
ALTER TABLESPACE users OFFLINE TEMPORARY; ALTER TABLESPACE tools OFFLINE TEMPORARY;
In this stage, you restore all necessary backups in the offline tablespaces.
To restore datafiles in an open database:
users
you might enter:
ALTER DATABASE RENAME FILE '?/oradata/trgt/users01.dbf' TO '/disk2/users01.dbf';
See Also:
Oracle Database SQL Reference for more information about |
In the final stage, you recover the datafiles in the offline tablespaces.
To recover offline tablespaces in an open database:
users
and tools
:
RECOVER TABLESPACE users, tools # recovers datafiles in users and tools
Note: For best performance, use parallel recovery to recover the datafiles. See "Performing Media Recovery in Parallel". |
RECOVER
AUTOMATIC
or SET
AUTORECOVERY
ON
, the database prompts for each required redo log file.
Recovery continues until all required archived logs have been applied to the datafiles. The online redo logs are then automatically applied to the restored datafiles 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.
users
and tools
online, issue the following statements:
ALTER TABLESPACE users ONLINE; ALTER TABLESPACE tools ONLINE;
See Also:
Oracle Database Administrator's Guide for more information about creating datafiles |
This section describes the steps necessary to complete the different types of incomplete media recovery operations, and includes the following topics:
In this phase, you examine the source of the media problem.
To prepare for incomplete recovery:
SHUTDOWN ABORT
In this phase, you restore a whole database backup.
To restore the files necessary for cancel-based recovery and bring them online:
If . . . | Then . . . |
---|---|
You do not have a backup of a datafile |
Create an empty replacement file that can be recovered as described in "Restoring Backups of the Damaged or Missing Files". |
A datafile was added after the intended time of recovery |
Do not restore a backup of this file because it will no longer be used for the database after recovery completes. |
The hardware problem causing the failure has been solved and all datafiles can be restored to their default locations |
Restore the files as described in "Restoring Datafiles and Archived Redo Logs" and skip Step 4 of this procedure. |
A hardware problem persists |
Restore damaged datafiles to an alternative storage device. |
STARTUP MOUNT
ALTER DATABASE RENAME FILE '?/oradata/trgt/users01.dbf' TO '/disk2/users01.dbf';
V$DATAFILE
view. For example, enter:
SELECT NAME,STATUS FROM V$DATAFILE;
NORMAL
option or is a read-only tablespace. For example, to guarantee that a datafile named ?/oradata/trgt/users01.dbf
is online, enter the following:
ALTER DATABASE DATAFILE '?/oradata/trgt/users01.dbf' ONLINE;
If a specified datafile is already online, the statement has no effect. If you prefer, create a script to bring all datafiles online at once as in the following:
SPOOL onlineall.sql SELECT 'ALTER DATABASE DATAFILE '''||name||''' ONLINE;' FROM V$DATAFILE; SPOOL OFF SQL> @onlineall
In cancel-based recovery, recovery proceeds by prompting you with the suggested filenames of archived redo log files. Recovery stops when you specify CANCEL
instead of a filename or when all redo has been applied to the datafiles.
Cancel-based recovery is better than change-based or time-based recovery if you want to control which archived log terminates recovery. For example, you may know that you have lost all logs past sequence 1234, so you want to cancel recovery after log 1233 is applied.
You should perform cancel-based media recovery in these stages:
To perform cancel-based recovery:
STARTUP MOUNT
RECOVER DATABASE UNTIL CANCEL
If you are using a backup control file with this incomplete recovery, then specify the USING
BACKUP
CONTROLFILE
option in the RECOVER
command.
RECOVER DATABASE UNTIL CANCEL USING BACKUP CONTROLFILE
LOG_ARCHIVE_DEST_1
and requests you to stop or proceed with applying the log file. Note that if the control file is a backup, then you must supply the names of the online logs if you want to apply the changes in these logs.
CANCEL
The database indicates whether recovery is successful. If you cancel before all the datafiles have been recovered to a consistent SCN and then try to open the database, you will get an ORA-1113
error if more recovery is necessary. As explained in "Determining Which Datafiles Require Recovery", you can query V$RECOVER_FILE
to determine whether more recovery is needed, or if a backup of a datafile was not restored prior to starting incomplete recovery.
RESETLOGS
option. You must always reset the logs after incomplete recovery or recovery with a backup control file. For example:
ALTER DATABASE OPEN RESETLOGS;
This section describes how to perform the time-based media recovery procedure in the following stages:
To perform change-based or time-based recovery:
RECOVER
DATABASE
UNTIL
statement to begin recovery. If recovering to an SCN, specify as a decimal number without quotation marks. For example, to recover through SCN 10034 issue:
RECOVER DATABASE UNTIL CHANGE 10034;
If recovering to a time, the time is always specified using the following format, delimited by single quotation marks: 'YYYY-MM-DD:HH24:MI:SS'
. The following statement recovers the database up to a specified time:
RECOVER DATABASE UNTIL TIME '2000-12-31:12:47:30'
RESETLOGS
mode. You must always reset the online logs after incomplete recovery or recovery with a backup control file. For example:
ALTER DATABASE OPEN RESETLOGS;
Whenever you perform incomplete recovery or recovery with a backup control file, you must reset the online logs when you open the database. The new version of the reset database is called a new incarnation.
This section contains the following topics:
The RESETLOGS
option is always required after incomplete media recovery or recovery using a backup control file. Resetting the redo log does the following:
RESETLOGS
, then the database archives logs 1000 and 1001 and then resets the online logs to sequence 1 and 2.RESETLOGS
SCN
and time stamp.Because the database will not apply an archived log to a datafile unless the RESETLOGS
SCN
and time stamps match, the RESETLOGS
prevents you from corrupting datafiles with archived logs that are not from direct parent incarnations of the current incarnation.
In prior releases, it was recommended that you back up the database immediately after the RESETLOGS
. Because you can now easily recover a pre-RESETLOGS
backup like any other backup, making a new database backup is optional. In order to perform recovery through resetlogs you must have all archived logs generated since the last backup and at least one control file (current, backup, or created).
Figure 17-1 shows the case of a database that can only be recovered to log sequence 2500 because an archived redo log is missing. When the online redo log is at sequence 4000, the database crashes. You restore the sequence 1000 backup and prepare for complete recovery. Unfortunately, one of your archived logs is corrupted. The log before the missing log contains sequence 2500, so you recover to this log sequence and open RESETLOGS
. As part of the RESETLOGS
, the database archives the current online logs (sequence 4000 and 4001) and resets the log sequence to 1.
You generate changes in the new incarnation of the database, eventually reaching log sequence 4000. The changes between sequence 2500 and sequence 4000 for the new incarnation of the database are different from the changes between sequence 2500 and sequence 4000 for the old incarnation. You cannot apply logs generated after 2500 in the old incarnation to the new incarnation, but you can apply the logs generated before 2500 in the old incarnation to the new incarnation. The invalid logs are said to be orphaned in the new incarnation because they are unusable for recovery.
Text description of the illustration bradv036.gif
To preserve the log sequence number when opening a database after media recovery, execute either of the following statements:
ALTER DATABASE OPEN NORESETLOGS; ALTER DATABASE OPEN;
To reset the log sequence number when opening a database after recovery and thereby create a new incarnation of the database, execute the following statement:
ALTER DATABASE OPEN RESETLOGS;
If you open with the RESETLOGS
option, the database returns different messages depending on whether recovery was complete or incomplete. If the recovery was complete, then the following message appears in the alert_
SID
.log
file:
RESETLOGS after complete recovery through change scn
If the recovery was incomplete, then this message is reported in the alert_
SID
.log
file, where scn
refers to the end point of incomplete recovery:
RESETLOGS after incomplete recovery UNTIL CHANGE scn
If you attempt to OPEN
RESETLOGS
when you should not, or if you neglect to reset the log when you should, then the database returns an error and does not open the database. Correct the problem and try again.
See Also:
"About User-Managed Media Recovery Problems" for descriptions of situations that can cause |
After opening the database with the RESETLOGS
option, check the alert_
SID
.log
to see whether the database detected inconsistencies between the data dictionary and the control file, for example, a datafile that the data dictionary includes but which is not listed in the new control file. The following table describes two possible scenarios.
If a media failure damages datafiles in a NOARCHIVELOG
database, then the only option for recovery is usually to restore a consistent whole database backup. If you are using logical backups created by an Oracle export utility to supplement regular physical backups, then you can also attempt to restore the database by importing an exported backup of the database into a re-created database or a database restored from an old backup.
In this scenario, the media failure is repaired so that you are able to restore all database files to their original location.
To restore the most recent whole database backup to the default location:
SHUTDOWN IMMEDIATE
% cp /backup/*.dbf $ORACLE_HOME/oradata/trgt/
RECOVER DATABASE UNTIL CANCEL CANCEL
RESETLOGS
mode:
ALTER DATABASE OPEN RESETLOGS;
In this scenario, you restore the database files to an alternative location because the original location is damaged by a media failure.
To restore the most recent whole database backup to a new location:
SHUTDOWN IMMEDIATE
% cp /backup/*.dbf /new_disk/oradata/trgt/
CONTROL_FILES = "/new_disk/oradata/trgt/control01.dbf"
STARTUP MOUNT
1
you might enter:
ALTER DATABASE RENAME FILE '?/oradata/trgt/system01.dbf' TO '/new_disk/oradata/system01.dbf';
ALTER DATABASE RENAME FILE '?/oradata/trgt/redo01.log' TO '/new_disk/oradata/redo_01.log'; ALTER DATABASE RENAME FILE '?/oradata/trgt/redo02.log' TO '/new_disk/oradata/redo_02.log';
RECOVER DATABASE UNTIL CANCEL; CANCEL;
RESETLOGS
mode. This command clears the online redo logs and resets the log sequence to 1:
ALTER DATABASE OPEN RESETLOGS;
Note that restoring a NOARCHIVELOG
database backup and then resetting the log discards all changes to the database made from the time the backup was taken to the time of the failure.
See Also:
Oracle Database Administrator's Guide for more information about renaming and relocating datafiles, and Oracle Database SQL Reference to learn about |
Use parallel media recovery to tune the roll forward phase of media recovery. In parallel media recovery, the database uses a "division of labor" approach to allocate different processes to different data blocks while rolling forward, thereby making the procedure more efficient. For example, if parallel recovery is performed with PARALLEL
4
, and only one datafile is recovered, then four spawned processes read blocks from the datafile and apply records instead of only one process.
Typically, recovery is I/O-bound on reads to data blocks. Parallelism at the block level may only help recovery performance if it increases total I/Os, for example, by bypassing operating system restrictions on asynchronous I/Os. Systems with efficient asynchronous I/O see little benefit from parallel media recovery.
The SQL*Plus RECOVER
PARALLEL
command specifies parallel media recovery (the default is NOPARALLEL
). This command selects a degree of parallelism equal to the number of CPUs available on all participating instances times the value of the PARALLEL_THREADS_PER_CPU
initialization parameter.
The format for the RECOVER
PARALLEL
command is the following:
RECOVER PARALLEL integer;
The integer
variable sets the number of recovery processes used for media recovery. If you use a Real Application Clusters configuration, then the database decides how to distribute these recovery processes among the instances. If integer
is not specified, then the database picks a default number of recovery processes.
Note:
The |
See Also:
|