Google+ Followers

Pages

Monday, January 7, 2013

Duplicate Oracle database on the same server



BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

[root@linux ~]# su - oracle



[oracle@linux ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1
[oracle@linux ~]$ echo $ORACLE_SID
orcl1

[oracle@linux ~]$ echo $ORACLE_HOSTNAME
linux.ora.com

[oracle@linux ~]$ rlwrap rman target /

Recovery Manager: Release 11.2.0.2.0 - Production on Fri Jan 4 12:30:14 2013

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

connected to target database: ORCL1 (DBID=1188271317)

RMAN> backup database plus archivelog;


Starting backup at 04-JAN-13
current log archived
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=56 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=1 STAMP=803823530
input archived log thread=1 sequence=4 RECID=2 STAMP=803824222
channel ORA_DISK_1: starting piece 1 at 04-JAN-13
channel ORA_DISK_1: finished piece 1 at 04-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_annnn_TAG20130104T123023_8gf18hkm_.bkp tag=TAG20130104T123023 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 04-JAN-13

Starting backup at 04-JAN-13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl1/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl1/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl1/example01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl1/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl1/users01.dbf
channel ORA_DISK_1: starting piece 1 at 04-JAN-13
channel ORA_DISK_1: finished piece 1 at 04-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_nnndf_TAG20130104T123027_8gf18mmh_.bkp tag=TAG20130104T123027 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:08
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 04-JAN-13
channel ORA_DISK_1: finished piece 1 at 04-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_ncsnf_TAG20130104T123027_8gf1dph2_.bkp tag=TAG20130104T123027 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JAN-13

Starting backup at 04-JAN-13
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=5 RECID=3 STAMP=803824360
channel ORA_DISK_1: starting piece 1 at 04-JAN-13
channel ORA_DISK_1: finished piece 1 at 04-JAN-13
piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_annnn_TAG20130104T123240_8gf1drn4_.bkp tag=TAG20130104T123240 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 04-JAN-13

RMAN> exit


Recovery Manager complete.
[oracle@linux ~]$
[oracle@linux ~]$


Add second database information in listener.ora as following.


[oracle@linux ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
# Generated by Oracle configuration tools.

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (GLOBAL_DBNAME = orcl1)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl1)
    )
    (SID_DESC =
      (GLOBAL_DBNAME = orcl2)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1)
      (SID_NAME = orcl2)
    )
  )

LISTENER =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = linux.ora.com)(PORT = 1521))
  )

ADR_BASE_LISTENER = /u01/app/oracle

[oracle@linux ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 04-JAN-2013 12:33:17

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

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=linux.ora.com)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.2.0 - Production
Start Date                04-JAN-2013 11:47:24
Uptime                    0 days 0 hr. 45 min. 52 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/linux/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=linux.ora.com)(PORT=1521)))
Services Summary...
Service "orcl1" has 2 instance(s).
  Instance "orcl1", status UNKNOWN, has 1 handler(s) for this service...
  Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "orcl1XDB" has 1 instance(s).
  Instance "orcl1", status READY, has 1 handler(s) for this service...
Service "orcl2" has 1 instance(s).
  Instance "orcl2", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully

Add TNS Entry in TNSNAMES.ora

 [oracle@linux ~]$ cat /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.

ORCL2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl2)
    )
  )

ORCL1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = orcl1)
    )
  )



Create parameter file for ORCL2 database as follows.

[oracle@linux ~]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
 [oracle@linux dbs]$ cat  initorcl2.ora

db_name=orcl2
control_files='/u01/app/oracle/oradata/orcl2/control01.ctl'
db_file_name_convert='/u01/app/oracle/oradata/orcl1','/u01/app/oracle/oradata/orcl2'
log_file_name_convert='/u01/app/oracle/oradata/orcl1','/u01/app/oracle/oradata/orcl2'


create directories

