• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

RMAN ‘Duplicate From Active Database’ Feature in Oracle 11g

by admin

You can create a duplicate database using the RMAN duplicate command. The duplicate database has a different DBID from the source database and functions entirely independently.Starting from 11g you can do duplicate database in 2 ways.

  1. Active database duplication
  2. Backup-based duplication

Active database duplication copies the live target database over the network to the auxiliary destination and then creates the duplicate database. The only difference is that 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:

  1. Creates a control file for the duplicate database
  2. Restarts the auxiliary instance and mounts the duplicate control file
  3. Creates the duplicate datafiles and recovers them with incremental backups and archived redo logs.
  4. Opens the duplicate database with the RESETLOGS option

For the active database duplication, RMAN does one extra step .i.e. copy the target database datafiles over the network to the auxiliary instance

A RAC TARGET database can be duplicated as well. The procedure is the same as below. If the auxiliary instance needs to be a RAC-database as well, then start the duplicate procedure for to a single instance and convert the auxiliary to RAC after the duplicate has succeeded.

Basic Steps to ACTIVE database duplication

1. Preparing the auxiliary instance:

1. Creating initialization Parameter file for the Auxiliary instance.
If you are using SPFILE then the 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 technique, then you need to set initialization parameters to set in the initialization parameter file. Required parameters are:

DB_NAME 
CONTROL_FILES
DB_BLOCK_SIZE
DB_FILE_NAME_CONVERT
LOG_FILE_NAME_CONVERT
DB_RECOVERY_FILE_DEST

In this post for simplicity we are specifying all the required parameters in the pfile. For example:

# cat initTEST.ora
DB_NAME=TEST 
diagnostic_dest='E:\oracle' 
DB_FILE_name_CONVERT=('I:\app\apadhi\oradata\amar','E:\oracle\oradata\test') 
LOG_FILE_NAME_CONVERT=( 'I:\app\apadhi\oradata\amar','E:\oracle\oradata\test')
SGA_TARGET=262144000 
CONTROL_FILES='E:\oracle\oradata\TEST\control01.dbf' 
COMPATIBLE= 11.1.0.0.0

2. Create an Oracle Password File for the Auxiliary Instance.
The password file is must for the Active database duplication. A password file 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 the target database. In case you are using password file make sure to have same SYSDBA password as the target database. Also, you can specify the PASSWORD FILE option on the DUPLICATE command. In this case, RMAN copies the source database password file to the destination host and overwrites any existing password file for the auxiliary instance.

In this post, we are using password file option in the duplicate command.

Create the database service (only for windows) and password file. For example:

% set ORACLE_SID=TEST
% set ORACLE_HOME=E:\oracle\product\11.1.0\db_1
% oradim -NEW -SID TEST
% orapwd FILE=E:\oracle\product\11.1.0\db_1\database\PWDTEST.ora PASSWORD=sys

For Unix/Linux the service is not needed, only the password file.

3. Start the Auxiliary instance in NOMOUNT. For example:

% sqlplus / as sysdba 

SQL*Plus: Release 11.1.0.6.0 - Production on Wed Aug 1 20:33:30 2007 

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

Connected to an idle instance. 

SQL> startup NOMOUNT pfile=E:\oracle\product\11.1.0\db_1\database\initTEST.ora 
ORACLE instance started. 

Total System Global Area  150667264 bytes 
Fixed Size                  1331732 bytes 
Variable Size              92278252 bytes 
Database Buffers           50331648 bytes 
Redo Buffers                6725632 bytes 
SQL> exit 

2. Create the necessary oracle NET connectivity.

1. Insert a static entry for the auxiliary in the listener.ora file on the auxiliary server. In addition, tnsnames.ora entry is needed in both target and auxiliary. For example:

Listener.ora (on the AUXILIARY host)

SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (GLOBAL_DBNAME = TEST) 
      (ORACLE_HOME = E:\oracle\product\11.1.0\db_1) 
      (SID_NAME = TEST) 
    ) 
  )


LISTENER = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = apadhi-idc)(PORT = 1521)) 
  )

tnsname.ora (In the TARGET and AUXILIARY host)

## For the Auxiliary database TEST ##TEST = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = apadhi-idc)(PORT = 1521)) 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = TEST) 
    ) 
  ) 

## For the target database AMAR ##
AMAR = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST = 152.69.210.76)(PORT = 1521)) 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = AMAR) 
    ) 
  )## Similary add entry for the catalog database ( Optional) 

2. Check connectivity between target and auxiliary instances:
Execute on the TARGET and AUXILIARY host

% tnsping AMAR
% tnsping TEST

3. Start RMAN and Connect to the Database Instances

Start RMAN and connect to the source database as TARGET, the duplicate database instance as AUXILIARY, and, if applicable, the recovery catalog database. You can start the RMAN client on any host so long as it can connect to all of the database instances. If the auxiliary instance requires a text-based initialization parameter file, then this file must exist on the same host that runs the RMAN client application.

In this post we are doing duplicate database from the auxiliary server. Look at the example:

% rman 

Recovery Manager: Release 11.1.0.6.0 - Production on Wed Aug 1 21:06:49 2007 
Copyright (c) 1982, 2007, Oracle. All rights reserved. 

