About User-Managed Restore Operations
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: · Datafiles and control files
· Server parameter file
In each case, the loss of a primary file and the restore of a backup has the following implications for media recovery.
If you lose . . . | Then . . . |
One or more datafiles | You must restore them from a backup and perform media recovery. Recovery is required whenever the checkpoint SCN in the datafile header does not match the checkpoint SCN for the datafile that is recorded in the control file. |
All copies of the current control file | You must restore a backup control file and then open the database with the RESETLOGS option. If you do not have a backup, then you can attempt to re-create the control file. If possible, use the script included in the ALTER DATABASE BACKUP CONTROLFILE TO TRACE output. Additional work may be required to match the control file structure with the current database structure. |
One copy of a multiplexed control file | Copy one of the intact multiplexed control files into the location of the damaged or missing control file and open the database. If you cannot copy the control file to its original location, then edit the initialization parameter file to reflect a new location or remove the damaged control file. Then, open the database. |
One or more archived logs required for media recovery | You must restore backups of these archived logs for recovery to proceed. You can restore either to the default or nondefault location. If you do not have backups, then you must performing incomplete recovery up to an SCN before the first missing redo log and open RESETLOGS. |
The server parameter file | If you have a backup of the server parameter file, then restore it. Alternatively, if you have a backup of the client-side initialization parameter file, then you can restore a backup of this file, start the instance, and then re-create the server parameter file. |
Note:
Restore and recovery of Oracle-managed files is no different from restore and recovery of user-named files.
Determining Which Datafiles Require Recovery
Use the following SQL*Plus commands to format the output of the query:
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.
Restoring Datafiles and Archived Redo Logs
SQL>ALTER TABLESPACE users OFFLINE IMMEDIATE;
Copy backups of the damaged datafiles to their default location using operating system commands.
% cp /disk2/backup/users01.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
Recover the affected tablespace.
SQL>RECOVER TABLESPACE users
Bring the recovered tablespace online.
SQL>ALTER TABLESPACE users ONLINE;
Restoring Archived Redo Logs with Operating System Utilities
The database locates the correct log automatically when required during media recovery.
% cp /disk2/arch/* $ORACLE_HOME/oradata/trgt/arch
If sufficient space is not available at the location indicated by the archiving destination initialization parameter, restore some or all of the required archived redo log files to an alternate location. Specify the location before or during media recovery using the 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
After an archived log is 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. For example:
% rm /tmp/*.dbf
Restoring Control Files
Restore Lost Copy of a Multiplexed Control File
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.
Copying a Multiplexed Control File to a Default Location
shut down
SQL>SHUTDOWN
Use an intact multiplexed copy of the database's current control file to copy over the damaged control files. For example, to replace bad_cf.f with good_cf.f, you might enter:
% cp /oracle/good_cf.f /oracle/dbs/bad_cf.f
Start a new instance and mount and open the database.
SQL>STARTUP
Copying a Multiplexed Control File to a Nondefault Location
shut down
SQL>SHUTDOWN
% cp $ORACLE_HOME/oradata/trgt/control01.dbf /new_disk/control01.dbf
Edit the parameter file of the database so that the CONTROL_FILES parameter
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'
Start a new instance and mount and open the database.
SQL>STARTUP
Restore Control File from Backup After Loss of All Current Control Files
Status of Online Logs | Status of Datafiles | Restore Procedure |
Available | Current | If the online logs contain redo necessary for recovery, then restore a backup control file and apply the logs during recovery. You must specify the filename of the online logs containing the changes in order to open the database. After recovery, open RESETLOGS. |
Unavailable | Current | If the online logs contain redo necessary for recovery, then re-create the control file. Because the online redo logs are inaccessible, open RESETLOGS (when the online logs are accessible it is not necessary to OPEN RESETLOGS after recovery with a created control file). |
Available | Backup | Restore a backup control file, perform complete recovery, and then open RESETLOGS. |
Unavailable | Backup | Restore a backup control file, perform incomplete recovery, and then open RESETLOGS. |
Restoring a Backup Control File to the Default Location
shut down
SQL>SHUTDOWN
% cp /backup/control01.dbf ORACLE_HOME/oradata/trgt/control01.dbf
% cp /backup/control02.dbf ORACLE_HOME/oradata/trgt/control02.dbf
Start a new instance and mount the database.
SQL>STARTUP MOUNT
SQL>RECOVER DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL
Apply the prompted archived logs. If you then receive another message saying that the required archived log is missing, it probably means that a necessary redo record is located in the online redo logs. This situation can occur when unarchived changes were located in the online logs when the instance crashed.
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 logsOpen the database with the RESETLOGS option after finishing recovery:
SQL>ALTER DATABASE OPEN RESETLOGS;
Restoring a Backup Control File to a Nondefault Location
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'
Create New Control File After Losing All Current and Backup Control Files
If you . . . | Then . . . |
Executed ALTER DATABASE BACKUP CONTROLFILE TO TRACE NORESETLOGS after you made the last structural change to the database, and if you have saved the SQL command trace output | Use the CREATE CONTROLFILE statement from the trace output as-is. |
Performed your most recent execution of ALTER DATABASE BACKUP CONTROLFILE TO TRACE before you made a structural change to the database | Edit the output of ALTER DATABASE BACKUP CONTROLFILE TO TRACE to reflect the change. For example, if you recently added a datafile to the database, then add this datafile to the DATAFILE clause of the CREATE CONTROLFILE statement. |
Backed up the control file with the ALTER DATABASE BACKUP CONTROLFILE TO filename statement (not the TO TRACE option) | Use the control file copy to obtain SQL output. Create a temporary database instance, mount the backup control file, and then run ALTER DATABASE BACKUP CONTROLFILE TO TRACE NORESETLOGS. If the control file copy predated a recent structural change, then edit the trace to reflect the change. |
Do not have a control file backup in either TO TRACE format or TO filename format | |
Note:
If your character set is not the default US7ASCII, then you must specify the character set as an argument to the CREATE CONTROLFILE statement. The database character set is written to the alert log at startup. The character set information is also recorded in the BACKUP CONTROLFILE TO TRACE output.
To create a new control file:
Start the database in NOMOUNT mode. For example, enter:
SQL>STARTUP NOMOUNT
Create the control file with the CREATE CONTROLFILE statement, specifying the NORESETLOGS option. 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.
Recover the database as normal (without specifying the USING BACKUP CONTROLFILE clause):
SQL>RECOVER DATABASE
Open the database after recovery completes (RESETLOGS option not required):
SQL>ALTER DATABASE OPEN;
Immediately back up the control file. The following SQL statement backs up a database's control file to /backup/control01.dbf:
SQL>ALTER DATABASE BACKUP CONTROLFILE TO '/backup/control01.dbf' REUSE;
Automating Recovery with SET AUTORECOVERY
Run the SET AUTORECOVERY ON command to enable on automatic recovery.
To automate the recovery using SET AUTORECOVERY:
Restore a backup of the offline datafiles. This example restores an inconsistent backup of all datafiles with an operating system utility:
% cp /backup/datafiles/*.dbf $ORACLE_HOME/oradata/trgt/
Ensure the database is mounted. For example, if the database is shut down, run:
SQL>STARTUP MOUNT
Enable automatic recovery.
SET AUTORECOVERY ON
Recover the desired datafiles.
SQL>RECOVER DATABASE
Open the database.
SQL>ALTER DATABASE OPEN;
Recovering When Archived Logs Are in the Default Location
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
SQL>SELECT NAME FROM V$ARCHIVED_LOG;
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.
Resetting the Archived Log Destination
You 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:
Use an operating system utility to restore the archived logs to a nondefault location. For example, enter:
% cp /backup/arch/* /tmp/
Change the value for the archive log parameter to the nondefault location. You can issue 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
Using SQL*Plus, start a new instance by specifying the edited initialization parameter file, and then mount the database. For example, enter:
SQL>STARTUP MOUNT
Begin media recovery as usual. For example, enter:
SQL>RECOVER DATABASE
Responding to Unsuccessful Application of Redo Logs
Error | Possible Cause | Solution |
ORA-27037: unable to obtain file status | Entered wrong filename. Log is missing. | Reenter correct filename. Restore backup archived redo log. |
ORA-27047: unable to read the header block of file | The log may have been partially written or become corrupted. | If you can locate an uncorrupted or complete log copy, then apply the intact copy and continue recovery. If no copy of the log exists and you know the time of the last valid redo entry, then you use incomplete recovery. Restore backups and restart recovery. |
Restoring Backups of the Damaged or Missing Files
In this stage, you restore all necessary backups.
To restore the necessary files:
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 ALTER DATABASE RENAME FILE. |
Losing Datafiles in ARCHIVELOG Mode
If either a permanent or temporary media failure affects the datafiles of a database operating in ARCHIVELOG mode, then the following scenarios can occur.
Damaged Datafiles | Database Status | Solution |
Datafiles in the SYSTEM tablespace or datafiles with active undo segments. | Database shuts down. | If the hardware problem is temporary, then fix it and restart the database. Usually, crash recovery recovers lost transactions. |
Datafiles not in the SYSTEM tablespace or datafiles that do not contain active rollback or undo segments. | Affected datafiles are taken offline, but the database stays open. | If the unaffected portions of the database must remain available, then do not shut down the database. Take tablespaces containing problem datafiles offline using the temporary option, then recover them. |
Recovering Through an Added Datafile with a Backup Control File:
If database recovery with a backup control file rolls forward through a CREATE TABLESPACE or an ALTER TABLESPACE ADD DATAFILE operation, then the database stops recovery when applying the redo record for the added files and lets you confirm the filenames.
For example, suppose the following sequence of events occurs:
You back up the database.You create a new tablespace containing two datafiles: /oracle/oradata/trgt/test01.dbf and /oracle/oradata/trgt/test02.dbf.
You later restore a backup control file and perform media recovery through the CREATE TABLESPACE operation.
You may see the following error when applying the CREATE TABLESPACE redo data:
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to control file by media recovery
ORA-01110: data file 11: '/oracle/oradata/trgt/test02.dbf'
ORA-01110: data file 10: '/oracle/oradata/trgt/test01.dbf'
To recover through an ADD DATAFILE operation, use the following procedure:
View the files added by selecting from V$DATAFILE. For example:
SQL>SELECT FILE#,NAME
FROM V$DATAFILE;
If multiple unnamed files exist, then determine which unnamed file corresponds to which datafile by using one of these methods:
Open the alert_SID.log, which contains messages about the original file location for each unnamed file.
Derive the original file location of each unnamed file from the error message and V$DATAFILE: each unnamed file corresponds to the file in the error message with the same file number.
Issue the ALTER DATABASE RENAME FILE statement to rename the datafiles. For example, enter:
SQL>ALTER DATABASE RENAME FILE '/db/UNNAMED00001' TO
'/oracle/oradata/trgt/test01.dbf';
SQL>ALTER DATABASE RENAME FILE '/db/UNNAMED00002' TO
'/oracle/oradata/trgt/test02.dbf';
Continue recovery by issuing the previous recovery statement. For example:
RECOVER AUTOMATIC DATABASE USING BACKUP CONTROLFILE UNTIL CANCEL
Re-Creating Datafiles When Backups Are Unavailable
If a datafile is damaged and no backup of the file is available, then you can still recover the datafile if:
· All archived log files written after the creation of the original datafile are available
· The control file contains the name of the damaged file (that is, the control file is current, or is a backup taken after the damaged datafile was added to the database)
Note:
You cannot re-create any of the datafiles for the SYSTEM tablespace by using the CREATE DATAFILE clause of the ALTER DATABASE statement because the necessary redo is not available.
To re-create a datafile for recovery:
Create a new, empty datafile to replace a damaged datafile that has no corresponding backup. For example, assume that the datafile ?/oradata/trgt/users01.dbf has been damaged, and no backup is available. The following statement re-creates the original datafile (same size) on disk2:
SQL>ALTER DATABASE CREATE DATAFILE '?/oradata/trgt/users01.dbf' AS ‘/disk2/users01.dbf';
This statement creates an empty file that is the same size as the lost file. The database looks at information in the control file and the data dictionary to obtain size information. The old datafile is renamed as the new datafile.
Perform media recovery on the empty datafile. For example, enter:
SQL>RECOVER DATAFILE '/disk2/users01.dbf'
All archived logs written after the original datafile was created must be applied to the new, empty version of the lost datafile during recovery.
Recovering Through RESETLOGS with Created Control File: Scenario
You can recover backups through an OPEN RESETLOGS so long as:
· You have a current, backup, or created control file that knows about the prior incarnations
· You have all available archived redo logs
If you need to re-create the control file, the trace file generated by ALTER DATABASE BACKUP CONTROLFILE TO TRACE will contain the necessary commands to re-construct the complete incarnation history. The V$DATABASE_INCARNATION view displays the RESETLOGS history known to the control file, while the V$LOG_HISTORY view displays the archived log history.
It is possible for the incarnation history to be incomplete in the in re-created control file. For example, archived logs necessary for recovery may be missing. In this case, it is possible to create incarnation records explicitly with the ALTER DATABASE REGISTER LOGFILE statement.
In the following example, you register four logs that are necessary for recovery but are not recorded in the re-created control file, and then recover the database:
ALTER DATABASE REGISTER LOGFILE '?/oradata/trgt/arch/arcr_1_1_42343523.arc';
ALTER DATABASE REGISTER LOGFILE '?/oradata/trgt/arch/arcr_1_1_34546466.arc';
ALTER DATABASE REGISTER LOGFILE '?/oradata/trgt/arch/arcr_1_1_23435466.arc';
ALTER DATABASE REGISTER LOGFILE '?/oradata/trgt/arch/arcr_1_1_12343533.arc';
RECOVER AUTOMATIC DATABASE;
Media Recovery of Transportable Tablespaces
To recover a transportable tablespace, use the following procedure:
If the database is open, then take the transported tablespace offline. For example, if you want to recover the users tablespace, then issue:
SQL>ALTER TABLESPACE users OFFLINE IMMEDIATE;
Restore a backup of the transported datafiles with an operating system utility. The backup can be the initial version of the transported datafiles or any backup taken after the tablespace is transported. For example, enter:
% cp /backup/users.dbf $ORACLE_HOME/oradata/trgt/users01.dbf
Recover the tablespace as normal. For example, enter:
SQL>RECOVER TABLESPACE users
Recovering After the Loss of Online Redo Log Files
If a media failure has affected the online redo logs of a database, then the appropriate
Status | Description |
UNUSED | The online redo log has never been written to. |
CURRENT | The online redo log is active, that is, needed for instance recovery, and it is the log to which the database is currently writing. The redo log can be open or closed. |
ACTIVE | The online redo log is active, that is, needed for instance recovery, but is not the log to which the database is currently writing.It may be in use for block recovery, and may or may not be archived. |
CLEARING | The log is being re-created as an empty log after an ALTER DATABASE CLEAR LOGFILE statement. After the log is cleared, then the status changes to UNUSED. |
CLEARING_CURRENT | The current log is being cleared of a closed thread. The log can stay in this status if there is some failure in the switch such as an I/O error writing the new log header. |
INACTIVE | The log is no longer needed for instance recovery. It may be in use for media recovery, and may or may not be archived. |
Recovering After Losing a Member of a Multiplexed Online Redo Log Group
If the online redo log of a database is multiplexed, and if at least one member of each online redo log group is not affected by the media failure, then the database continues functioning as normal, but error messages are written to the log writer trace file and the alert_SID.log of the database.
Solve the problem by taking one of the following actions:
· If the hardware problem is temporary, then correct it. The log writer process accesses the previously unavailable online redo log files as if the problem never existed.
· If the hardware problem is permanent, then drop the damaged member and add a new member by using the following procedure.
Note:
The newly added member provides no redundancy until the log group is reused.
Locate the filename of the damaged member in V$LOGFILE. The status is INVALID if the file is inaccessible:
SQL>SELECT GROUP#, STATUS, MEMBER
FROM V$LOGFILE
WHERE STATUS='INVALID';
Drop the damaged member. For example, to drop member redo01.log from group 2, issue:
SQL>ALTER DATABASE DROP LOGFILE MEMBER '/oracle/oradata/trgt/redo02.log';
Add a new member to the group. For example, to add redo02.log to group 2, issue:
SQL>ALTER DATABASE ADD LOGFILE MEMBER '/oracle/oradata/trgt/redo02b.log'
TO GROUP 2;
If the file you want to add already exists, then it must be the same size as the other group members, and you must specify REUSE. For example:
SQL>ALTER DATABASE ADD LOGFILE MEMBER '/oracle/oradata/trgt/redo02b.log'
REUSE TO GROUP 2;
Recovering After the Loss of All Members of an Online Redo Log Group
If a media failure damages all members of an online redo log group, then different scenarios can occur depending on the type of online redo log group affected by the failure and the archiving mode of the database.
If the damaged log group is active, then it is needed for crash recovery; otherwise, it is not.
If the group is . . . | Then . . . | And you should . . . |
Inactive | It is not needed for crash recovery | Clear the archived or unarchived group. |
Active | It is needed for crash recovery | Attempt to issue a checkpoint and clear the log; if impossible, then you must restore a backup and perform incomplete recovery up to the most recent available redo log. |
Current | It is the log that the database is currently writing to | Attempt to clear the log; if impossible, then you must restore a backup and perform incomplete recovery up to the most recent available redo log. |
Your first task is to determine whether the damaged group is active or inactive.
Locate the filename of the lost redo log in V$LOGFILE and then look for the group number corresponding to it. For example, enter:
SQL>SELECT GROUP#, STATUS, MEMBER FROM V$LOGFILE;
Determine which groups are active. For example, enter:
SQL>SELECT GROUP#, MEMBERS, STATUS, ARCHIVED
FROM V$LOG;
Losing an Inactive Online Redo Log Group
If all members of an online redo log group with INACTIVE status are damaged, then the procedure depends on whether you can fix the media problem that damaged the inactive redo log group.
If the failure is . . . | Then . . . |
Temporary | Fix the problem. LGWR can reuse the redo log group when required. |
Permanent | The damaged inactive online redo log group eventually halts normal database operation. Reinitialize the damaged group manually by issuing the ALTER DATABASE CLEAR LOGFILE statement as described in this section. |
Clearing Inactive, Archived Redo
You can clear an inactive redo log group when the database is open or closed. The procedure depends on whether the damaged group has been archived.
To clear an inactive, online redo log group that has been archived, use the following procedure:
If the database is shut down, then start a new instance and mount the database:
SQL>STARTUP MOUNT
Reinitialize the damaged log group. For example, to clear redo log group 2, issue the following statement:
SQL>ALTER DATABASE CLEAR LOGFILE GROUP 2;