Oracle9i Recovery Manager User's Guide Release 1 (9.0.1) Part Number A90135-01 |
|
This chapter describes how to use the duplicate
command to create a duplicate database for testing purposes. This chapter contains these topics:
Oracle9i Data Guard Concepts and Administration to learn how to create a standby database using the
See Also:
DUPLICATE
command
You can use the RMAN DUPLICATE
command create a duplicate database from target database backups while still retaining the original target database. A duplicate database is a copy of the target database that you can run independently for a variety of purposes. For example, you can use it to:
For example, you can duplicate the production database on host1
to host2
, and then use the duplicate database on host2
to practice restore and recovery scenarios while the production database on host1
continues as usual.
A duplicate database is distinct from a standby database, although both types of databases are created with the DUPLICATE
command. A standby database is a copy of the primary database that you can update continually or periodically by using archived logs from the primary database. If the primary database is damaged or destroyed, then you can perform failover to the standby database and effectively transform it into the new primary database. A duplicate database, on the other hand, cannot be used in this way: it is not intended for failover scenarios and does not support the various standby recovery and failover options.
See Also:
Chapter 13, "Creating a Standby Database with Recovery Manager" to learn how to create a standby database with the |
To prepare for database duplication, you must first create an auxiliary instance as described in "Preparing the Auxiliary Instance for Duplication: Basic Steps". For the duplication to work, you must connect RMAN to both the target (primary) database and an auxiliary instance started in NOMOUNT
mode.
You must have at least one auxiliary channel allocated on the auxiliary instance. The principal work of the duplication is performed by the auxiliary channel, which starts a server session on the duplicate host. This channel then restores the necessary backups of the primary database, uses them to create the duplicate database, and initiates recovery.
So long as RMAN is able to connect to the primary and duplicate instances, the RMAN client can run on any machine. However, all backups, copies of datafiles, and archived logs used for creating and recovering the duplicate database must be accessible by the server session on the duplicate host. If the duplicate host is different from the primary host, then you must make backups and copies on the primary host disks available to the remote node with the same full path name as in the primary database. You can accomplish this goal in two ways:
In the case of tape backups, you must make the tapes containing the backups accessible to the remote node, either by physically moving the tape to the remote host or by using a network tape server.
As part of the duplicating operation, RMAN manages the following:
RESETLOGS
option after incomplete recovery to create the online redo logs
DUPLICATE
...
FOR
STANDBY
(described in Chapter 13, "Creating a Standby Database with Recovery Manager"), then RMAN does not create a unique DBID.
During duplication, RMAN must perform incomplete recovery because the online redo logs in the target are not backed up and cannot be applied to the duplicate database. The farthest that RMAN can go in recovery of the duplicate database is the last log archived by the target database.
When duplicating a database, you can do the following:
DUPLICATE
command with or without a recovery catalog
SKIP
READONLY
clause. Read-only tablespaces are included by default. If you omit them, then you can add them later.
NOFILENAMECHECK
option and reuse the target datafile filenames for the duplicate datafiles.
SET
UNTIL
option when creating the duplicate database to recover it to a noncurrent time. By default, the DUPLICATE
command creates the database by using the most recent backups of the target database and then performs recovery to the most recent consistent point contained in the incremental backups and archived redo logs.
DB_NAME
differently from the target database DB_NAME
in some cases. If the duplicate database exists in the same Oracle home as the target, then the DB_NAME
initialization parameter must be different. If the duplicate database resides in a different Oracle home (on the same machine or on another machine), then its DB_NAME
setting just has to be different from other database names in the same Oracle home on the duplicate host.
RMAN duplication involves a number of prerequisites, restrictions, and caveats. Review the restrictions section of the DUPLICATE
syntax entry before attempting duplication (see Oracle9i Recovery Manager Reference for DUPLICATE
syntax).
When duplicating a database, RMAN creates the required database files. This section describes these stages of file creation:
The DUPLICATE
command creates the control files by using the names listed in the initialization parameter file of the auxiliary instance. When choosing names for the duplicate database control files, make sure that you set the initialization parameter settings correctly so that you do not overwrite the production files at the target database.
Table 12-1 lists the options for creating the names of the duplicate online redo logs. The options appear in the order of precedence.
The order of precedence determines how RMAN renames the online redo logs. For example, if you specify both the LOGFILE
clause and the LOG_FILE_NAME_CONVERT
parameter, then RMAN uses the LOGFILE
clause. If you specify neither of the first two options, then RMAN uses the original target redo log filenames for the duplicate database files.
To have different filenames for the duplicate datafiles, you must use parameters or commands to specify them. Table 12-2 lists the options for renaming datafiles. The options appear in the order of precedence.
The order of precedence determines how RMAN names the files. For example, if you specify all the commands and the initialization parameter, then RMAN uses SET
NEWNAME
. If you run CONFIGURE
AUXNAME
and DB_FILE_NAME_CONVERT
, then RMAN uses CONFIGURE
AUXNAME
. If you do not specify any of the first three options, then RMAN uses the original target filenames for the duplicate file.
When you specify SKIP
READONLY
, RMAN does not duplicate the datafiles of read-only tablespaces. After duplication is complete, you can query the views in the duplicate database described in Table 12-3 and Table 12-4 to determine whether datafiles are read-only. The STATUS
and ENABLED
columns are the key to determining the current status of the duplicate datafile.
In the column ... | The value is ... |
---|---|
|
|
|
|
|
|
View | In the column ... | The value is ... |
---|---|---|
|
|
|
|
|
|
When tablespaces are taken offline with the OFFLINE
NORMAL
option, RMAN does not duplicate the datafiles of these tablespaces. After duplication, you can manually add or drop these tablespaces. Query the views in the duplicate database described in Table 12-5 and Table 12-6 to determine whether datafiles are offline. The STATUS
and ENABLED
columns are the key to determining the current status of the datafile.
In the column ... | The value is ... |
---|---|
|
|
|
|
|
|
View | In the column ... | The value is ... |
---|---|---|
|
|
|
|
|
|
When you take a tablespace offline with the IMMEDIATE
option, RMAN duplicates rather than skips the tablespace because this tablespace requires recovery. As with online tablespaces, RMAN requires a valid backup for duplication.
It is possible for a CONFIGURE
AUXNAME
, SET
NEWNAME
, or DB_FILE_NAME_CONVERT
to generate a name that is already in use in the target database. In this case, specify NOFILENAMECHECK
to avoid an error message. For example, assume that the host A database has two files: datafile 1
is named /oracle/data/file1.f
and datafile 2
is named /oracle/data/file2.f
. When duplicating to host B, you use a configured channel to duplicate as follows:
RUN { SET NEWNAME FOR DATAFILE 1 TO /oracle/data/file2.f; # rename datafile 1 as file2.f SET NEWNAME FOR DATAFILE 2 TO /oracle/data/file1.f; # rename datafile 2 as file1.f DUPLICATE TARGET DATABASE TO newdb; }
Even though you issued SET
NEWNAME
commands for all the datafiles, the DUPLICATE
command fails because the duplicate filenames are still in use in the target database. Although datafile 1
in the target is not using /oracle/data/file2.f
, and datafile 2
in the target is not using /oracle/data/file1.f
, the target filename is used by one of the duplicate datafiles and so you must specify NOFILENAMECHECK
to avoid an error.
Perform these tasks before performing RMAN duplication:
For instructions on how to create and maintain Oracle password files, refer to Oracle9i Database Administrator's Guide.
The auxiliary instance must be accessible through Oracle Net. Before proceeding, start SQL*Plus to ensure that you can establish a connection to the auxiliary instance. Note that you must connect to the auxiliary instance with SYSDBA
privileges, so a password file must exist.
Create a client-side initialization parameter file for the auxiliary instance, and set at least the parameters described in the following table.
Parameter | You must specify: |
---|---|
|
The same name used in the |
|
Refer to "Creating the Duplicate Control Files". |
Optionally, set the parameters described in the following table.
Parameter | You must specify: |
---|---|
|
Refer to "Naming the Duplicate Datafiles". |
|
Set other parameters, including the parameters that allow you to connect as SYSDBA
through Oracle Net, as needed. When duplicating to the same host or to a new host with a different file system, pay special attention to all parameters specifying path names. Verify that all paths are accessible on the host where the database is being duplicated.
Following are examples of the initialization parameter settings for the duplicate database:
DB_NAME=newdb CONTROL_FILES=(/oracle/dup_prod/cf/cf1.f,/oracle/dup_prod/cf/cf2.log) DB_FILE_NAME_CONVERT=(/oracle/prod/db,/oracle/dup_prod/db, /disk2/db,/oracle/dup_prod/db) LOG_FILE_NAME_CONVERT=(/oracle/prod/log,/oracle/dup_prod/log)
After you create the client-side initialization parameter file, you can run the CREATE
SPFILE
command from SQL*Plus to create a server-side initialization parameter file. You can run this command before or after instance startup. For example, you can create a server-side parameter file in the default location as follows, specifying the filename of the client-side initialization parameter file in the FROM
clause:
SQL> CREATE SPFILE FROM PFILE='/oracle/dup_prod/dbs/initDUPDB.ora';
A server-side parameter file in the default location is an advantage when duplicating a database because you do not need to specify the PFILE
parameter on the DUPLICATE
command. Because RMAN shuts down and restarts the auxiliary instance as part of the duplication process, you must tell RMAN which client-side file to use if you use a client-side parameter file. It is highly recommended that you create a server-side parameter file for use in database duplication.
Before beginning RMAN duplication, use SQL*Plus to connect to the auxiliary instance and start it in NOMOUNT
mode (specifying a client-side parameter file if necessary). In this example, aux_pwd
is the password for the user with SYSDBA
authority and aux_str
is the net service name for the auxiliary instance:
SQL> CONNECT SYS/aux_pwd@aux_str AS SYSDBA SQL> STARTUP NOMOUNT # uses the server-side parameter file
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.
RMAN shuts down and restarts the auxiliary instance as part of the duplication process. Hence, it is a good idea to create a server-side initialization parameter file for the auxiliary instance in the default location.
If you do not have a server-side initialization parameter file for the auxiliary instance in the default location, then you must specify the client-side initialization parameter file with the PFILE
parameter on the DUPLICATE
command. The client-side parameter file for the auxiliary instance must reside on the same host as the RMAN executable used to perform the duplication.
Before beginning RMAN duplication, mount or open the target database--specifying a client-side parameter file if necessary--if it is not already mounted or open. For example, enter:
SQL> STARTUP PFILE='/oracle/dbs/initPROD1.ora'
Make sure backups all target datafiles are available. If you do not have backups of everything, then the duplicate operation fails. The database backup does not have to be a whole database backup: you can use a mix of full and incremental backups of individual datafiles.
Make sure that you meet either of the following conditions:
Start RMAN with a connection to the target database, the duplicate database, and (if you use one) the recovery catalog database. In this example, a connection is established to three databases, all through the use of net service names:
% rman TARGET SYS/target_pwd@target_str CATALOG rman/cat_pwd@cat_str AUXILIARY \ > SYS/aux_pwd@aux_str
If you do not have automatic channels configured, then before issuing the DUPLICATE
command, manually allocate at least one auxiliary channel within the same RUN
command. The channel type (DISK
or sbt
) must match the media where the backups of the target database are located. If the backups reside on disk, then the more channels you allocate, the faster the duplication will be. For tape backups, limit the number of channels to the number of devices available for the operation.
RUN { # to manually allocate a channel of type sbt issue: ALLOCATE AUXILIARY CHANNEL ch1 DEVICE TYPE sbt; # to manually allocate three auxiliary channels for disk issue (specifying whatever # channel id that you want): ALLOCATE AUXILIARY CHANNEL aux1 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux2 DEVICE TYPE DISK; ALLOCATE AUXILIARY CHANNEL aux3 DEVICE TYPE DISK; . . . DUPLICATE ... }
When you create a duplicate database, the procedure differs depending on your configuration. This section contains these topics:
The simplest case is to duplicate the database to a different host and to use the same directory structure. In this case, you do not need to change the initialization parameter file or set new filenames for the duplicate datafiles.
DUPLICATE
command, making sure to do the following:
NOFILENAMECHECK
parameter on the DUPLICATE
command.
PFILE
parameter if starting the auxiliary instance with a client-side parameter file. The client-side parameter file must exist on the same host as the RMAN executable used to perform the duplication.
The following example duplicates the database with an automatic channel, specifies an initialization parameter file, and also specifies the NOFILENAMECHECK
option:
DUPLICATE TARGET DATABASE TO dupdb # specify client-side parameter file (on same host as RMAN executable) for # auxiliary instance if necessary PFILE = /oracle/dbs/initDUPDB.ora NOFILENAMECHECK;
RMAN automatically allocates the configured channels, then uses all incremental backups, archived redo log backups, and archived redo logs to perform incomplete recovery. Finally, RMAN opens the database with the RESETLOGS
option to create the online redo logs.
If you create the duplicate database on a host with a different file system, you need to change several initialization parameter file parameters and generate new filenames for the duplicate database datafiles.
Use LOG_FILE_NAME_CONVERT
or the LOGFILE
clause to convert the online redo log filenames. Use DB_FILE_NAME_CONVERT
, the SET
NEWNAME
command, or the CONFIGURE
AUXNAME
command for the datafile filenames.
This section contains these topics:
This procedure assumes that you set initialization parameters to rename the duplicate datafiles and log files.
_DEST
or _PATH
and specify a path name.
DB_FILE_NAME_CONVERT
so that it captures all the target datafiles and converts them appropriately, for example, from tbs_*
to duptbs_*
.
LOG_FILE_NAME_CONVERT
so that it captures all the online redo logs and converts them appropriately, for example, log_*
to duplog_*
.
PFILE
parameter.
The following example duplicates the database with an automatic sbt
channel and uses a server-side parameter file to restart the auxiliary instance:
DUPLICATE DEVICE TYPE sbt TARGET DATABASE TO dupdb; # Note that DUPLICATE DEVICE TYPE sbt works only if the sbt device is configured # using CONFIGURE CHANNEL, CONFIGURE DEVICE TYPE, or CONFIGURE DEFAULT DEVICE.
RMAN uses all incremental backups, archived redo log backups, and archived redo logs to perform incomplete recovery. RMAN then shuts down, starts, and opens the database with the RESETLOGS
option to create the online redo logs.
This procedure assumes that you set initialization parameters to rename the duplicate datafiles and the LOGFILE
clause to rename the redo logs.
LOG_FILE_NAME_CONVERT
parameter.
LOGFILE
clause.
PFILE
parameter.
The following example duplicates the database with an automatic channel and specifies an initialization parameter file as well as the LOGFILE
clause:
DUPLICATE TARGET DATABASE TO dupdb # specify client-side parameter file for auxiliary instance if necessary PFILE = /oracle/dbs/initDUPDB.ora LOGFILE '/oracle/dbs/log1.f' SIZE 200K, '/oracle/dbs/log2.f' SIZE 200K;
This procedure assumes that you use the SET
NEWNAME
command to rename the duplicate datafiles.
_DEST
or _PATH
and specify a path name.
PFILE
parameter.
The following example uses automatic channels and a default server-side initialization parameter file for the database duplication, and specifies the LOGFILE
clause to name the online redo logs:
RUN { # set new filenames for the datafiles SET NEWNAME FOR DATAFILE 1 TO '$ORACLE_HOME/dbs/dupdb_data_01.f'; SET NEWNAME FOR DATAFILE 2 TO '$ORACLE_HOME/dbs/dupdb_data_02.f'; . . . # issue the duplicate command DUPLICATE TARGET DATABASE TO dupdb # create at least two online redo log groups LOGFILE GROUP 1 ('$ORACLE_HOME/dbs/dupdb_log_1_1.f', '$ORACLE_HOME/dbs/dupdb_log_1_2.f') SIZE 200K, GROUP 2 ('$ORACLE_HOME/dbs/dupdb_log_2_1.f', '$ORACLE_HOME/dbs/dupdb_log_2_2.f') SIZE 200K; }
RMAN uses all incremental backups, archived redo log backups, and archived redo logs to perform incomplete recovery. RMAN shuts down, starts up, and then opens the database with the RESETLOGS
option to create the online logs.
This procedure assumes that you use the CONFIGURE
AUXNAME
command to rename the duplicate datafiles.
_DEST
or _PATH
and specify a path name.
PFILE
parameter. The client-side parameter file must reside on the same host as the RMAN executable used to perform the duplication.
The following example uses automatic channels and a client-side initialization parameter file for the database duplication, and specifies the LOGFILE
clause to name the online redo logs:
# run the DUPLICATE command DUPLICATE TARGET DATABASE TO dupdb # specify client-side parameter file for auxiliary instance if necessary PFILE = /oracle/dbs/initDUPDB.ora . . . # create at least two online redo log groups LOGFILE GROUP 1 ('$ORACLE_HOME/dbs/dupdb_log_1_1.f', '$ORACLE_HOME/dbs/dupdb_log_1_2.f') SIZE 200K, GROUP 2 ('$ORACLE_HOME/dbs/dupdb_log_2_1.f', '$ORACLE_HOME/dbs/dupdb_log_2_2.f') SIZE 200K;
RMAN uses all incremental backups, archived redo log backups, and archived redo logs to perform incomplete recovery and then opens the database with the RESETLOGS
option to create the online redo logs.
# un-specify auxiliary names for the datafiles CONFIGURE AUXNAME FOR DATAFILE 1 CLEAR; CONFIGURE AUXNAME FOR DATAFILE 2 CLEAR; . . . CONFIGURE AUXNAME FOR DATAFILE n CLEAR;
When creating a duplicate database on the same host as the target database, follow the same procedure as for duplicating to a remote host with a different directory structure as described in "Duplicating a Database on a Remote Host with a Different Directory Structure".
Note that you can duplicate the database to the same Oracle home as the target database, but you must convert the filenames by means of the same methods used for conversion on a separate host.
This section contains these topics:
This example assumes the following:
rcat
.
host1
and contains nine datafiles.
dupdb
on remote host host2
.
host1
and host2
use different file systems.
host2
in the /oracle/dbs
subdirectory and use the tbs_*
prefix for each datafile.
host1
to an appropriate location in host2
.
_DEST
or _PATH
and specify a path name.
host2
by means of an operating system utility.
sbt
. The media management device is accessible by host2
.
PFILE
parameter is not necessary on the DUPLICATE
command).
CONNECT TARGET; CONNECT CATALOG rman/rman@rcat; CONNECT AUXILIARY sys/change_on_install@dupdb; # note that a RUN command is necessary because you can only execute SET NEWNAME # within a RUN command RUN { # the DUPLICATE command uses an automatic sbt channel SET NEWNAME FOR DATAFILE 1 TO '$ORACLE_HOME/dbs/tbs_01.f'; SET NEWNAME FOR DATAFILE 2 TO '$ORACLE_HOME/dbs/tbs_02.f'; SET NEWNAME FOR DATAFILE 3 TO '$ORACLE_HOME/dbs/tbs_03.f'; SET NEWNAME FOR DATAFILE 4 TO '$ORACLE_HOME/dbs/tbs_04.f'; SET NEWNAME FOR DATAFILE 5 TO '$ORACLE_HOME/dbs/tbs_05.f'; SET NEWNAME FOR DATAFILE 6 TO '$ORACLE_HOME/dbs/tbs_06.f'; SET NEWNAME FOR DATAFILE 7 TO '$ORACLE_HOME/dbs/tbs_07.f'; SET NEWNAME FOR DATAFILE 8 TO '$ORACLE_HOME/dbs/tbs_08.f'; SET NEWNAME FOR DATAFILE 9 TO '$ORACLE_HOME/dbs/tbs_09.f'; DUPLICATE TARGET DATABASE TO dupdb LOGFILE GROUP 1 ('$ORACLE_HOME/dbs/log_1_1.f', '$ORACLE_HOME/dbs/log_1_2.f') SIZE 200K REUSE, GROUP 2 ('$ORACLE_HOME/dbs/log_2_1.f', '$ORACLE_HOME/dbs/log_2_2.f') SIZE 200K REUSE; }
This example makes the same assumptions as in "Setting New Filenames Manually: Example". Additionally, it assumes that you want to update the duplicate database daily so that it stays current with the target database.
# start RMAN and then connect to the databases CONNECT TARGET / CONNECT CATALOG rman/rman@rcat CONNECT AUXILIARY sys/change_on_install@dupdb # configure auxiliary names for the datafiles only once CONFIGURE AUXNAME FOR DATAFILE 1 TO '$ORACLE_HOME/dbs/tbs_01.f'; CONFIGURE AUXNAME FOR DATAFILE 2 TO '$ORACLE_HOME/dbs/tbs_02.f'; CONFIGURE AUXNAME FOR DATAFILE 3 TO '$ORACLE_HOME/dbs/tbs_03.f'; CONFIGURE AUXNAME FOR DATAFILE 4 TO '$ORACLE_HOME/dbs/tbs_04.f'; CONFIGURE AUXNAME FOR DATAFILE 5 TO '$ORACLE_HOME/dbs/tbs_05.f'; CONFIGURE AUXNAME FOR DATAFILE 6 TO '$ORACLE_HOME/dbs/tbs_06.f'; CONFIGURE AUXNAME FOR DATAFILE 7 TO '$ORACLE_HOME/dbs/tbs_07.f'; CONFIGURE AUXNAME FOR DATAFILE 8 TO '$ORACLE_HOME/dbs/tbs_08.f'; CONFIGURE AUXNAME FOR DATAFILE 9 TO '$ORACLE_HOME/dbs/tbs_09.f'; # Create the duplicate database. Issue the same command daily # to re-create the database, thereby keeping the duplicate # in sync with the target. DUPLICATE TARGET DATABASE TO dupdb LOGFILE GROUP 1 ('$ORACLE_HOME/dbs/log_1_1.f', '$ORACLE_HOME/dbs/log_1_2.f') SIZE 200K REUSE, GROUP 2 ('$ORACLE_HOME/dbs/log_2_1.f', '$ORACLE_HOME/dbs/log_2_2.f') SIZE 200K REUSE;
This duplication example assumes the following:
prod1
and duplicate database dupdb
are on different hosts but have exactly the same directory structure.
prod1
as it appeared at that time.
CONNECT TARGET sys/change_on_install@prod1 CONNECT AUXILIARY sys/sysdba@dupdb RUN { SET UNTIL TIME 'SYSDATE-7'; ALLOCATE AUXILIARY CHANNEL dupdb1 DEVICE TYPE sbt; DUPLICATE TARGET DATABASE TO dupdb NOFILENAMECHECK; }
If you use a client-side initialization parameter file to start the auxiliary instance, then it must reside on the same host as the RMAN executable used to perform the duplication. Assume the following scenario:
host_tar
and the Oracle home is /oracle/version/8.1.6.0.0
.
host_dup
and the Oracle home is /oracle_tests/version/8.1.7.0.0
.
host_dup
has the filename $ORACLE_HOME/dbs/init_test.ora
.
host_dup
and host_tar
are linked by a network.
In this scenario, you can run the RMAN executable (that is, run the DUPLICATE
command in an RMAN session) either on host_tar
or host_dup
.
If you run the executable on host_dup
, you can duplicate the database as follows:
DUPLICATE DEVICE TYPE sbt TARGET DATABASE TO dupdb PFILE='$ORACLE_HOME/dbs/init_test.ora';
Because the initialization parameter file used by the auxiliary instance resides on the same node as the RMAN executable, you can simply reference the filename of the parameter file.
In this scenario, the client-side initialization parameter file is not located on the same node as the RMAN executable. Hence, you have to do one of the following:
host_dup
to host_tar
.
host_dup
directory containing the parameter file on the host_tar
file system.
In this scenario, you manually copy the file from one host to another and then connect to the databases as follows:
% cp /net/host_dup/oracle_tests/version/8.1.7.0.0/dbs/init_test.ora \ > /net/host_tar/oracle/versions/8.1.6.0.0/dbs % rman RMAN> CONNECT TARGET sys/change_on_install@prod1 RMAN> CONNECT AUXILIARY sys/sysdba@dupdb
Then, you perform the duplication as follows:
DUPLICATE DEVICE TYPE sbt TARGET DATABASE TO dupdb PFILE='$ORACLE_HOME/dbs/init_test.ora';
In this scenario, you mount the host_dup
file system on the host_tar
file system by using /tmp
as the mount point. The /tmp/init_test.ora
filename on host_tar
points to the init_test.ora
file residing on host_dup
. Then, you can run the duplication as follows:
DUPLICATE DEVICE TYPE sbt TARGET DATABASE TO dupdb PFILE='/tmp/init_test.ora';
|
![]() Copyright © 1996-2001, Oracle Corporation. All Rights Reserved. |
|