Monday, September 16, 2013

Creating a Duplicate database from Active Database ( Without RMAN backup) on Same Server

This example below demonstrates on how to create a duplicate database on same server.

Pre-Requisites:
1) Create tns entry for auxiliary database ( I created for both target and auxiliary)
2) Create a password file for auxiliary (SYS password should be same for both target and auxiliary).
     If it's different, It failed.
3) Create a pfile for auxiliary instance and create necessary directory structure.

Sample Pfile:

db_name=dupdb
memory_target=1G
audit_file_dest=/u01/app/oracle/admin/dupdb/adump
audit_trail='db'
db_block_size=8192
db_domain=""
diagnostic_dest=/u01/app/oracle
dispatchers='(PROTOCOL=TCP)(SERVICE=ORA11XDB)'
open_cursors=300
undo_tablespace='UNDOTBS1'
control_files=/u02/oradata/dupdb/control01.ctl
compatible='11.1.0'
log_archive_dest='/u02/oradata/dupdb/archive/'
remote_login_passwordfile=exclusive
db_create_file_dest='/u02/oradata/dupdb' --> This is important to create datafiles.





Start the auxiliart instance into nomount mode

Connected from target database

[oracle@asus001n1 dbs]$ rman target sys/oracle@FIRSTDB auxiliary sys/oracle@dupdb

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Sep 16 22:54:22 2013

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

connected to target database: FIRSTDB (DBID=620399556)
connected to auxiliary database: DUPDB (not mounted)

RMAN> duplicate target database to dupdb from active database;

Starting Duplicate Db at 16-SEP-13
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=91 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    1068937216 bytes

Fixed Size                     2220200 bytes
Variable Size                620760920 bytes
Database Buffers             440401920 bytes
Redo Buffers                   5554176 bytes

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

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2220200 bytes
Variable Size                620760920 bytes
Database Buffers             440401920 bytes
Redo Buffers                   5554176 bytes

Starting backup at 16-SEP-13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=173 device type=DISK
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/snapcf_FIRSTDB.f tag=TAG20130916T225443 RECID=2 STAMP=826325683
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 16-SEP-13

database mounted

