Oracle® Database Backup and Recovery User's Guide 11g Release 2 (11.2) Part Number E10642-01 |
|
|
View PDF |
This chapter explains how to perform RMAN tablespace point-in-time recovery. This chapter contains the following sections:
Running RMAN TSPITR:
In order to use RMAN tablespace point-in-time recovery (TSPITR) effectively, it is helpful to understand what types of problems it can resolve, its components, what RMAN does during TSPITR and the various limitations and restrictions on when and how it can be run. This section explains the basic concepts, preparatory tasks and modes of running RMAN TSPITR.
Recovery Manager (RMAN) Automatic TSPITR enables quick recovery of one or more tablespaces in a database to an earlier time without affecting the rest of the tablespaces and objects in the database.
RMAN TSPITR is most useful for the following situations:
You want to recover a logical database to a point different from the rest of the physical database, when multiple logical databases exist in separate tablespaces of one physical database. For example, you maintain logical databases in the orders
and personnel
tablespaces. An incorrect batch job or DML statement corrupts the data in only one of the tablespaces.
You want to recover data lost after DDL operations that change the structure of tables. You cannot use Flashback Table to rewind a table to before the point of a structural change such as a truncate table operation.
You want to recover a table after it has been dropped with the PURGE
option.
You want to recover from the logical corruption of a table.
You want to recover dropped tablespaces. In fact, RMAN can perform TSPITR on dropped tablespaces even when a recovery catalog is not used.
You can also use Flashback Database to rewind data, but you must rewind the entire database rather than just a subset. Also, unlike TSPITR, the Flashback Database feature necessitates the overhead of maintaining flashback logs. The point in time to which you can flash back the database is more limited than the TSPITR window, which extends back to your earliest recoverable backup.
Table 20-1 defines some of the common entities that are used by RMAN TSPITR.
Table 20-1 RMAN TSPITR Entities
Name | What is it? |
---|---|
Target Instance |
Contains the tablespace to be recovered to the target time |
Target Time |
Point-in-time or SCN of the tablespace after TSPITR completes |
Auxiliary Instance |
A database instance used in the recovery process to perform the work of recovery. The auxiliary instance has other files associated with it. See auxiliary set for a complete list |
Auxiliary Destination |
An optional disk location where RMAN uses to temporarily store the auxiliary set files. The auxiliary destination is used only when using a RMAN-managed auxiliary instance. Specifying an auxiliary destination with a user-managed auxiliary instance results in an error. All references to auxiliary destination in this chapter assume use of a RMAN-managed auxiliary instance. |
Recovery Set |
Datafiles in the tablespaces that you intend to recover |
Auxiliary Set |
Datafiles required for TSPITR that are not part of the recovery set. The auxiliary set typically includes:
The auxiliary set does not include the parameter file, password file or associated network files |
You start RMAN TSPITR with the RMAN RECOVER TABLESPACE
command. You have several options for running RMAN TSPITR. The difference between the various modes of operation correspond to how much automation versus customization you require in your environment. There are three ways to run the utility:
Fully Automated (the default)
In this mode, RMAN manages the entire TSPITR process including the auxiliary instance. You specify the tablespaces of the recovery set, an auxiliary destination, the target time and allow RMAN to manage all other aspects of TSPITR.
The default mode is recommended unless you specifically need more control over the location of recovery set files after TSPITR, auxiliary set files during TSPITR, channel settings and parameters or some other aspect of your auxiliary instance. For more information, see "Performing Fully Automated RMAN TSPITR"
Automated - RMAN-Managed Auxiliary Instance with User Settings
You can override some of the defaults of RMAN TSPITR while still using a RMAN-managed auxiliary instance and destination. This variation of the default mode enables you to benefit from some of the built-in management that RMAN TSITR provides while being able to specify:
Location of auxiliary set or recovery set files
Initialization parameters
For more information, see "Overriding Defaults for RMAN TSPITR with a RMAN-Managed Auxiliary Instance"
Non-Automated - TSPITR and User-managed auxiliary instance
This mode of RMAN TSPITR requires you to set up and manage all aspects of the auxiliary instance as well as some aspects of the TSPITR process. This mode may be appropriate if, for example, you need to allocate a different number of channels or change the channel parameters for your user-managed auxiliary instance.
For more information, see "Performing RMAN TSPITR Using Your Own Auxiliary Instance".
Having selected tablespaces from the recovery set, an auxiliary destination and a target time, you are now ready to perform Fully Automated RMAN TSPITR (default). The automated RMAN TSPITR (Mode 2) shares many of these high-level processing steps.
RMAN TSPITR automatically performs the following actions:
Provided the tablespaces in the recovery set have not been dropped, checks to see if the tablespaces in the recovery set are self-contained by executing the DBMS_TTS.TRANSPORT_SET_CHECK
for the recovery set tablespaces and then checking that the view TRANSPORT_SET_VIOLATIONS
is empty. If the query returns rows, RMAN stops TSPITR processing and any tablespace containment violations must be resolved before TSPITR can proceed. Example 20-1 shows you how to set up and run the query before invoking RMAN TSPITR.
Checks to see if a connection to a user-managed auxiliary instance was provided. If it is, then RMAN TSPITR uses it. If not, creates the auxiliary instance, starts it, and connects to it.
Takes the tablespaces to be recovered offline in the target database, provided the tablespaces in the recovery set have not been dropped
Restores a backup control file from a point in time before the target time to the auxiliary instance.
Restores the datafiles from the recovery set and the auxiliary set to the auxiliary instance.
Files are restored either in the:
Locations you specify for each file
Original location of the file (for recovery set datafiles)
Auxiliary Destination (if you used the AUXILIARY DESTINATION
argument of RECOVER TABLESPACE
and a RMAN-managed auxiliary instance)
Recovers the restored datafiles in the auxiliary instance to the specified time.
Opens the auxiliary database with the RESETLOGS
option.
Makes the recovery set tablespaces read-only in the auxiliary instance.
Exports the recovery set tablespaces from the auxiliary instance using the Data Pump utility to produce a transportable tablespace dump file.
Shuts down the auxiliary instance.
Drops the recovery set tablespaces from the target.
Data Pump utility reads the transportable tablespace dump file and plugs the recovery set tablespaces into the target.
Makes the tablespaces that were put in the target database read/write and immediately takes them offline.
Deletes all auxiliary set files.
At this point, RMAN TSPITR has finished. The recovery set datafiles are returned to their contents at the specified point-in-time, and belong to the target database.
The recovery set tablespaces are left offline for you to backup and then bring back online. These last steps follow Oracle's recommendation and best practice of backing up recovered tablespaces as soon as TSPITR completes.
A number of database problems cannot be resolved with TSPITR. The following list explains when you cannot perform TSPITR:
If there are no archived redo logs or if the database runs in NOARCHIVELOG
mode.
If TSPITR is used to recover a renamed tablespace to a point-in-time before it was renamed, you must use the previous name of the tablespace in order to perform the recovery operation.
In this case and once TSPITR completes, the target database will end up with two copies of the same tablespace, the original tablespace with the new name and the TSPITR tablespace with the old name. If this is not desired, then you can drop the new tablespace with the new name.
If constraints for the tables in tablespace tbs1
are contained in tablespace tbs2
, then you cannot recover tbs1
without also recovering tbs2
.
You cannot use TSPITR to recover the current default tablespace.
You cannot use TSPITR to recover tablespaces containing any of the following objects:
Objects with underlying objects (such as materialized views) or contained objects (such as partitioned tables) unless all of the underlying or contained objects are in the recovery set
Undo or rollback segments
Oracle8-compatible advanced queues with multiple recipient
Objects owned by the user SYS
. Examples of these types of object are: PL/SQL, Java classes, callout programs, views, synonyms, users, privileges, dimensions, directories, and sequences.
After TSPITR completes, RMAN recovers the datafiles in the recovery set to the target time. Note the following special cases:
TSPITR will not recover query optimizer statistics for recovered objects.
You must gather new statistics after the TSPITR completes.
If you run TSPITR on a tablespace and bring the tablespace online at time t, then backups of the tablespace created before time t are no longer usable for recovery with a current control file.
You cannot use the current control file to recover the database to any time less than or equal to t.
If one or more datafiles in the recovery set have OMF names and the compatibility in the target database is set to version 10.1 or earlier, RMAN cannot reuse the datafile. This restriction is true even if no NEWNAME is provided for the datafile. A new OMF name is created for the recovery set datafile. This action will temporarily double the space requirements for the datafile. This is because DB_CREATE_FILE_DEST
has two copies of the datafile (the original datafile and the one used by TSPITR) until the tablespace is dropped in the target and the original datafile is deleted.
You should be aware of following precautions:
Since RMAN has no historical record of the undo in the control file, RMAN assumes that the current set of tablespaces with rollback or undo segments were the same set present at the time when recovery is performed. If the tablespace set has changed since that time, that the current rollback or undo segments were the same segments present at the time to which recovery is performed. If the undo segments have changed since that time, then you can use UNDO TABLESPACE
to indicate the correct set of tablespaces with undo at the point in time where the tablespaces are being recovered.
TSPITR to a time that is too old may not succeed if Oracle has reused the control file records for needed backups. (In planning your database, set the CONTROL_FILE_RECORD_KEEP_TIME
initialization parameter to a value large enough to ensure that control file records needed for TSPITR are kept.)
If you need to rerun TSPITR and you are not using a recovery catalog, you must first drop the tablespace to be used by TSPITR from the target database before running TSPITR again.
This section assumes that you have read "TSPITR Restrictions, Special Cases and Limitations". You must carry out the following steps when preparing for TSPITR:
It is extremely important that you choose the right target time or SCN for your TSPITR. As noted in "TSPITR Restrictions, Special Cases and Limitations", after you bring a tablespace online after TSPITR, you cannot use any backup from a time earlier than the moment you brought the tablespace online.
If you have a recovery catalog, then you can perform repeated TSPITR operations to different target times because the catalog contains tablespace history information. If RMAN uses only a control file, however, repeated TSPITR is only possible after dropping the tablespace because the control file does not have the tablespace history. In this case, RMAN only knows about the current set of tablespaces. The tablespace on which TSPITR was performed has a creation time equal to the time it was brought online.
To investigate past states of your data to identify the target time for TSPITR, you can use Oracle Flashback Query, Oracle Transaction Query and Oracle Flashback Version Query to find the point in time when unwanted database changes occurred.
See Also:
Oracle Database Advanced Application Developer's Guide for more information on Flashback Query, Flashback Transaction Query, and Flashback Version Query.Initially, your recovery set includes the datafiles for the tablespaces you intend to recover. However, if objects in the tablespaces that you need have relationships (such as constraints) to objects in other tablespaces, then you will have to account for this relationship before you can perform TSPITR. You have the following choices when faced with such a relationship:
Add the tablespace including the related objects to your recovery set
Remove the relationship
Suspend the relationship for the duration of TSPITR
RMAN TSPITR requires that the tablespace be self-contained and that no SYS owned objects reside in the tablespace. You can use the DBMS_TTS.TRANSPORT_SET_CHECK
procedure to locate objects outside the tablespace and identify relationships between objects that span the recovery set boundaries. If the TRANSPORT_SET_VIOLATIONS
view returns rows, you must investigate and correct the problem according to the choices mentioned above.
Note:
If one or more of the tablespaces in the recovery set have been dropped, RMAN TSPITR cannot run the procedureDBMS_TTS.TRANSPORT_SET_CHECK
. In this case, DBMS_TTS.TRANSPORT_SET_CHECK
is run when the Data Pump export of the auxiliary instance occurs. Just like RMAN TSPITR, if the export operation encounters any tablespaces that are not self-contained it will fail.Record all actions performed during this step so that you can re-create any suspended or removed relationships after completing TSPITR. Proceed with TSPITR only when the TRANSPORT_SET_VIOLATIONS
view is empty for the tablespaces in the recovery set.
The query in Example 20-1 illustrates how to use the DBMS_TTS.TRANSPORT_SET_CHECK
procedure for an initial recovery set consisting of tablespaces tools
and users
. It queries the transportable tablespace violations table to manage any dependencies. No rows are returned from this query when all dependencies are managed.
Example 20-1 Querying DBMS_TTS.TRANSPORT_SET_CHECK for a Subset of Tablespaces
BEGIN EXECUTE DBMS_TTS.TRANSPORT_SET_CHECK('USERS,TOOLS', TRUE,TRUE); END; / SELECT * FROM TRANSPORT_SET_VIOLATIONS;
See Also:
Oracle Database PL/SQL Packages and Types Reference for more information about theDBMS_TTS.TRANSPORT_SET_CHECK
procedure and corresponding view.When you perform RMAN TSPITR on a tablespace, objects created after the target recovery time are lost. You can preserve such objects after they are identified by exporting them before TSPITR with the Data Pump Export utility and re-importing them afterward with Data Pump Import.
To determine which objects will be lost in TSPITR, query the TS_PITR_OBJECTS_TO_BE_DROPPED
view on the primary database. Table 20-2 describes the contents of the view.
Table 20-2 TS_PITR_OBJECTS_TO_BE_DROPPED View
Column Name | Meaning |
---|---|
|
Owner of the object to be dropped. |
|
The name of the object that will be lost as a result of undergoing TSPITR |
|
Creation timestamp for the object. |
|
Name of the tablespace containing the object. |
Filter the view for objects whose CREATION_TIME
is after the target time for TSPITR. For example, with a recovery set consisting of users
and tools
, and a recovery point-in-time of November 2, 2007, 7:03:11 AM, issue the statement shown in Example 20-2.
Example 20-2 Querying TS_PITR_OBJECTS_TO_BE_DROPPED
SELECT OWNER, NAME, TABLESPACE_NAME, TO_CHAR(CREATION_TIME, 'YYYY-MM-DD:HH24:MI:SS') FROM TS_PITR_OBJECTS_TO_BE_DROPPED WHERE TABLESPACE_NAME IN ('USERS','TOOLS') AND CREATION_TIME > TO_DATE('02-NOV-06:07:03:11','YY-MON-DD:HH24:MI:SS') ORDER BY TABLESPACE_NAME, CREATION_TIME;
The TO_CHAR
and TO_DATE
functions are used to avoid issues with different national date formats. Of course, you can use local date formats in your own work.
Alternatively, if you have the SCN of the tablespaces, you can use conversion functions to determine the timestamp associated with the SCN and the objects that will be dropped. Suppose the SCN to recover tablespaces users
and tools
is 1645870, use the statement outlined in Example 20-3 to determine the objects that will be dropped.
Example 20-3 Using SCN and TS_PITR_OBJECTS_TO_BE_DROPPED
SELECT OWNER, NAME, TABLESPACE_NAME, TO_CHAR(CREATION_TIME,'YYYY-MM-DD:HH24:MI:SS') FROM TS_PITR_OBJECTS_TO_BE_DROPPED WHERE TABLESPACE_NAME IN ('USERS','TOOLS') AND CREATION_TIME > TO_DATE(TO_CHAR(SCN_TO_TIMESTAMP(1645870), 'MM/DD/YYYY HH24:MI:SS'), 'MM/DD/YYYY HH24:MI:SS') ORDER BY TABLESPACE_NAME, CREATION_TIME;
See Also:
Oracle Database Reference for more information about theTS_PITR_OBJECTS_TO_BE_DROPPED
viewIn the default mode, RMAN bases as much of the configuration for TSPITR as possible on the target database. During TSPITR, the recovery set datafiles are written in their current locations on the target database (For OMF files, see "Limitations of TSPITR"). The same channel configurations for the target database are used on the auxiliary instance when restoring files from backup. Auxiliary set datafiles and other auxiliary instance files, however, are stored in the auxiliary destination.
Use the AUXILIARY DESTINATION
parameter to set a location for RMAN to use for the auxiliary set datafiles. The auxiliary destination must be a location on disk with enough space to hold auxiliary set datafiles. Even if you use other techniques to rename some or all of the auxiliary set datafiles, specifying an AUXILIARY DESTINATION
parameter provides a default location for auxiliary set datafiles for which names are not specified. TSPITR will not fail if you inadvertently do not provide names for all auxiliary set datafiles.
In order to perform fully automated RMAN TSPITR the user performing TSPITR should be able to connect as SYSDBA
using OS authentication.
To perform fully automated RMAN TSPITR:
Review the information in "TSPITR Restrictions, Special Cases and Limitations".
Perform the tasks in "Planning and Preparing for TSPITR".
Start an RMAN session on the target database and, if applicable, connect to a recovery catalog.
Note:
Do not connect to an auxiliary instance when starting the RMAN client for automated TSPITR. If RMAN is connected to an auxiliary instance when you runRECOVER TABLESPACE
, then RMAN assumes that you are trying to manage your own auxiliary instance, as described in "Performing RMAN TSPITR Using Your Own Auxiliary Instance", and will try to use the connected auxiliary for TSPITR.Configure any channels required for the TSPITR on the target instance.
The auxiliary instance uses the same channel configuration as the target instance when performing the TSPITR.
Run the RECOVER TABLESPACE
command, specifying both the UNTIL
clause and the AUXILIARY DESTINATION
parameter.
Example 20-4 returns the users
and tools
tablespaces to the end of log sequence number 1299, and stores the auxiliary set files in the /disk1/auxdest
directory.
Example 20-4 Performing TSPITR on Two Tablespaces
RECOVER TABLESPACE users, tools UNTIL LOGSEQ 1300 THREAD 1 AUXILIARY DESTINATION '/disk1/auxdest';
The next step depends on the results of the RECOVER
command:
If no error occurs during TSPITR, then proceed to step 6.
The tablespaces are taken offline by RMAN, restored from backup and recovered to the desired point in time on the auxiliary instance, and then re-imported to the target database. The tablespaces are left offline. All auxiliary set datafiles and other auxiliary instance files are cleaned up from the auxiliary destination.
If an error occurs during TSPITR, then proceed to "Troubleshooting RMAN TSPITR".
If TSPITR completes successfully, then back up the recovered tablespaces before bringing them online.
For example, enter the following command:
BACKUP TABLESPACE users, tools;
After you perform TSPITR on a tablespace, you can no longer use previous backups of that tablespace once TSPITR successfully completes. If you use the recovered tablespaces without taking a backup, then you are running your database without a usable backup of these tablespaces.
Bring the tablespaces back online.
For example, enter the following command:
RMAN> SQL "ALTER TABLESPACE users, tools ONLINE";
Your recovered tablespaces are now ready for use.
You can customize the following aspects of RMAN TSPITR while still mostly following the procedure described in "Performing Fully Automated RMAN TSPITR":
Rename or relocate your recovery set datafiles so that the datafiles making up the recovered tablespaces are not stored in the original locations after TSPITR. This may be necessary if the disk that originally contained the tablespace is not usable.
This task is described in "Renaming TSPITR Recovery Set Datafiles with SET NEWNAME".
Specify a location other than the auxiliary destination for some or all auxiliary set datafiles. You might choose this option if no single location on disk has enough space for all auxiliary set files.
This task is described in "Naming TSPITR Auxiliary Set Datafiles".
Rename files in an Oracle Managed Files format.
This task is described in "Considerations When Renaming OMF Auxiliary Set Files in TSPITR".
Set up image copy backups of your auxiliary set datafiles in advance to avoid having to restore datafiles during TSPITR.
This task is described in "Using Image Copies for Faster RMAN TSPITR Performance".
Customize initialization parameters for your RMAN-managed auxiliary instance.
This task is described in "Customizing Initialization Parameters for the Automatic Auxiliary Instance in TSPITR".
You may not want the recovery set datafiles restored and recovered in their original locations. The SET NEWNAME
command enables you to specify a new destination. When you specify a new destination for the recovery set, RMAN does not remove the original datafile(s) of the tablespace(s).
To specify new recovery set filenames, create a RUN
block and use SET NEWNAME
commands within it. Be sure to assign names that do not conflict with each other or with the names of your current datafiles. Example 20-5 illustrates the basic technique.
Example 20-5 Renaming Recovery Set Files
RUN { . . . SET NEWNAME FOR DATAFILE 'ORACLE_HOME/oradata/trgt/users01.dbf' TO '/newfs/users01.dbf'; ...other SET NEWNAME commands... RECOVER TABLESPACE users, tools UNTIL SEQUENCE 1300 THREAD 1; }
In this example, RMAN takes the following actions:
Restores each specified datafile to the new location during TSPITR
Uses the image copy if one exists at the specified location and its checkpoint is before the specified point-in-time. If this criteria is not met, then RMAN overwrites the image copy.
Plugs the newly recovered datafile into the target control file
RMAN does not detect conflicts between names set with SET NEWNAME
and current datafile names on the target database until the actual recovery. If RMAN detects a conflict, then TSPITR fails and RMAN reports an error. The valid datafile is not overwritten.
Unlike recovery set datafiles, which are usually stored in their original locations, auxiliary set datafiles must not overwrite the corresponding original files in the target database. If you do not specify an auxiliary set file location that is different from its original location, then TSPITR fails. The failure occurs when RMAN attempts to overwrite the corresponding file in the original database and discovers the file in use.
The simplest way to provide locations for auxiliary set datafiles is to specify an auxiliary destination for TSPITR. However, RMAN supports the following alternatives for controlling the location of auxiliary set datafiles, which are listed in order of precedence shown in Table 20-3.
Table 20-3 Order of Precedence for Naming Files
Order | Technique | Section |
---|---|---|
1 |
|
|
2 |
|
"Using SET NEWNAME and CONFIGURE AUXNAME with Auxiliary Set Image Copies" |
3 |
|
"Using DB_FILE_NAME_CONVERT to Name Auxiliary Set Datafiles". If target database uses OMF names for auxiliary set, then you cannot use |
4 |
|
Settings higher on the list override settings lower on the list in situations where both have been applied. For example, you might run RECOVER TABLESPACE... AUXILIARY DESTINATION
on a target database when some auxiliary set datafiles have auxiliary names configured with CONFIGURE AUXNAME
.
Even if you intend to use either of the preceding techniques to provide locations for specific files, Oracle recommends that you provide an AUXILIARY DESTINATION
argument to RECOVER TABLESPACE
when using an RMAN-managed auxiliary instance. If you overlook renaming some auxiliary set datafiles, then TSPITR will still succeed. Any files not otherwise renamed will be placed in the auxiliary destination.
Note:
You can view any currentCONFIGURE
AUXNAME
settings by running the SHOW
AUXNAME
command, which is described in Oracle Database Backup and Recovery Reference.Auxiliary set datafiles can have Oracle Managed Files (OMF) in the target and can use ASM or non-ASM storage. TSPITR performs name conversion differently when the DB_FILE_NAME_CONVERT
initialization parameter is set and the OMF files are in ASM or non-ASM storage.
For Oracle Managed Files (OMF) that use ASM storage, the database converts only disk group names as in: +DISK1 to +DISK2.
You can use DB_FILE_NAME_CONVERT
and LOG_FILE_NAME_CONVERT
initialization parameters for the auxiliary instance to specify the conversion of the disk group. RMAN uses the pattern to convert the ASM disk group name and generates a valid OMF filename in the converted disk group. The following command demonstrates this point:
LOG_FILE_NAME_CONVERT='+onlinelogs','+tmpasm'
If the DB_FILE_NAME_CONVERT
and LOG_FILE_NAME_CONVERT
parameters change a substring other than the disk group name, the conversion is ignored and the resulting disk group name is used, for example:
DB_FILE_NAME_CONVERT='+DATAFILE/prod','+DATAFILE/tspitr'
The command above results in an invalid ASM OMF filename and the change is ignored. Instead, the files are created in disk group name +DATAFILE and the following message is issued:
WARNING: DB_FILE_NAME_CONVERT resulted in invalid ASM names; names changed to disk group only
If auxiliary set datafiles are stored in ASM disk groups, then you can use SET
NEWNAME
to redirect individual files to a specific disk group accessible from the auxiliary instance (and allow the database to generate the filename within the disk group). Example 20-6 shows how to do this:
The initialization parameters DB_FILE_NAME_CONVERT
and LOG_FILE_NAME_CONVERT
cannot be used to rename OMF (non-ASM) filenames for the auxiliary instance since this method generates invalid OMF filenames. If you need to control the generation of new OMF filenames that do not use ASM storage, you must rename them using one of the alternate techniques outlined below. The various naming options are listed in order from most recommended to least recommended.
Use an auxiliary destination, as described in "Performing Fully Automated RMAN TSPITR".
Specify locations for new OMF files with or more of the OMF initialization parameters for the auxiliary instance so that all of the necessary OMF files are handled:
DB_CREATE_FILE_DEST
for the auxiliary set datafiles
DB_CREATE_ONLINE_LOG_DEST_
n
together with DB_CREATE_FILE_DEST
for the online redo logs of the auxiliary instance if the online logs will not be created in the DB_CREATE_FILE_DEST
.
To specify a new name for an auxiliary set datafile, you can enclose RECOVER TABLESPACE
in a RUN
command and use a SET NEWNAME
command within the RUN
block to rename the file. Example 20-7 illustrates the basic technique.
Example 20-7 Renaming Auxiliary Set Oracle Managed Files (OMF) in TSPITR
RUN { SET NEWNAME FOR DATAFILE '?/oradata/prod/system01.dbf' TO '/disk1/auxdest/system01.dbf'; SET NEWNAME FOR DATAFILE '?/oradata/prod/sysaux01.dbf' TO '/disk1/auxdest/sysaux01.dbf'; SET NEWNAME FOR DATAFILE '?/oradata/prod/undotbs01.dbf' TO '/disk1/auxdest/undotbs01.dbf'; RECOVER TABLESPACE users, tools UNTIL LOGSEQ 1300 THREAD 1 AUXILIARY DESTINATION '/disk1/auxdest'; }
The result depends on whether /disk1/auxdest/system01.dbf
exists when RECOVER TABLESPACE
is executed. If ?/oradata/system01.dbf
exists at the specified location and was created at an SCN before the UNTIL
time for TSPITR, then the DATAFILECOPY
is used and restore is not necessary. For more information, see "Using SET NEWNAME and CONFIGURE AUXNAME with Auxiliary Set Image Copies". Otherwise, RMAN restores the auxiliary set datafile to the NEWNAME
instead of the default location. If your intention is only to control where the auxiliary set datafiles are stored, then ensure that no file is stored at the location specified by SET NEWNAME
before performing TSPITR.
Assume that you do not want to use an auxiliary destination for all of your auxiliary set datafiles, but you also do not want to name every file individually. In this case, you can include a DB_FILE_NAME_CONVERT
initialization parameter in the initialization parameter file used by the auxiliary instance. You can only use this technique in the following circumstances:
You create your own initialization parameter file for an automatically managed auxiliary instance, as described in "Customizing Initialization Parameters for the Automatic Auxiliary Instance in TSPITR".
or
You create your own auxiliary instance, as described in "Performing RMAN TSPITR Using Your Own Auxiliary Instance".
The filenames to be converted are ASM/OMF filenames.
The DB_FILE_NAME_CONVERT
initialization parameter in the auxiliary instance specifies how to derive names for files in the auxiliary instance from the original names of the corresponding files in the target database instance. The parameter consists of a list of pairs of strings. For any filename that contains the first string of a pair as a substring, the name of the corresponding file in the auxiliary instance is generated by substituting the second string of the pair into the original filename.
For example, assume that the target instance contains the following files:
?/oradata/trgt/system01.dbf
of the SYSTEM
tablespace
?/oradata/trgt/sysaux01.dbf
of the SYSAUX
tablespace
?/oradata/trgt/undotbs01.dbf
of the undotbs
tablespace
To place the corresponding files of the auxiliary instance in /bigtmp
, then you would add the following line to the auxiliary instance parameter file:
DB_FILE_NAME_CONVERT=('?/oradata/trgt', '/bigtmp')
New filenames for the corresponding auxiliary instance files would be /bigtmp/trgt/system01.dbf
, /bigtmp/trgt/sysaux01.dbf
, and /bigtmp/trgt/undotbs01.dbf
.
The most important point to remember is that DB_FILE_NAME_CONVERT
must be present in the auxiliary instance parameter file. If the auxiliary instance was manually created, then add DB_FILE_NAME_CONVERT
to the auxiliary instance parameter file.
You can still rename individual auxiliary set datafiles with SET NEWNAME
or CONFIGURE AUXNAME
. Also, files that do not match the patterns provided in DB_FILE_NAME_CONVERT
will not be renamed. When using RMAN-managed auxiliary instance, you can use the AUXILIARY DESTINATION
parameter of RECOVER TABLESPACE
to ensure that all auxiliary set datafiles are sent to some destination. If none of the renaming methods used provide a new name for a file at the auxiliary instance, then TSPITR will fail.
Tempfiles are considered part of the auxiliary set for your database. When the auxiliary instance is instantiated, RMAN re-creates the temporary tablespaces of the target database and generates their names by means of the regular rules for the auxiliary datafile names.
To rename tempfiles, you can use one of the following:
SET
NEWNAME
FOR
TEMPFILE
command
DB_FILE_NAME_CONVERT
initialization parameter of the auxiliary instance. See the previous example. If the temporary files have non-ASM Oracle Managed File names, you cannot use this parameter option. See "Considerations When Renaming OMF Auxiliary Set Files in TSPITR".
AUXILIARY DESTINATION
clause of the RECOVER
command when using a RMAN-managed auxiliary instance
You can enhance TSPITR performance by redirecting RMAN to use existing image copies of the recovery set and auxiliary set datafiles. In this case, RMAN does not need to restore the datafiles from backup. You can use the following techniques to tell RMAN about the possible existence of an image copy of a datafile:
Use CONFIGURE AUXNAME
command with image copies of auxiliary set datafiles
Use SET NEWNAME
command with image copies of recovery set datafiles or auxiliary set datafiles
In general, if a suitable image copy is available in the specified location, then RMAN uses the image copy to perform the TSPITR and the datafilecopy is uncataloged from the target controlfile.
During TSPITR, RMAN looks in the specified NEWNAME
location for the datafile. RMAN checks whether an image copy backup of the datafile exists with a datafile checkpoint SCN early enough that it can be recovered to the target time. If RMAN finds a usable image copy, then RMAN uses it in TSPITR. Otherwise, RMAN restores the datafile to the NEWNAME
location. Any file in the location specified by the NEWNAME
is overwritten. The specified NEWNAME
becomes the name of the datafile in the target database once TSPITR completes. Example 20-8 illustrates this technique.
CONFIGURE AUXNAME
sets a persistent alternative location for an auxiliary set datafile image copy, while SET NEWNAME
sets an alternative location for the duration of a RUN
command.
Assume that you use SET NEWNAME
or CONFIGURE AUXNAME
to specify a new location for an auxiliary set datafile. Also assume that there is an image copy at that location with an SCN that can be used in TSPITR. In this case, RMAN uses the image copy. If there is no usable image copy at that location, however, then RMAN restores a usable copy from backup. (If an image copy is present but the SCN is after the target time for TSPITR, then the datafile is overwritten by the restored file.)
As with all auxiliary set files, the file is deleted after TSPITR. This behavior occurs regardless of whether it was an image copy created before TSPITR or restored by RMAN during TSPITR.
The primary use of CONFIGURE AUXNAME
is to make TSPITR faster by eliminating restore times. If you anticipate performing TSPITR, then you can include in your backup routine the maintenance of a set of image copies of the auxiliary set datafiles, and update these periodically to the earliest point to which you expect to perform TSPITR. The recommended usage model is:
Configure the AUXNAME
for the files once, when setting up this strategy.
Perform BACKUP AS COPY DATAFILE
n
FORMAT
auxname
regularly to maintain the updated image copy. For better performance, use an incrementally updated backup strategy to keep the image copies up to date without performing full backups of the datafiles
When TSPITR is needed, specify a target time after the last update of the image copy.
Assume that you have enough disk space to save image copies of your entire database for use in TSPITR. In preparation for the possibility of TSPITR, you do the following:
Configure an AUXNAME
for each datafile in the auxiliary set by using a command of the following form:
CONFIGURE AUXNAME FOR DATAFILE n TO auxname_n;
Take an image copy of the auxiliary set every Sunday by using a command of the following form:
BACKUP AS COPY DATAFILE n FORMAT auxname_n
If the image copies are all in the same location on disk, and if they are named similarly to the original datafiles, then you can avoid performing backups of every datafile. Instead, you can use the FORMAT
or DB_FILE_NAME_CONVERT
options of the BACKUP
command and use BACKUP AS COPY DATABASE
. For example, if the configured auxiliary names are a translation of the location maindisk
to auxdisk
, then you use the following command:
BACKUP AS COPY DATABASE DB_FILE_NAME_CONVERT (maindisk, auxdisk);
Note:
Because Oracle managed filenames cannot generally be translated using a simple substitution, you cannot typically use the technique of usingDB_FILE_NAME_CONVERT
to generate names for image copies stored in OMF.You are then prepared for TSPITR without restoring the auxiliary set from backup. For example, if an erroneous batch job, started on November 15, 2007, at 19:00:00, incorrectly updates the tables in the tablespace parts
, you use the following command to perform TSPITR on tablespace parts
:
RECOVER TABLESPACE parts UNTIL TIME 'November 15 2007, 19:00:00';
Because AUXNAME
locations are configured and refer to datafile copies from an SCN before the TSPITR target time, the auxiliary set is not restored from backup. Instead, the datafile copies are used in recovery which reduces the restore overhead.
You can also prevent the recovery set from being restored. You need to take frequent image copies of the tablespaces and use SET NEWNAME
to specify the location of these copies. This method ensures that the recovery set will not be restored and the tablespace will change location once TSPITR successfully completes.
The automatic auxiliary instance uses a set of default initialization parameters as shown in Table 20-4, it also looks for additional initialization parameters to complement the default parameters in a location that is operating system-dependent. For example, in Unix it is: ?/rdbms/admin/params_auxinst.ora
. RMAN always looks for this additional parameter file for a RMAN-automatic auxiliary instance when performing TSPITR. If the file is not found, then RMAN does not generate an error. Instead, RMAN only uses the default parameters in Table 20-4 for the RMAN-managed automatic auxiliary instance.
Table 20-4 Default Initialization Parameters for the RMAN-Managed Auxiliary Instance
Initialization Parameter | Value |
---|---|
|
Same as |
|
Same as the compatible setting of the target database. |
|
RMAN auto-generated unique value based on |
|
Same as the |
|
Auxiliary destination (only if the |
|
Auxiliary destination (only if the |
|
|
|
Same as |
|
|
In most cases it is not necessary to alter or add to the values of these initialization parameters, especially if you provide an AUXILIARY DESTINATION
clause to RECOVER TABLESPACE
when using a RMAN-managed auxiliary instance. If you override one of the initialization parameters in Table 20-4 with an inappropriate value, then TSPITR may fail due to problems with the auxiliary instance. Nevertheless, you can add other parameters besides these basic parameters if needed. For example, you can use DB_FILE_NAME_CONVERT
to specify the names of the datafiles in the auxiliary and recovery sets.
To override or specify parameters for the automatic auxiliary instance, you can either:
Place the initialization parameters in the OS specific default auxiliary parameter filename. For example, in Unix: ?/rdbms/admin/params_auxinst.ora
.
Place the initialization parameters in a file
Specify the location of this file with the SET AUXILIARY INSTANCE PARAMETER FILE
command before executing TSPITR.
Regardless of the method you choose, the parameters you specify take precedence over defaults and can override the value of an AUXILIARY DESTINATION
clause.
If you use an initialization parameter file, then you can specify your own location for the control file of your auxiliary instance. Set the CONTROL_FILES
initialization parameter to specify a location for the control files.
If you do not explicitly specify a control file location, and if you use the AUXILIARY DESTINATION
clause, then RMAN locates the control file in the auxiliary destination. If you do not use AUXILIARY DESTINATION
, then the auxiliary instance control files are stored in an operating system-specific location.
No matter where you store your auxiliary instance control file, it is removed at the end of the TSPITR operation. Because control files are relatively small, it is rare that RMAN will encounter a problem creating an auxiliary control file. If there is not enough space to create the control file, however, then TSPITR will fail.
To perform recovery on the auxiliary and recovery sets after restoring them at the auxiliary instance, RMAN may need to restore archived logs. When an auxiliary destination is being used, the archived logs are restored to that location. In the absence of an auxiliary destination and any other initialization parameters, the archived logs will be restored to an OS specific location. For details, consult your OS-specific documentation. You can use LOG_ARCHIVE_DEST_1 initialization parameter to specify an alternative location where the archived logs will be restored.
If you specify the LOG_FILE_NAME_CONVERT
initialization parameter in your auxiliary instance parameter file and the parameter successfully converts the names of the online redo logs of the target, then this parameter determines the online redo log location. The same restrictions that apply to OMF datafiles, apply to OMF online redo logs. For more information, see "Considerations When Renaming OMF Auxiliary Set Files in TSPITR". If RMAN is managing the auxiliary instance and an auxiliary destination is specified, RMAN creates the online redo log in the auxiliary destination.
Alternatively you can use DB_CREATE_FILE_DEST
or DB_CREATE_FILE_DEST
and DB_CREATE_ONLINE_LOG_1
to specify the location where the auxiliary instance redo logs will be created. If you choose the later option, you must use DB_CREATE_ONLINE_LOG_1
together with DB_CREATE_FILE_DEST
in order for RMAN TSPITR to use it.
If you do not specify a location for the online redo logs using one of the following:
LOG_FILE_NAME_CONVERT
DB_CREATE_FILE_DEST
DB_CREATE_FILE_DEST
and DB_CREATE_ONLINE_LOG_1
AUXILIARY DESTINATION
TSPITR will fail trying to create the online redo logs.
While Oracle recommends that you let RMAN to manage all aspects of the auxiliary instance, there may be times when you need to create and manage your own auxiliary instance. If you select this mode, you are responsible for setting up, starting, stopping and cleaning up the auxiliary instance used in TSPITR
One reason you might want to create your own instance is to exercise control of channels used in TSPITR. The automatic auxiliary instance uses the configured channels of the target database as the basis for the channels to configure on the auxiliary instance and use during restore. You may need different channel settings and may not want to use CONFIGURE
to change the settings on the target database. In this case, you can operate your own auxiliary instance. By connecting to the auxiliary instance before invoking RECOVER
, a run block can provide specific channel allocations using the ALLOCATE AUXILIARY CHANNEL
command.
Creating an Oracle instance suitable for use as an auxiliary instance requires that you carry out all of the following steps:
Step 1: Create an Oracle Password File for the Auxiliary Instance
Step 2: Create an Initialization Parameter File for the Auxiliary Instance
Step 3: Check Oracle Net Connectivity to the Auxiliary Instance
For instructions on how to create and maintain Oracle password files, refer to Oracle Database Administrator's Guide.
Use a text editor to create an initialization parameter file for the auxiliary instance on the target database host. For this example, assume your parameter file is placed at /tmp/initAux.ora
. Set the parameters described in Table 20-5.
Note:
For TSPITR, the target and auxiliary database instances must be on the same host.Table 20-5 Initialization Parameters in a User-Managed Auxiliary Instance
Parameter | Mandatory? | Value |
---|---|---|
YES |
The same name as the target database. |
|
YES |
A value different from any database in the same Oracle home. For simplicity, specify |
|
|
YES |
Set to |
|
YES |
The same value as the parameter in the target database. |
|
YES |
If this initialization parameter is set in the target database, then it must be set to the same value in the auxiliary instance. |
NO |
Patterns to generate filenames for the online redo logs of the auxiliary database based on the online redo log names of the target database. Query Note: Some platforms do not support ending patterns in a forward or backward slash ( See Also: "Specifying the Auxiliary Instance Online Log Location in TSPITR" for restrictions on possible values for |
|
NO |
Patterns to convert filenames for the datafiles of the auxiliary database. You can use this parameter to generate filenames for those files that you did not name with Note: Some platforms do not support ending patterns in a forward or backward slash ( See Also: "Using DB_FILE_NAME_CONVERT to Name Auxiliary Set Datafiles" and "Considerations When Renaming OMF Auxiliary Set Files in TSPITR". |
|
|
NO |
Use it to specify a location for all auxiliary set files |
|
NO |
Use it to specify where archived logs required for recover will be created |
|
NO |
Use it together with |
NO |
Filenames that do not conflict with the control file names of the target instance (or any other existing file). |
|
|
NO (Recommended) |
280M |
|
NO YES |
If If |
Set other parameters as needed, including the parameters to specify how much memory the auxiliary instance will use.
The following example shows possible initialization parameter settings for an auxiliary instance for TSPITR:
DB_NAME=trgt DB_UNIQUE_NAME=_trgt CONTROL_FILES=/tmp/control01.ctl DB_FILE_NAME_CONVERT=('/oracle/oradata/trgt/','/tmp/') LOG_FILE_NAME_CONVERT=('/oracle/oradata/trgt/redo','/tmp/redo') REMOTE_LOGIN_PASSWORDFILE=exclusive COMPATIBLE =11.0.0 DB_BLOCK_SIZE=8192
Note:
After setting these initialization parameters, ensure that you do not overwrite the initialization settings for the production files at the target database.See Also:
Oracle Database Net Services Administrator's Guide for more information about Oracle NetThe auxiliary instance must have a valid net service name. Before proceeding, use SQL*Plus to ensure that you can establish a SYSDBA
connection to the auxiliary instance.
If you are running your own auxiliary instance, then it is possible for the sequence of commands required for TSPITR to be long. This situation can occur when you allocate a complex channel configuration for restoring from backup and you are not using DB_CREATE_FILE_DEST
to determine file naming of auxiliary set files.
You may want to store the series of commands for TSPITR in an RMAN command file. Review the command file carefully to catch any errors. To read the command file into RMAN, use the @
command (or the CMDFILE
command line argument when starting RMAN).
The following example runs the command file named /tmp/tspitr.rman
:
@/tmp/tspitr.rman;
See Also:
"Using Command Files with RMAN"When you run your own auxiliary instance, the default behavior is to use the automatic channel configuration of the target instance. If you decide to allocate your own channels with different a configuration (changing the number of channels or channel parameters), you can include ALLOCATE AUXILIARY CHANNEL
commands in a RUN
block along with the RECOVER TABLESPACE
command for TSPITR. Plan out these commands, if necessary, and add them to the sequence of commands you will run for TSPITR.
See Also:
"Performing TSPITR with Your Own Auxiliary Instance: Scenario" to learn how to include channel allocation in your TSPITR scriptYou may want to use SET NEWNAME
commands to refer to existing image copies of auxiliary set files to improve TSPITR performance, or to assign new names to the recovery set files for after TSPITR. Plan out these commands, if necessary, and add them to the sequence of commands you will run for TSPITR. For more information, see "Renaming TSPITR Recovery Set Datafiles with SET NEWNAME".
With the preparations complete and your TSPITR commands completely planned, you are now ready to perform TSPITR. The following steps are required:
Before beginning RMAN TSPITR, start SQL*Plus and connect to the auxiliary instance with SYSOPER
privileges.
Start the auxiliary instance in NOMOUNT
mode, specifying a parameter file if necessary. For example, enter the following SQL*Plus command:
SQL> STARTUP NOMOUNT PFILE='/tmp/initAux.ora'
Remember that if you specify PFILE
, then the path for the PFILE
will be a client-side path on the host from which you run SQL*Plus.
Because the auxiliary instance does not yet have a control file, you can only start the instance in NOMOUNT
mode. Do not create a control file or try to mount or open the auxiliary instance for TSPITR.
Start RMAN and connect to the target database and the manually created auxiliary instance.
$ rman target dba/dbapwd AUXILARY aux/auxpwd@aux
In the simplest case, execute the RECOVER TABLESPACE... UNTIL
command at the RMAN prompt:
RECOVER TABLESPACE ts1, ts2... UNTIL TIME 'time';
If you want to use the ALLOCATE AUXILIARY CHANNEL
or SET NEWNAME
commands, then include these commands before the RECOVER TABLESPACE
command within a RUN
command. The following example illustrates this technique:
RUN
{
ALLOCATE AUXILIARY CHANNEL c1 DEVICE TYPE DISK;
ALLOCATE AUXILIARY CHANNEL c2 DEVICE TYPE sbt;
# and so on...
RECOVER TABLESPACE ts1, ts2 UNTIL TIME 'time';
}
This scenario shows the execution of a RECOVER TABLESPACE... UNTIL
operation. This scenario illustrates the following features of RMAN TSPITR:
Managing your own auxiliary instance
Configuring channels for restore of backups from disk and SBT devices
Using recoverable image copies for some auxiliary set datafiles using SET NEWNAME
Specifying new names for recovery set datafiles using SET NEWNAME
Prepare the auxiliary instance as described in "Preparing Your Own Auxiliary Instance for RMAN TSPITR". Specify a password for the auxiliary instance in the password file, and set up the auxiliary instance parameter file /bigtmp/init_tspitr_prod.ora
with the following settings:
DB_NAME=PROD DB_UNIQUE_NAME=tspitr_PROD CONTROL_FILES=/bigtmp/tspitr_cntrl.dbf' DB_CREATE_FILE_DEST=/bigtmp COMPATIBLE=11.0.0 BLOCK_SIZE=8192 REMOTE_LOGIN_PASSWORD=exclusive
Create service name pitprod
for the auxiliary instance, and check for connectivity.
Using SQL*Plus, connect to the auxiliary instance with SYSOPER
privileges. Start the instance in NOMOUNT
mode:
SQL> STARTUP NOMOUNT PFILE=/bigtmp/init_tspitr_prod.ora
Start RMAN and connect to the target and auxiliary database instances.
$ rman target / auxiliary sys/syspwd@pitprod
Enter the following commands in a RUN
block to set up and execute TSPITR:
RUN { # Specify NEWNAME for recovery set datafiles SET NEWNAME FOR TABLESPACE clients TO '?/oradata/prod/rec/%b'; # Specify NEWNAMES for some of the auxiliary set # datafiles that have a valid image copy to avoid restores: SET NEWNAME FOR DATAFILE '?/oradata/prod/system01.dbf' TO '/backups/prod/system01_monday_noon.dbf'; SET NEWNAME FOR DATAFILE '?/oradata/prod/system02.dbf' TO '/backups/prod/system02_monday_noon.dbf'; SET NEWNAME FOR DATAFILE '?/oradata/prod/sysaux01.dbf' TO '/backups/prod/sysaux01_monday_noon.dbf'; SET NEWNAME FOR DATAFILE '?/oradata/prod/undo01.dbf' TO '/backups/prod/undo01_monday_noon.dbf'; # Specify the types of channels to use ALLOCATE AUXILIARY CHANNEL c1 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL t1 DEVICE TYPE sbt; # Recover the clients tablespace to 24 hours ago: RECOVER TABLESPACE clients UNTIL TIME 'sysdate-1'; }
Consider storing this command sequence in a command file and executing the command file.
If the TSPITR operation is successful, then the results are:
The recovery set datafiles are registered in the target database control file under the names specified with SET NEWNAME
, with their contents as of the time specified time for the TSPITR.
The auxiliary files are removed by RMAN, including the control files, online logs and auxiliary set datafiles of the auxiliary instance.
The auxiliary instance is shut down.
If the TSPITR operation fails, the auxiliary set files are removed and the auxiliary instance is shutdown. The recovery set files are left in the specified location and in an unresolved state from the failed TSPITR run.
A variety of problems can cause RMAN TSPITR to fail. This section lists possible areas to check and fix:
Filename conflicts
Mismatched or incorrect TSPITR target times for sets of tablespaces and undo segments.
Management issues with auxiliary instances not created by RMAN
Name conflicts can occur between files already in the target database, filenames assigned by the SET NEWNAME or CONFIGURE AUXNAME commands, and filenames generated by the effect of the DB_FILE_NAME_CONVERT parameter.
Suppose that SET NEWNAME
, CONFIGURE AUXNAME
, and DB_FILE_NAME_CONVERT
cause multiple files in the auxiliary or recovery sets to have the same name. In this case, RMAN reports an error during TSPITR. To correct the problem, use different values for these parameters to eliminate the duplicate name.
During TSPITR, RMAN needs information about which tablespaces had undo segments at the TSPITR target time. This information is usually available in the recovery catalog, if one is used.
If there is no recovery catalog or the information is not found in the recovery catalog, RMAN assumes that the set of tablespaces with undo segments at the target time is the same as the set of tablespaces with undo segments at the present time. If this assumption is not correct, then TSPITR will fail with an error. In this case, use the UNDO
TABLESPACE
clause to provide a list of tablespaces with undo segments at the target time.
If you are managing your own auxiliary instance and TSPITR fails, do not attempt to rerun TSPITR without resolving the errors and following this approach:
Identify and fix the problem(s) that prevented TSPITR from a successful run
Start the auxiliary instance in NOMOUNT
Run TSPITR again