RMAN Duplicate database from Active database

I am started writing this blog after a long time, in which I will discuss about one of the Oracle 11g New features in Recovery Manager (RMAN).

From Oracle 11g, we create a duplicate database using the RMAN by two methods.

  • Active database duplication (Oracle 11g New Feature)
  • Backup-based duplication

Active database duplication copies the target database over the network to the destination and then creates the duplicate database. Only difference is you don’t need to have the pre-existing RMAN backups and copies. The duplication work is performed by an auxiliary channel. This channel corresponds to a server session on the auxiliary instance on the auxiliary host.

As part of the duplicating operation, RMAN automates the following steps:

  • Creates a control file for the duplicate database.
  • Restarts the auxiliary instance and mounts the duplicate control file.
  • Creates the duplicate data files and recovers them with incremental backups and archived redo logs.
  • Opens the duplicate database with the resetlogs option.

For the active database duplication, RMAN will copy the target database data files over the network to the auxiliary instance.

The Only Disadvantage is there will be a High traffic on your network connection between source and target database.

  • Creating initialization Parameter file for the Duplicate database

If you are using spfile then only parameter required for the duplicate database is DB_NAME. Rest other parameters can be set in the duplicate command itself. If you are not using the spfile , then you need to set initialization parameters in the pfile.

Required parameters:

DB_NAME
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT

We will create a pfile with the above parameters for the duplicate database.Create an Oracle Password File for the Duplicate database.

I will make the Duplicate database  name as  “DUP”

Password file is must for the Active database duplication where as it is not required for backup-based duplication. For Active database duplication it connects directly to the auxiliary instance using the password file with the same SYSDBA password as target database. In case you are using password file make sure to have same SYSDBA password as the target database. In this case, RMAN copies the source database password file to the destination host and overwrites any existing password file for the auxiliary instance.

cd $ORACLE_HOME/dbs

orapwd password=ORCL file=orapwDUP
  • Establish Oracle Net Connectivity to the Auxiliary Instance

Auxiliary instance must be available through Oracle Net if you are duplicating from an ACTIVE database.

Add following entries into listener.ora file.

Edit the listener.ora and add following lines:

SID_LIST_LISTENER =
 (SID_LIST =
 )
 (SID_DESC =
 (SID_NAME = dup)
 (ORACLE_HOME = =/home/oracle/app/oracle/product/11.2.0/dbhome_1)
 (GLOBAL_DBNAME = dup.localdomain)
 )
 )

Add the Following entry in the tnsnames.ora

prd =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = prd)
 )
 )

