One of the most important tasks that a DBA must know and understand is database cloning. Database cloning will be required for different reasons such as creating replicas for your development team or you want to stress test your database and you need a copy of it. We will see in this article one of the many ways we can clone an Oracle database using RMAN DUPLICATE. You can use the RMAN DUPLICATE command to create a duplicate database from backups of the target database(pri database) while retaining the original target database. The duplicate database can be identical to the target database or contain only a subset of the tablespaces in the target database. The target site and the duplicate site can be on separate hosts or on the same host. Just as a reminder remember that a duplicate database is distinct from a standby database, although both types of databases are created with the DUPLICATE command. In the image bellow is a description of the process and the components that are required to create a stb using duplicate command. Let's see the list of tasks we have to go thrum in order to successfully stb our Oracle database using duplicate command
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = server.domain)(PORT = 1521))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME= /oracle/app/product/11.2.0/dbhome_1)
(SID_NAME = stb)
(GLOBAL_DBNAME= stb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = STANDBY)(PORT = 1521))
)
)
--add this to so you can log in with RMAN when your stb db is in nomount mode.
--this is a static listener entry
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1)
(SID_NAME = stb)
(GLOBAL_DBNAME= stb)
)
)
[oracle@STANDBY admin]$ lsnrctl start LISTENER
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 14-SEP-2014 09:06:51
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /u01/app/oracle/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/STANDBY/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=STANDBY)(PORT=1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 14-SEP-2014 09:06:51
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/STANDBY/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=STANDBY)(PORT=1521)))
Services Summary...
Service "stb" has 1 instance(s).
Instance "stb", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
STB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = STANDBY)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = stb)
)
)
PRI =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = PRIMARY)(PORT = 1522))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = pri)
)
)
[oracle@STANDBY admin]$ tnsping stb
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 14-SEP-2014 09:07:25
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = STANDBY)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = stb)))
OK (0 msec)
sql:alter user sys identified by "your pri password";
# Go to
[oracle@STANDBY admin]$ cd $ORACLE_HOME/dbs
[oracle@STANDBY dbs]$ pwd
/u01/app/oracle/product/11.2.0/dbhome_1/dbs
[oracle@STANDBY dbs]$ ll orapwstb
-rw-r----- 1 oracle oinstall 1536 Sep 14 08:52 orapwstb
# Remove the old orapwstb
[oracle@STANDBY dbs]$ rm -f orapwstb
# Re-create the orapwd file
[oracle@STANDBY dbs]$ orapwd file=orapwstb password=******* ignorecase=y
[oracle@STANDBY dbs]$ ll orapwstb
-rw-r----- 1 oracle oinstall 1536 Sep 14 09:59 orapwstb
--Test on standby host
[oracle@STANDBY dbs]$ rman target sys/*******@pri auxiliary sys/*******@stb
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Sep 14 10:03:08 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PRI (DBID=788900126)
connected to auxiliary database: STB (DBID=783068347)
RMAN
--Test on primary host
[oracle@primary dbs]$ rman target sys/*******@pri auxiliary sys/*******@stb
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Sep 14 10:04:22 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PRI (DBID=788900126)
connected to auxiliary database: STB (DBID=783068347)
$ rman target /
RMAN CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN BACKUP DATABASE PLUS ARCHIVELOG
select 'set newname for datafile '||file#||' to ''/new/mount/point'|| substr(name,instr(name,'/',-1))||''';' as remane_dbf from v$datafile;
REMANE_DBF
--------------------------------------------------------------------------------
set newname for datafile 1 to '/new/mount/point/system01.dbf';
set newname for datafile 2 to '/new/mount/point/sysaux01.dbf';
set newname for datafile 3 to '/new/mount/point/undotbs01.dbf';
set newname for datafile 4 to '/new/mount/point/users01.dbf';
select 'set newname for tempfile '||file#||' to ''/new/mount/point'|| substr(name,instr(name,'/',-1))||''';' as remane_tmp from v$tempfile;
REMANE_TMP
--------------------------------------------------------------------------------
set newname for tempfile 1 to '/new/mount/point/temp01.dbf';
run {
allocate channel P1 device type disk;
allocate auxiliary channel AUX1 device type disk;
set newname for datafile 1 to '/new/mount/point/system01.dbf';
set newname for datafile 2 to '/new/mount/point/sysaux01.dbf';
set newname for datafile 3 to '/new/mount/point/undotbs01.dbf';
set newname for datafile 4 to '/new/mount/point/users01.dbf';
set newname for tempfile 1 to '/new/mount/point/temp01.dbf';
duplicate target database to stb from active database;
}
startup force nomount;
ORACLE instance started.
Total System Global Area 221294592 bytes
Fixed Size 2212048 bytes
Variable Size 104861488 bytes
Database Buffers 109051904 bytes
Redo Buffers 5169152 bytes
[oracle@STANDBY dbs]$ rman target sys/*******@pri auxiliary sys/*******@stb
Recovery Manager: Release 11.2.0.1.0 - Production on Sun Sep 14 10:23:23 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PRI (DBID=788900126)
connected to auxiliary database: STB (not mounted)
RMAN
RMAN run {
allocate channel P1 device type disk;
allocate auxiliary channel AUX1 device type disk;
set newname for datafile 1 to '/u01/app/oracle/oradata/stb/system01.dbf';
set newname for datafile 2 to '/u01/app/oracle/oradata/stb/sysaux01.dbf';
set newname for datafile 3 to '/u01/app/oracle/oradata/stb/undotbs01.dbf';
set newname for datafile 4 to '/u01/app/oracle/oradata/stb/users01.dbf';
set newname for tempfile 1 to '/u01/app/oracle/oradata/stb/temp01.dbf';
duplicate target data base to STB from active database;
}
.........
.........
.........
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=858249753 file name=/u01/app/oracle/oradata/stb/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=858249754 file name=/u01/app/oracle/oradata/stb/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=858249754 file name=/u01/app/oracle/oradata/stb/users01.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 14-SEP-14
released channel: P1
released channel: AUX1
RMAN