Oracle9i User-Managed Backup and Recovery Guide Release 2 (9.2) Part Number A96572-01 |
|
This chapter describes how to recover a database, and includes the following topics:
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. |
One of the most important aspects of user-managed backup and recovery is keeping records of all current database files as well as the backups of these files. For example, you should have records for the location of the following files:
The following useful SQL script displays the location of all control files, datafiles, and online redo log files for the database:
SELECT NAME FROM V$DATAFILE UNION ALL SELECT MEMBER FROM V$LOGFILE UNION ALL SELECT NAME FROM V$CONTROLFILE;
Sample output follows:
NAME -------------------------------------------------------------------------------- /oracle/dbs/tbs_01.f /oracle/dbs/tbs_02.f /oracle/dbs/tbs_11.f /oracle/dbs/tbs_12.f /oracle/dbs/t1_log1.f /oracle/dbs/t1_log2.f /oracle/dbs/cf1.f /oracle/dbs/cf2.f
See Also:
Oracle9i Database Reference for more information on the |
You can determine the location of the default archived log destinations by executing the following SQL script:
SELECT NAME, VALUE FROM V$PARAMETER WHERE NAME LIKE log_archive_dest% AND VALUE IS NOT NULL / NAME VALUE ---------------------------------- ------------------------------------------- log_archive_dest_1 LOCATION=/oracle/work/arc_dest/arc log_archive_dest_state_1 enable
Determine the format for archived logs by running SHOW
as follows:
SHOW PARAMETER LOG_ARCHIVE_FORMAT NAME TYPE VALUE ------------------------------------ ------- ------------------------------ log_archive_format string r_%t_%s.arc
To see a list of all the archived logs recorded in the control file, issue this query:
SELECT NAME FROM V$ARCHIVED_LOG; NAME -------------------------------------------------------------------------------- /oracle/work/arc_dest/arcr_1_110.a /oracle/work/arc_dest/arcr_1_111.a /oracle/work/arc_dest/arcr_1_112.a /oracle/work/arc_dest/arcr_1_113.a
It is not enough to merely record the location of backup files: you must correlate the backups with the original files. If possible, name the backups with the same relative filename as the primary file. Whatever naming system you use, keep a table containing the relevant information. For example, you could keep the following table as a record of database file locations in case of a restore emergency.
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 NAME TABLESPACE_NAME ---------------------------------- ---------------- /oracle/dbs/tbs_14.f TBS_1 /oracle/dbs/tbs_15.f TBS_2 /oracle/dbs/tbs_21.f TBS_3
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# /
Sample output follows:
DF# DF_NAME TBSP_NAME STATUS ERROR CHANGE# TIME ---- -------------------- ---------- ------- ---------- ----------- ---------- 14 /oracle/dbs/tbs_14.f TBS_1 OFFLINE OFFLINE 0 NORMAL 15 /oracle/dbs/tbs_15.f TBS_2 OFFLINE OFFLINE 0 NORMAL 21 /oracle/dbs/tbs_21.f TBS_3 OFFLINE OFFLINE 0 NORMAL
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 an Oracle 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, you must 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;
tbs_24.f
on UNIX you might issue:
% cp /disk2/backup/tbs_24.bak /disk1/oracle/dbs/tbs_24.f
RECOVER TABLESPACE users
ALTER TABLESPACE users ONLINE;
If a datafile is damaged and no backup of the file is available, then you can still recover the datafile if:
To re-create a datafile for recovery:
/disk1/users1.f
has been damaged, and no backup is available. The following statement re-creates the original datafile (same size) on disk2
:
ALTER DATABASE CREATE DATAFILE '/disk1/users1.f' AS '/disk2/users1.f';
This statement creates an empty file that is the same size as the lost file. Oracle looks at information in the control file and the data dictionary to obtain size information. The old datafile is renamed as the new datafile.
RECOVER DATAFILE '/disk2/users1.f'
If a media failure has affected the control files of a database (whether control files are multiplexed or not), then the database continues to run until the first time that an Oracle background process needs to access the control files. At this point, the database and instance are automatically shut down.
If the media failure is temporary and the database has not yet shut down, avoid the automatic shutdown of the database by immediately correcting the media failure. If the database shuts down before you correct the temporary media failure, however, then you can restart the database after fixing the problem and restoring access to the control files.
The appropriate recovery procedure for media failures that permanently prevent access to control files of a database depends on whether you have multiplexed the control files. The following sections describe the appropriate procedures:
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.
Assuming that 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
good_cf.f
to new_cf.f
you might issue:
% cp /oracle/dbs/good_cf.f /oracle/dbs/new_cf.f
CONTROL_FILES
parameter reflects the current locations of all control files and excludes all control files that were not restored. For example, assume the initialization parameter file contains:
CONTROL_FILES = '/oracle/dbs/good_cf.f', '/oracle/dbs/bad_cf.f'
Then, you can edit it as follows:
CONTROL_FILES = '/oracle/dbs/good_cf.f', '/oracle/dbs/new_cf.f'
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, then you can start the instance, but not mount the database. If you attempt to mount the database when the control file is unavailable, you see this error message:
ORA-00205: error in identifying controlfile, check alert log for more info
You cannot mount and open the database until you make the control file accessible again. If you restore a backup control file, then you must open the database with the RESETLOGS
option.
As indicated in Table 3-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
initialization parameter. For example, if /dsk1/oracle/dbs/cf1.f
and /dsk2/cf2.f
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/cf.bak /dsk1/oracle/dbs/cf1.f % cp /backup/cf.bak /dsk2/cf2.f
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 06/08/2000 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/dbs/t1_log1.f Log applied. Media recovery complete.
If for some reason the online logs are not accessible, then you can cancel recovery without applying the online logs. Note that if all datafiles are current, and redo is located in the online logs that 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 Oracle 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:
CONTROL_FILES = '/dsk1/oracle/dbs/cf1.f', '/dsk2/cf2.f'
You can change the initialization parameter to read:
CONTROL_FILES = '/dsk3/tmp/cf1.f', 'dsk3/tmp/cf2.f'
If all control files have been lost or damaged by a permanent media failure, but all online redo logfiles remain intact, then you can recover the database after creating a new control file. Note that this procedure does not require you 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 3-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. Copy the backup control file and execute |
Do not have a control file backup in either |
Create the |
To create a new control file:
NOMOUNT
mode. For example, enter:
STARTUP NOMOUNT
CREATE
CONTROLFILE
statement, specifying the NORESETLOGS
option (refer to Table 3-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, Oracle mounts the database.
USING
BACKUP
CONTROLFILE
clause):
RECOVER DATABASE
ALTER DATABASE OPEN;
Note that a RESETLOGS
is not necessary.
?/dbs/cf.bak
:
ALTER DATABASE BACKUP CONTROLFILE TO '?/dbs/cf.bak' REUSE;
All archived redo log files generated between the time a restored backup was created and the target recovery time are required for the pending media recovery. The archived logs will eventually need to be on disk so that they are available to Oracle during the recovery.
To restore necessary archived redo logs:
V$ARCHIVED_LOG
and V$RECOVERY_LOG
. If a datafile requires recovery, but not 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
. Oracle locates the correct log automatically when required during media recovery. For example, enter:
% cp /disk2/arc_backup/*.arc /disk1/oracle/dbs/arc_dest
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 /disk2/temp # set location using SET statement DATABASE RECOVER FROM '/disk2/temp'; # set location in RECOVER statement itself
% rm *.arc
See Also:
Oracle9i Database Reference for more information about the data dictionary views, and "Performing User-Managed Media Recovery: Overview" for an overview of log application during media recovery |
|
Copyright © 2002 Oracle Corporation. All Rights Reserved. |
|