dup =
 (DESCRIPTION =
 (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
 (CONNECT_DATA =
 (SERVER = DEDICATED)
 (SERVICE_NAME = dup)
 )
 )
  • Create the directories which are required for the duplicate database.
mkdir -p /home/oracle/app/oracle/oradata/dup
mkdir -p /home/oracle/app/oracle/fast_recovery_area/dup
mkdir -p /home/oracle/app/oracle/admin/dup/pfile
  • Create the parameter file (initdup.ora).
DB_NAME=dup
diagnostic_dest='/home/oracle/app/oracle'
DB_FILE_name_CONVERT=('/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup')
LOG_FILE_NAME_CONVERT=('/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup')
Memory_TARGET=262144000
CONTROL_FILES='/home/oracle/app/oracle/oradata/dup/control01.dbf'
COMPATIBLE= 11.2.0.0.0
  • Start the Auxiliary instance from Sqlplus

Use SQL*Plus to connect to the auxiliary instance using the above created pfile and start it in NOMOUNT mode.

[oracle@localhost admin]$ export ORACLE_SID=dup
[oracle@localhost admin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Fri Mar 1 12:40:21 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount pfile=/home/oracle/app/oracle/admin/dup/pfile/initdup.ora
ORACLE instance started.

Total System Global Area 372449280 bytes
Fixed Size 1345044 bytes
Variable Size 234883564 bytes
Database Buffers 130023424 bytes
Redo Buffers 6197248 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 -
Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
  • Test connectivity to auxiliary and target instance from the Both Sides.
sqlplus sys/ORCL@PRD as sysdba

sqlplus sys/ORCL@DUP as sysdba
  • Using RMAN, Connect to the Database Instances
[oracle@localhost admin]$ rman target sys/ORCL@prd catalog rman/rman@prd

Recovery Manager: Release 11.2.0.3.0 - Production on Fri Mar 1 12:41:24 2013

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

connected to target database: PRD (DBID=1867953957)
connected to recovery catalog database

RMAN> connect auxiliary sys/ORCL@DUP

connected to auxiliary database: DUP (not mounted)

RMAN> DUPLICATE TARGET DATABASE TO 'DUP' FROM ACTIVE DATABASE
2> DB_FILE_NAME_CONVERT '/home/oracle/app/oracle/oradata/prd','/home/oracle/app/oracle/oradata/dup';

Starting Duplicate Db at 01-MAR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK

contents of Memory Script:
{
 sql clone "create spfile from memory";
}
executing Memory Script

sql statement: create spfile from memory

contents of Memory Script:
{
 shutdown clone immediate;
 startup clone nomount;
}
executing Memory Script

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

contents of Memory Script:
{
 sql clone "alter system set db_name =
 ''PRD'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
 sql clone "alter system set db_unique_name =
 ''DUP'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
 shutdown clone immediate;
 startup clone force nomount
 backup as copy current controlfile auxiliary format
'/home/oracle/app/oracle/oradata/dup/control01.ctl';
 alter clone database mount;
}
executing Memory Script

sql statement: alter system set db_name = ''PRD'' comment= ''Modified by
RMAN duplicate'' scope=spfile

sql statement: alter system set db_unique_name = ''DUP'' comment= ''Modified
by RMAN duplicate'' scope=spfile

Oracle instance shut down

Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

Starting backup at 01-MAR-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_prd.f
tag=TAG20130301T124259 RECID=9 STAMP=808922591
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:26
Finished backup at 01-MAR-13

database mounted

contents of Memory Script:
{
 set newname for datafile 1 to
 "/home/oracle/app/oracle/oradata/dup/system01.dbf";
 set newname for datafile 2 to
 "/home/oracle/app/oracle/oradata/dup/sysaux01.dbf";
 set newname for datafile 3 to
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf";
 set newname for datafile 4 to
 "/home/oracle/app/oracle/oradata/dup/users01.dbf";
 set newname for datafile 5 to
 "/home/oracle/app/oracle/oradata/dup/example01.dbf";
 set newname for datafile 6 to
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf";
 backup as copy reuse
 datafile 1 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/system01.dbf" datafile
 2 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/sysaux01.dbf" datafile
 3 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf" datafile
 4 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/users01.dbf" datafile
 5 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/example01.dbf" datafile
 6 auxiliary format
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf" ;
 sql 'alter system archive log current';
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

executing command: SET NEWNAME

Starting backup at 01-MAR-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001
name=/home/oracle/app/oracle/oradata/prd/system01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/system01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:06:38
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002
name=/home/oracle/app/oracle/oradata/prd/sysaux01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:06:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005
name=/home/oracle/app/oracle/oradata/prd/example01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/example01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:05:18
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003
name=/home/oracle/app/oracle/oradata/prd/undotbs01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006
name=/home/oracle/app/oracle/oradata/prd/rmantbs01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:04
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004
name=/home/oracle/app/oracle/oradata/prd/users01.dbf
output file name=/home/oracle/app/oracle/oradata/dup/users01.dbf
tag=TAG20130301T124336
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03
Finished backup at 01-MAR-13

sql statement: alter system archive log current

contents of Memory Script:
{
 backup as copy reuse
 archivelog like
"/home/oracle/app/oracle/fast_recovery_area/PRD/archivelog/2013_03_01/o1_mf_1_26_8m0pf583_.arc"
auxiliary format
 "/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf"
;
 catalog clone archivelog
"/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf";
 switch clone datafile all;
}
executing Memory Script

Starting backup at 01-MAR-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=26 RECID=26 STAMP=808923777
output file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:07
Finished backup at 01-MAR-13

cataloged archived log
archived log file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
RECID=26 STAMP=808923794

datafile 1 switched to datafile copy
input datafile copy RECID=9 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=10 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=11 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=12 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=13 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=14 STAMP=808923795 file
name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf

contents of Memory Script:
{
 set until scn 1134180;
 recover
 clone database
 delete archivelog
 ;
}
executing Memory Script

executing command: SET until clause

Starting recover at 01-MAR-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK

starting media recovery

archived log for thread 1 with sequence 26 is already on disk as file
/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
archived log file
name=/home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs/arch1_26_804290346.dbf
thread=1 sequence=26
media recovery complete, elapsed time: 00:00:02
Finished recover at 01-MAR-13
Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes

contents of Memory Script:
{
 sql clone "alter system set db_name =
 ''DUP'' comment=
 ''Reset to original value by RMAN'' scope=spfile";
 sql clone "alter system reset db_unique_name scope=spfile";
 shutdown clone immediate;
 startup clone nomount;
}
executing Memory Script

sql statement: alter system set db_name = ''DUP'' comment= ''Reset to
original value by RMAN'' scope=spfile

sql statement: alter system reset db_unique_name scope=spfile

Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area 372449280 bytes

Fixed Size 1345044 bytes
Variable Size 239077868 bytes
Database Buffers 125829120 bytes
Redo Buffers 6197248 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS
ARCHIVELOG
 MAXLOGFILES 16
 MAXLOGMEMBERS 3
 MAXDATAFILES 100
 MAXINSTANCES 8
 MAXLOGHISTORY 292
 LOGFILE
 GROUP 1 ( '/home/oracle/app/oracle/oradata/dup/redo01.log' ) SIZE 50 M
REUSE,
 GROUP 2 ( '/home/oracle/app/oracle/oradata/dup/redo02.log' ) SIZE 50 M
REUSE,
 GROUP 3 ( '/home/oracle/app/oracle/oradata/dup/redo03.log' ) SIZE 50 M
REUSE
 DATAFILE
 '/home/oracle/app/oracle/oradata/dup/system01.dbf'
 CHARACTER SET AL32UTF8
contents of Memory Script:
{
 set newname for tempfile 1 to
 "/home/oracle/app/oracle/oradata/dup/temp01.dbf";
 switch clone tempfile all;
 catalog clone datafilecopy
"/home/oracle/app/oracle/oradata/dup/sysaux01.dbf",
 "/home/oracle/app/oracle/oradata/dup/undotbs01.dbf",
 "/home/oracle/app/oracle/oradata/dup/users01.dbf",
 "/home/oracle/app/oracle/oradata/dup/example01.dbf",
 "/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf";
 switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /home/oracle/app/oracle/oradata/dup/temp01.dbf in
control file

cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
RECID=1 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
RECID=2 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/users01.dbf
RECID=3 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/example01.dbf
RECID=4 STAMP=808923861
cataloged datafile copy
datafile copy file name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf
RECID=5 STAMP=808923861

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/example01.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=808923861 file
name=/home/oracle/app/oracle/oradata/dup/rmantbs01.dbf

contents of Memory Script:
{
 Alter clone database open resetlogs;
}
executing Memory Script

database opened
Finished Duplicate Db at 01-MAR-13

Duplicate database is successfully created.

Advertisements

3 thoughts on “RMAN Duplicate database from Active database

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s