contents of Memory Script:
{
   set newname for clone datafile  1 to new;
   set newname for clone datafile  2 to new;
   set newname for clone datafile  3 to new;
   set newname for clone datafile  4 to new;
   set newname for clone datafile  5 to new;
   set newname for clone datafile  6 to new;
   backup as copy reuse
   datafile  1 auxiliary format new
   datafile  2 auxiliary format new
   datafile  3 auxiliary format new
   datafile  4 auxiliary format new
   datafile  5 auxiliary format new
   datafile  6 auxiliary format new
   ;
   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 16-SEP-13
using channel ORA_DISK_1
RMAN-06554: WARNING: file 1 is in backup mode
RMAN-06554: WARNING: file 2 is in backup mode
RMAN-06554: WARNING: file 3 is in backup mode
RMAN-06554: WARNING: file 4 is in backup mode
RMAN-06554: WARNING: file 5 is in backup mode
RMAN-06554: WARNING: file 6 is in backup mode
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u02/oradata/sysaux01.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_sysaux_08ok1elo_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u02/oradata/users01.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_09ok1enp_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u02/oradata/users02.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_0aok1eo9_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u02/oradata/system01.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_system_0bok1ep2_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u02/oradata/undotbs01.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_undotbs1_0cok1eph_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u02/oradata/usersindx01.dbf
output file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_usersind_0dok1epo_.dbf tag=TAG20130916T225448
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01
Finished backup at 16-SEP-13

sql statement: alter system archive log current

contents of Memory Script:
{
   backup as copy reuse
   archivelog like  "/u02/oradata/archive/1_8_826060964.dbf" auxiliary format
 "/u02/oradata/dupdb/archive/1_8_826060964.dbf"   ;
   catalog clone archivelog  "/u02/oradata/dupdb/archive/1_8_826060964.dbf";
   switch clone datafile all;
}
executing Memory Script

Starting backup at 16-SEP-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=8 RECID=46 STAMP=826325818
output file name=/u02/oradata/dupdb/archive/1_8_826060964.dbf RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01
Finished backup at 16-SEP-13

cataloged archived log
archived log file name=/u02/oradata/dupdb/archive/1_8_826060964.dbf RECID=46 STAMP=826325819

datafile 1 switched to datafile copy
input datafile copy RECID=2 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_system_0bok1ep2_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=3 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_sysaux_08ok1elo_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=4 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_undotbs1_0cok1eph_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=5 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_09ok1enp_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=6 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_0aok1eo9_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=7 STAMP=826325819 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_usersind_0dok1epo_.dbf

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

executing command: SET until clause

Starting recover at 16-SEP-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=47 device type=DISK

starting media recovery

archived log for thread 1 with sequence 6 is already on disk as file /u02/oradata/archive/1_6_826060964.dbf
archived log for thread 1 with sequence 7 is already on disk as file /u02/oradata/archive/1_7_826060964.dbf
archived log for thread 1 with sequence 8 is already on disk as file /u02/oradata/dupdb/archive/1_8_826060964.dbf
archived log file name=/u02/oradata/archive/1_6_826060964.dbf thread=1 sequence=6
archived log file name=/u02/oradata/archive/1_7_826060964.dbf thread=1 sequence=7
archived log file name=/u02/oradata/dupdb/archive/1_8_826060964.dbf thread=1 sequence=8
media recovery complete, elapsed time: 00:00:01
Finished recover at 16-SEP-13

contents of Memory Script:
{
   shutdown clone immediate;
   startup clone nomount;
   sql clone "alter system set  db_name =
 ''DUPDB'' 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

database dismounted
Oracle instance shut down

connected to auxiliary database (not started)
Oracle instance started

Total System Global Area    1068937216 bytes

Fixed Size                     2220200 bytes
Variable Size                620760920 bytes
Database Buffers             440401920 bytes
Redo Buffers                   5554176 bytes

sql statement: alter system set  db_name =  ''DUPDB'' 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    1068937216 bytes

Fixed Size                     2220200 bytes
Variable Size                620760920 bytes
Database Buffers             440401920 bytes
Redo Buffers                   5554176 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "DUPDB" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      2
  MAXDATAFILES       30
  MAXINSTANCES     1
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1  SIZE 50 M ,
  GROUP  2  SIZE 50 M ,
  GROUP  3  SIZE 50 M
 DATAFILE
  '/u02/oradata/dupdb/DUPDB/datafile/o1_mf_system_0bok1ep2_.dbf'
 CHARACTER SET AL32UTF8


contents of Memory Script:
{
   set newname for clone tempfile  1 to new;
   set newname for clone tempfile  2 to new;
   switch clone tempfile all;
   catalog clone datafilecopy  "/u02/oradata/dupdb/DUPDB/datafile/o1_mf_sysaux_08ok1elo_.dbf",
 "/u02/oradata/dupdb/DUPDB/datafile/o1_mf_undotbs1_0cok1eph_.dbf",
 "/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_09ok1enp_.dbf",
 "/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_0aok1eo9_.dbf",
 "/u02/oradata/dupdb/DUPDB/datafile/o1_mf_usersind_0dok1epo_.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

executing command: SET NEWNAME

renamed tempfile 1 to /u02/oradata/dupdb/DUPDB/datafile/o1_mf_temp_%u_.tmp in control file
renamed tempfile 2 to /u02/oradata/dupdb/DUPDB/datafile/o1_mf_temp_%u_.tmp in control file

cataloged datafile copy
datafile copy file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_sysaux_08ok1elo_.dbf RECID=1 STAMP=826325834
cataloged datafile copy
datafile copy file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_undotbs1_0cok1eph_.dbf RECID=2 STAMP=826325834
cataloged datafile copy
datafile copy file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_09ok1enp_.dbf RECID=3 STAMP=826325834
cataloged datafile copy
datafile copy file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_0aok1eo9_.dbf RECID=4 STAMP=826325834
cataloged datafile copy
datafile copy file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_usersind_0dok1epo_.dbf RECID=5 STAMP=826325834

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=826325834 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_sysaux_08ok1elo_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=826325834 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_undotbs1_0cok1eph_.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=826325834 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_09ok1enp_.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=826325834 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_users_0aok1eo9_.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=826325834 file name=/u02/oradata/dupdb/DUPDB/datafile/o1_mf_usersind_0dok1epo_.dbf

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

database opened
Finished Duplicate Db at 16-SEP-13

No comments:

Post a Comment