RMAN> connect TARGET sys / sys @ AMAR;   ## Target database ##
connected to target database: AMAR (DBID=1450838187) 

RMAN> connect AUXILIARY sys / sys @ TEST ;  ## Auxiliary database ##
connected to auxiliary database: TEST (not mounted) 

RMAN> connect CATALOG rman / rman @ CAT ; ## Catalog database .Optional ## 
connected to recovery catalog database

4. Run the DUPLICATE database command:

The simplest case is to use active database duplication to duplicate the database to a different host and use the different directory structure.Look at the example :

This example assumes the following:

  • Using a recovery catalog.
  • The target database is on host1 and contains 4 datafiles.
  • Duplicate the target to database TEST on the different host having different file structure.
  • Tablespace USERS in target is read-only tablespace.
  • Running duplicate database from the Auxiliary site.
RMAN> DUPLICATE TARGET DATABASE  
      TO 'TEST' 
      FROM ACTIVE DATABASE 
      DB_FILE_NAME_CONVERT 'I:\app\apadhi\oradata\amar','E:\oracle\oradata\test';

And this is what is going on:

Starting Duplicate Db at 02-AUG-07 
using target database control file instead of recovery catalog 
allocated channel: ORA_AUX_DISK_1 
channel ORA_AUX_DISK_1: SID=97 device type=DISK 