[oracle@linux dbs]$ mkdir -p /u01/app/oracle/oradata/orcl2/
[oracle@linux dbs]$ mkdir -p /u01/app/oracle/fast_recovery_area/orcl2
[oracle@linux dbs]$ mkdir -p /u01/app/oracle/admin/orcl2/adump/
[oracle@linux dbs]$ mkdir -p /u01/app/oracle/diag/rdbms/orcl2/orcl2/trace/
[oracle@linux dbs]$ mkdir -p /u01/app/oracle/diag/rdbms/orcl2/orcl2/cdump/
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$


Create password file for ORCL2

[oracle@linux dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@linux dbs]$ orapwd file=orapworcl2 password=oracle ignorecase=y
[oracle@linux dbs]$ #cp orapworcl1  orapworcl2
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$ echo $ORACLE_SID
orcl1

now start ORCL2 in nomount state

[oracle@linux dbs]$ export ORACLE_SID=orcl2
[oracle@linux dbs]$ sqlplus

SQL*Plus: Release 11.2.0.2.0 Production on Fri Jan 4 12:53:07 2013

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

Enter user-name: / as sysdba
Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area  217157632 bytes
Fixed Size                  2225064 bytes
Variable Size             159386712 bytes
Database Buffers           50331648 bytes
Redo Buffers                5214208 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options



Start main (ORCL) database (if not already started)

[oracle@linux dbs]$
[oracle@linux dbs]$ export ORACLE_SID=orcl1
[oracle@linux dbs]$ sqlplus

SQL*Plus: Release 11.2.0.2.0 Production on Fri Jan 4 12:53:55 2013

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

Enter user-name: / as sysdba

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


SQL> startup
ORA-01081: cannot start already-running ORACLE - shut it down first
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@linux dbs]$

[oracle@linux dbs]$ rlwrap rman target / auxiliary sys/oracle@orcl2

Recovery Manager: Release 11.2.0.2.0 - Production on Fri Jan 4 12:57:16 2013

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

connected to target database: ORCL1 (DBID=1188271317)
connected to auxiliary database: ORCL2 (not mounted)

RMAN> duplicate target database to orcl2;

Starting Duplicate Db at 04-JAN-13
using target database control file instead of recovery catalog
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     217157632 bytes

Fixed Size                     2225064 bytes
Variable Size                159386712 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5214208 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCL1'' comment=
 ''Modified by RMAN duplicate'' scope=spfile";
   sql clone "alter system set  db_unique_name =
 ''ORCL2'' 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

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

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

Oracle instance shut down

Oracle instance started

Total System Global Area     217157632 bytes

Fixed Size                     2225064 bytes
Variable Size                159386712 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5214208 bytes

Starting restore at 04-JAN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=18 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 /u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_ncsnf_TAG20130104T123027_8gf1dph2_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_ncsnf_TAG20130104T123027_8gf1dph2_.bkp tag=TAG20130104T123027
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/app/oracle/oradata/orcl2/control01.ctl
Finished restore at 04-JAN-13

database mounted

contents of Memory Script:
{
   set until scn  1024235;
   set newname for datafile  1 to
 "/u01/app/oracle/oradata/orcl2/system01.dbf";
   set newname for datafile  2 to
 "/u01/app/oracle/oradata/orcl2/sysaux01.dbf";
   set newname for datafile  3 to
 "/u01/app/oracle/oradata/orcl2/undotbs01.dbf";
   set newname for datafile  4 to
 "/u01/app/oracle/oradata/orcl2/users01.dbf";
   set newname for datafile  5 to
 "/u01/app/oracle/oradata/orcl2/example01.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

executing command: SET NEWNAME

Starting restore at 04-JAN-13
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 /u01/app/oracle/oradata/orcl2/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/app/oracle/oradata/orcl2/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/app/oracle/oradata/orcl2/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /u01/app/oracle/oradata/orcl2/users01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00005 to /u01/app/oracle/oradata/orcl2/example01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_nnndf_TAG20130104T123027_8gf18mmh_.bkp
channel ORA_AUX_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/ORCL1/backupset/2013_01_04/o1_mf_nnndf_TAG20130104T123027_8gf18mmh_.bkp tag=TAG20130104T123027
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:01:58
Finished restore at 04-JAN-13

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

datafile 1 switched to datafile copy
input datafile copy RECID=7 STAMP=803825994 file name=/u01/app/oracle/oradata/orcl2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=8 STAMP=803825994 file name=/u01/app/oracle/oradata/orcl2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=9 STAMP=803825994 file name=/u01/app/oracle/oradata/orcl2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=10 STAMP=803825994 file name=/u01/app/oracle/oradata/orcl2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=11 STAMP=803825994 file name=/u01/app/oracle/oradata/orcl2/example01.dbf

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

executing command: SET until clause

Starting recover at 04-JAN-13
using channel ORA_AUX_DISK_1

starting media recovery

archived log for thread 1 with sequence 5 is already on disk as file /u01/app/oracle/fast_recovery_area/ORCL1/archivelog/2013_01_04/o1_mf_1_5_8gf1dr2m_.arc
archived log file name=/u01/app/oracle/fast_recovery_area/ORCL1/archivelog/2013_01_04/o1_mf_1_5_8gf1dr2m_.arc thread=1 sequence=5
media recovery complete, elapsed time: 00:00:01
Finished recover at 04-JAN-13
Oracle instance started

Total System Global Area     217157632 bytes

Fixed Size                     2225064 bytes
Variable Size                159386712 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5214208 bytes

contents of Memory Script:
{
   sql clone "alter system set  db_name =
 ''ORCL2'' 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 =  ''ORCL2'' 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     217157632 bytes

Fixed Size                     2225064 bytes
Variable Size                159386712 bytes
Database Buffers              50331648 bytes
Redo Buffers                   5214208 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "ORCL2" RESETLOGS ARCHIVELOG
  MAXLOGFILES     16
  MAXLOGMEMBERS      3
  MAXDATAFILES      100
  MAXINSTANCES     8
  MAXLOGHISTORY      292
 LOGFILE
  GROUP  1 ( '/u01/app/oracle/oradata/orcl2/redo01.log' ) SIZE 50 M  REUSE,
  GROUP  2 ( '/u01/app/oracle/oradata/orcl2/redo02.log' ) SIZE 50 M  REUSE,
  GROUP  3 ( '/u01/app/oracle/oradata/orcl2/redo03.log' ) SIZE 50 M  REUSE
 DATAFILE
  '/u01/app/oracle/oradata/orcl2/system01.dbf'
 CHARACTER SET WE8MSWIN1252


contents of Memory Script:
{
   set newname for tempfile  1 to
 "/u01/app/oracle/oradata/orcl2/temp01.dbf";
   switch clone tempfile all;
   catalog clone datafilecopy  "/u01/app/oracle/oradata/orcl2/sysaux01.dbf",
 "/u01/app/oracle/oradata/orcl2/undotbs01.dbf",
 "/u01/app/oracle/oradata/orcl2/users01.dbf",
 "/u01/app/oracle/oradata/orcl2/example01.dbf";
   switch clone datafile all;
}
executing Memory Script

executing command: SET NEWNAME

renamed tempfile 1 to /u01/app/oracle/oradata/orcl2/temp01.dbf in control file

cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl2/sysaux01.dbf RECID=1 STAMP=803826017
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl2/undotbs01.dbf RECID=2 STAMP=803826017
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl2/users01.dbf RECID=3 STAMP=803826017
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/orcl2/example01.dbf RECID=4 STAMP=803826017

datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=803826017 file name=/u01/app/oracle/oradata/orcl2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=803826017 file name=/u01/app/oracle/oradata/orcl2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=803826017 file name=/u01/app/oracle/oradata/orcl2/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=803826017 file name=/u01/app/oracle/oradata/orcl2/example01.dbf

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

database opened
Finished Duplicate Db at 04-JAN-13

RMAN> exit


Recovery Manager complete.
[oracle@linux dbs]$ ps -ef | grep smon | grep -v grep
oracle   11365     1  0 11:55 ?        00:00:01 ora_smon_orcl1
oracle   20215     1  0 13:00 ?        00:00:00 ora_smon_orcl2
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$
[oracle@linux dbs]$

No comments:

Post a Comment