Search This Blog

Wednesday, September 7, 2011

Clone Database on 11g with Duplicate RMAN on same host

Clone database of PRODUCATION on same host is a quite frequent to do task of DBA's.
Use the following simple step to achieve the same.
Step:
1. backup source database through RMAN
2. create needful administration directories (like ORADATA)
3. create init parameter file for duplicate database (using any text editor create the init.ora file)
4. create oracle services via oradim utility
5. create password file for duplicate database via ORAPWD utility
6. configure tns entry for source and target database
7. startup duplicate database in nomount mode with the help of init.ora file
8. connect rman client with target and auxiliary database
9. execute duplicate database command
10. You have done it successfully.
11. create the SPFILE for duplicate database.
12. take backup of duplicate database (optional)


OS: WINDOWS 2003
SOURCE DB: ORG
TARGET DB: DUP


NOTE: 1. FLASH RECOVERY AREA IS NOT CONFIGURED SO BACKUP WILL STORE IN THE %ORACLE_HOME%/database folder
2. OEM is not configured. (FYI)



1. backup source database through RMAN

CMD> set oracle_sid=org
CMD> rman target sys
password: xxxxxxx


RMAN> backup database plus archivelog;




2. create needful administration directories (like ORADATA)
In the 11g , you just need to create directories for ORADATA


3. create init parameter file for duplicate database (using any text editor create the init.ora file)
The following parameter is required. (mandatory)

DB_NAME=dup
control_files=D:\APP\ADMINISTRATOR\ORADATA\dup\CONTROL01.CTL, D:\APP\ADMINISTRATOR\ORADATA\dup\CONTROL02.CTL
db_block_size=8192
db_file_name_convert='D:\app\Administrator\oradata\org','D:\app\Administrator\oradata\dup'
LOG_file_name_convert='D:\app\Administrator\oradata\org','D:\app\Administrator\oradata\dup'





4. create oracle services via oradim utility
CMD>ORADIM -NEW -SID DUP -STARTMODE manual




5. create password file for duplicate database via ORAPWD utility
CMD>ORAPWD FILE=%ORACLE_HOME%\database\pwddup.ora password=oracle




6. configure tns entry for source and target database

ORG =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.1.4.78)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = org)
    )
  )


7. startup duplicate database in nomount mode with the help of init.ora file
CMD> set oracle_sid=dup
CMD> sqlplus sys/oracle as sysdba
SQL> startup nomount pfile='c:\init_dup.ora' -- my pfile is located under c: drive




8. connect rman client with target and auxiliary database
CMD> rman target sys@org auxiliary sys 
NOTE: i used tns entry to connect to source database and auxiliary database at same time.




9. execute duplicate database command

C:\>rman target sys@org  auxiliary sys


Recovery Manager: Release 11.2.0.2.0 - Production on Wed Sep 7 12:16:14 2011


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


target database Password:
connected to target database: ORG (DBID=1479245426)
auxiliary database Password:
connected to auxiliary database: DUP (not mounted)


RMAN> run
2> {
3> set until sequence 4 thread 1;
4> duplicate target database to dup;
5> }


executing command: SET until clause


Starting Duplicate Db at 07-SEP-11
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=96 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     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes


contents of Memory Script:
{
   set until scn  769666;
   sql clone "alter system set  db_name =
 ''ORG'' 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
   restore clone primary controlfile;
   alter clone database mount;
}
executing Memory Script


executing command: SET until clause


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


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


Oracle instance shut down


Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes


Starting restore at 07-SEP-11
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=95 device type=DISK


channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\ADMINISTRATOR\11.2.0\DB
\DATABASE\03MLUO8R_1_1
channel ORA_AUX_DISK_1: piece handle=D:\APP\ADMINISTRATOR\11.2.0\DB\DATABASE\03M
LUO8R_1_1 tag=TAG20110907T113023
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:03
output file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\CONTROL01.CTL
output file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\CONTROL02.CTL
Finished restore at 07-SEP-11


database mounted


contents of Memory Script:
{
   set until scn  769666;
   set newname for datafile  1 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSTEM01.DBF";
   set newname for datafile  2 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF";
   set newname for datafile  3 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF";
   set newname for datafile  4 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF";
   restore
   clone database
   ;
}
executing Memory Script


executing command: SET until clause


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


executing command: SET NEWNAME


Starting restore at 07-SEP-11
using channel ORA_AUX_DISK_1


channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\SYSTEM01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00002 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\SYSAUX01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00003 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\UNDOTBS01.DBF
channel ORA_AUX_DISK_1: restoring datafile 00004 to D:\APP\ADMINISTRATOR\ORADATA
\DUP\USERS01.DBF
channel ORA_AUX_DISK_1: reading from backup piece D:\APP\ADMINISTRATOR\11.2.0\DB
\DATABASE\02MLUO6F_1_1
channel ORA_AUX_DISK_1: piece handle=D:\APP\ADMINISTRATOR\11.2.0\DB\DATABASE\02M
LUO6F_1_1 tag=TAG20110907T113023
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:15
Finished restore at 07-SEP-11


contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script


datafile 1 switched to datafile copy
input datafile copy RECID=5 STAMP=761228440 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSTEM01.DBF
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=7 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\UNDOTBS01.DBF
datafile 4 switched to datafile copy
input datafile copy RECID=8 STAMP=761228441 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\USERS01.DBF


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


executing command: SET until clause


Starting recover at 07-SEP-11
using channel ORA_AUX_DISK_1


starting media recovery


archived log for thread 1 with sequence 3 is already on disk as file C:\ARCH\ARC
0000000003_0761225013.0001
archived log file name=C:\ARCH\ARC0000000003_0761225013.0001 thread=1 sequence=3


media recovery complete, elapsed time: 00:00:02
Finished recover at 07-SEP-11
Oracle instance started


Total System Global Area     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 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     150667264 bytes


Fixed Size                     1382112 bytes
Variable Size                 92277024 bytes
Database Buffers              50331648 bytes
Redo Buffers                   6676480 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUP" RESETLOGS ARCHIVELOG


  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO01.LOG' ) SIZE 50 M  REUSE,
  GROUP  2 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO02.LOG' ) SIZE 50 M  REUSE,
  GROUP  3 ( 'D:\APP\ADMINISTRATOR\ORADATA\DUP\REDO03.LOG' ) SIZE 50 M  REUSE
 DATAFILE
  'D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSTEM01.DBF'
 CHARACTER SET WE8MSWIN1252




contents of Memory Script:
{
   set newname for tempfile  1 to
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\TEMP01.DBF";
   switch clone tempfile all;
   catalog clone datafilecopy  "D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF",


 "D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF",
 "D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF";
   switch clone datafile all;
}
executing Memory Script


executing command: SET NEWNAME


renamed tempfile 1 to D:\APP\ADMINISTRATOR\ORADATA\DUP\TEMP01.DBF in control fil
e


cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\SYSAUX01.DBF RECID=1 ST
AMP=761228527
cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\UNDOTBS01.DBF RECID=2 S
TAMP=761228527
cataloged datafile copy
datafile copy file name=D:\APP\ADMINISTRATOR\ORADATA\DUP\USERS01.DBF RECID=3 STA
MP=761228527


datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\SYSAUX01.DBF
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\UNDOTBS01.DBF
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=761228527 file name=D:\APP\ADMINISTRATOR\ORADA
TA\DUP\USERS01.DBF


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


database opened
Finished Duplicate Db at 07-SEP-11





10. You have done it successfully.

C:\>set oracle_sid=dup


C:\>sqlplus sys/oracle as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 7 12:22:53 2011


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
 132033645 DUP


SQL> conn sys@org/oracle as sysdba
Connected.
SQL> select dbid,name from v$database;


      DBID NAME
---------- ---------
1479245426 ORG


SQL> conn sys/oracle as sysdba
Connected.
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            D:\app\Administrator\11.2.0\db\RDBMS
Oldest online log sequence     1
Next log sequence to archive   1
Current log sequence           1
SQL>





11. create SPFILE for the duplicate database

C:\>set oracle_sid=dup


C:\>sqlplus sys/oracle as sysdba


SQL*Plus: Release 11.2.0.2.0 Production on Wed Sep 7 12:54:10 2011


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




Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


SQL> create spfile from pfile;
create spfile from pfile
*
ERROR at line 1:
ORA-32002: cannot create SPFILE already being used by the instance




SQL> --if you check physical then file is not exist becuase duplicate db
SQL> --started with clone spfile
SQL> --therefore shutdown the db and create spfile and start with spfile
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> create spfile from pfile='c:\init_dup.ora';


File created.


SQL> startup
ORACLE instance started.


Total System Global Area  150667264 bytes
Fixed Size                  1382112 bytes
Variable Size              92277024 bytes
Database Buffers           50331648 bytes
Redo Buffers                6676480 bytes
Database mounted.
Database opened.



12. take backup of duplicate database (optional)


write me email in case of any queries at askdbataj

4 comments:

Sukaina said...

Superb...

Sukaina

Mohammed Taj said...

Thank you.

Ramu said...

gr8 and nice examples.

Raj said...

Hi Mohammad Taj,
Im new to oracle, working as a jr dba...i was trying to practice cloning and came through your blog..I am stuck after creating all, unable to login to sql plus- getting TNS Protocol adapter error...
Can you guide me through ?