contents of Memory Script: 
{ 
   set newname for datafile  1 to "E:\ORACLE\ORADATA\TEST\SYSTEM01.DBF"; 
   set newname for datafile  2 to "E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF"; 
   set newname for datafile  3 to "E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF"; 
   set newname for datafile  4 to "E:\ORACLE\ORADATA\TEST\USERS01.DBF"; 
   backup as copy reuse 
   datafile  1 auxiliary format  "E:\ORACLE\ORADATA\TEST\SYSTEM01.DBF"   
   datafile  2 auxiliary format  "E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF"   
   datafile  3 auxiliary format  "E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF"   
   datafile  4 auxiliary format  "E:\ORACLE\ORADATA\TEST\USERS01.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 

Starting backup at 02-AUG-07 
allocated channel: ORA_DISK_1 
channel ORA_DISK_1: SID=123 device type=DISK 
channel ORA_DISK_1: starting datafile copy 
input datafile file number=00001 name=I:\APP\APADHI\ORADATA\AMAR\SYSTEM01.DBF 
output file name=E:\ORACLE\ORADATA\TEST\SYSTEM01.DBF tag=TAG20070802T114254 RECID=0 STAMP=0 
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:08:22 
channel ORA_DISK_1: starting datafile copy 
input datafile file number=00002 name=I:\APP\APADHI\ORADATA\AMAR\SYSAUX01.DBF 
output file name=E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF tag=TAG20070802T114254 RECID=0 STAMP=0 
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:05:59 
channel ORA_DISK_1: starting datafile copy 
input datafile file number=00003 name=I:\APP\APADHI\ORADATA\AMAR\UNDOTBS01.DBF 
output file name=E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF tag=TAG20070802T114254 RECID=0 STAMP=0 
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:02:57 
channel ORA_DISK_1: starting datafile copy 
input datafile file number=00004 name=I:\APP\APADHI\ORADATA\AMAR\USERS01.DBF 
output file name=E:\ORACLE\ORADATA\TEST\USERS01.DBF tag=TAG20070802T114254 RECID=0 STAMP=0 
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15 
Finished backup at 02-AUG-07 

sql statement: alter system archive log current 
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST" RESETLOGS ARCHIVELOG  
  MAXLOGFILES     16 
  MAXLOGMEMBERS      3 
  MAXDATAFILES      100 
  MAXINSTANCES     8 
  MAXLOGHISTORY      292 
 LOGFILE 
  GROUP  1 ( 'E:\ORACLE\ORADATA\TEST\REDO01.LOG' ) SIZE 50 M  REUSE, 
  GROUP  2 ( 'E:\ORACLE\ORADATA\TEST\REDO02.LOG' ) SIZE 50 M  REUSE, 
  GROUP  3 ( 'E:\ORACLE\ORADATA\TEST\REDO03.LOG' ) SIZE 50 M  REUSE 
 DATAFILE 
  'E:\ORACLE\ORADATA\TEST\SYSTEM01.DBF' 
 CHARACTER SET AL32UTF8 

contents of Memory Script: 
{ 
   backup as copy reuse 
   archivelog like  "I:\APP\APADHI\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001" auxiliary format  
 "E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001"   archivelog like  
 "I:\APP\APADHI\FLASH_RECOVERY_AREA\AMAR\ARCHIVELOG\2007_08_02\O1_MF_1_42_3C2YJNP7_.ARC" auxiliary format  
 "E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001"   ; 
   catalog clone archivelog  "E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001"; 
   catalog clone archivelog  "E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001"; 
   switch clone datafile all; 
} 
executing Memory Script 

Starting backup at 02-AUG-07 
using channel ORA_DISK_1 
channel ORA_DISK_1: starting archived log copy 
input archived log thread=1 sequence=42 RECID=35 STAMP=629553646 
output file name=E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 RECID=0 STAMP=0 
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01 
channel ORA_DISK_1: starting archived log copy 
input archived log thread=1 sequence=42 RECID=36 STAMP=629553646 
output file name=E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 RECID=0 STAMP=0 
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01 
Finished backup at 02-AUG-07 

cataloged archived log 
archived log file name=E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 RECID=1 STAMP=629553800 

cataloged archived log 
archived log file name=E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 RECID=2 STAMP=629553800 

datafile 2 switched to datafile copy 
input datafile copy RECID=1 STAMP=629553800 file name=E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF 
datafile 3 switched to datafile copy 
input datafile copy RECID=2 STAMP=629553801 file name=E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF 

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

executing command: SET until clause 

Starting recover at 02-AUG-07 
using channel ORA_AUX_DISK_1 
datafile 4 not processed because file is read-only 

starting media recovery 

archived log for thread 1 with sequence 42 is already on disk as file E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 
archived log file name=E:\ORACLE\PRODUCT\11.1.0\DB_1\RDBMS\ARC00042_0629061547.001 thread=1 sequence=42 
media recovery complete, elapsed time: 00:00:01 
Finished recover at 02-AUG-07 

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

database dismounted 
Oracle instance shut down 

connected to auxiliary database (not started) 
Oracle instance started 

Total System Global Area     263639040 bytes 

Fixed Size                     1332544 bytes 
Variable Size                 83888832 bytes 
Database Buffers             171966464 bytes 
Redo Buffers                   6451200 bytes 
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "TEST" RESETLOGS ARCHIVELOG  
  MAXLOGFILES     16 
  MAXLOGMEMBERS      3 
  MAXDATAFILES      100 
  MAXINSTANCES     8 
  MAXLOGHISTORY      292 
 LOGFILE 
  GROUP  1 ( 'E:\ORACLE\ORADATA\TEST\REDO01.LOG' ) SIZE 50 M  REUSE, 
  GROUP  2 ( 'E:\ORACLE\ORADATA\TEST\REDO02.LOG' ) SIZE 50 M  REUSE, 
  GROUP  3 ( 'E:\ORACLE\ORADATA\TEST\REDO03.LOG' ) SIZE 50 M  REUSE 
 DATAFILE 
  'E:\ORACLE\ORADATA\TEST\SYSTEM01.DBF' 
 CHARACTER SET AL32UTF8 


contents of Memory Script: 
{ 
   set newname for tempfile  1 to  
 "E:\ORACLE\ORADATA\TEST\TEMP01.DBF"; 
   switch clone tempfile all; 
   catalog clone datafilecopy  "E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF"; 
   catalog clone datafilecopy  "E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF"; 
   switch clone datafile all; 
} 
executing Memory Script 

executing command: SET NEWNAME 

renamed tempfile 1 to E:\ORACLE\ORADATA\TEST\TEMP01.DBF in control file 

cataloged datafile copy 
datafile copy file name=E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF RECID=1 STAMP=629553825 

cataloged datafile copy 
datafile copy file name=E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF RECID=2 STAMP=629553826 

datafile 2 switched to datafile copy 
input datafile copy RECID=1 STAMP=629553825 file name=E:\ORACLE\ORADATA\TEST\SYSAUX01.DBF 
datafile 3 switched to datafile copy 
input datafile copy RECID=2 STAMP=629553826 file name=E:\ORACLE\ORADATA\TEST\UNDOTBS01.DBF 

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

database opened 

contents of Memory Script: 
{ 
   catalog clone datafilecopy  "E:\ORACLE\ORADATA\TEST\USERS01.DBF"; 
   switch clone datafile  4 to datafilecopy  "E:\ORACLE\ORADATA\TEST\USERS01.DBF"; 
#online the readonly tablespace 
sql clone "alter tablespace  USERS online"; 
} 
executing Memory Script 

cataloged datafile copy 
datafile copy file name=E:\ORACLE\ORADATA\TEST\USERS01.DBF RECID=3 STAMP=629553870 

datafile 4 switched to datafile copy 
input datafile copy RECID=3 STAMP=629553870 file name=E:\ORACLE\ORADATA\TEST\USERS01.DBF 

sql statement: alter tablespace  USERS online 
Finished Duplicate Db at 02-AUG-07

Filed Under: oracle, Oracle 11g

Some more articles you might also be interested in …

  1. How to Clone a Pluggable Database from an RMAN Container Database Backup
  2. How to list all the named events set for a database
  3. How to Rename the Default JSESSIONID in WebLogic
  4. Oracle ASM 11gR2 instance is unable to start due to missing ASM spfile
  5. Extend rule sets by using factors in Oracle Database Vault
  6. How to find redo log members/redo log file size/redo log status
  7. How to change max_string_size value from STANDARD to EXTENDED
  8. How To Setup UDEV Rules For RAC OCR And Voting Devices on Partitions
  9. How to Restore ASM Based OCR After Complete Loss of the CRS Diskgroup on Linux/UNIX
  10. How to Change SYS and SYSTEM Passwords in Oracle Database

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright