Wednesday, June 18, 2008

RMAN cloning

The cloning method using RMAN is more suitable for production databases with large size and more number of tablespaces. It is a common request to create a duplicate database from a production database. This can be easily achieved using the RMAN DUPLICATE command.

Using the RMAN DUPLICATE command a DBA can create a duplicate database from a target database's backup while still retaining the original target database.

While it is possible to create a duplicate database that contains only a subset of the original database. This document will demonstrate how to create a completely identical database. Using this method allows DBA to test backup and recovery procedures developed on the production database.

Steps to be followed:

1.Create a parameter file for the clone database using the parameter file of the target database.

SQL> create pfile='/home/vamsi/OraHome1/dbs/initclon.ora' from spfile;
File created.

2.Create a password file for the clone database.

[vamsi@vamsi dbs]$ orapwd file='/home/vamsi/OraHome1/dbs/orapwclon'
password=change_on_install

3.Do the necessary changes to the parameter values in the pfile of clone insert the following parameters in the file.

db_file_name_convert='/data/cloning/target/data','/data/cloning/clon/data')
log_file_name_convert=('/data/cloning/target/redo','/data/cloning/clon/redo')
background_dump_dest='/data/cloning/clon/bdump'
compatible='9.2.0.0.0'
control_files='/data/cloning/clon/control/control01.ctl'
core_dump_dest='/data/cloningdb/target/cdump'
db_name='clon'
instance_name='clon'
log_archive_dest_1='LOCATION=/data/cloning/clon/arch/'
user_dump_dest='/data/cloning/clon/udump'

4. Configure the network files.

[vamsi@vamsi admin]$ vi listener.ora
LISTENER=(DESCRIPTION=
(ADDRESS=(PROTOCOL = TCP)(HOST = 192.9.200.217)(PORT = 1521))
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = target.com)
(ORACLE_HOME = /home/vamsi/OraHome1)
(SID_NAME = target)
)
(SID_DESC =
(GLOBAL_DBNAME = catalog.com)
(ORACLE_HOME = /home/vamsi/OraHome1)
(SID_NAME = catalog)
)
(SID_DESC =
(GLOBAL_DBNAME = clon.com)
(ORACLE_HOME = /home/vamsi/OraHome1)
(SID_NAME = clon)
)
)

[vamsi@vamsi admin]$ vi tnsnames.ora
CON_CLO =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.9.200.217)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = clon.com)
))
CON_CAT =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.9.200.217)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = catalog.com)
))
CON_TAR =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.9.200.217)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = target.com)
(SERVER=DEDICATED)
))

5. Create the necessary directory structure for the clone.

[vamsi@vamsi clon]$ mkdir adump bdump cdump udump
[vamsi@vamsi clon]$ mkdir data control redo arch

6. Configure the RMAN to take backup of control file.

RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR
DEVICE TYPE DISK TO '/data/cloning/clon/control/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE
DISK TO '/data/cloning/clone/control/%F';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete

RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT
'/data/cloning/clon/data/DB_%d_S_%s_P_%p_T_%t';
new RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK FORMAT
'/data/cloning/clone/data/DB_%d_S_%s_P_%p_T_%t';
new RMAN configuration parameters are successfully stored
starting full resync of recovery catalog
full resync complete
released channel: ORA_DISK_1

7. Take complete backup of the target database using RMAN.

RMAN> backup database;
Starting backup at 25APR08
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/data/cloning/target/data/system01.dbf
input datafile fno=00002 name=/data/cloning/target/data/undotbs01.dbf
input datafile fno=00005 name=/data/cloning/target/data/example01.dbf
input datafile fno=00010 name=/data/cloning/target/data/xdb01.dbf
input datafile fno=00006 name=/data/cloning/target/data/indx01.dbf
input datafile fno=00009 name=/data/cloning/target/data/users01.dbf
input datafile fno=00003 name=/data/cloning/target/data/cwmlite01.dbf
input datafile fno=00004 name=/data/cloning/target/data/drsys01.dbf
input datafile fno=00007 name=/data/cloning/target/data/odm01.dbf
input datafile fno=00008 name=/data/cloning/target/data/tools01.dbf
channel ORA_DISK_1: starting piece 1 at 25APR08
channel ORA_DISK_1: finished piece 1 at 25APR08
piece handle=/data/cloning/clon/data/DB_TARGET_S_3_P_1_T_652995913
comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
Finished backup at 25APR08
Starting Control File and SPFILE Autobackup at 25APR08
piece handle=/data/cloning/clon/control/c30548414812008042500
comment=NONE
Finished Control File and SPFILE Autobackup at 25APR08

8. Startup the clone database to nomount phase and exit from the terminal.

[vamsi@vamsi clon]$ export ORACLE_SID=clone
[vamsi@vamsi clon]$ sqlplus "/as sysdba"

SQL*Plus: Release 9.2.0.1.0 Production
on Fri Apr 25 19:52:43 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to an idle instance.
SQL> startup nomount
ORACLE instance started.
Total System Global Area 235999352 bytes
Fixed Size 450680 bytes
Variable Size 201326592 bytes
Database Buffers 33554432 bytes
Redo Buffers 667648 bytes
SQL>exit

Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 Production

9.Connect to the clone database through RMAN.

RMAN> connect auxiliary sys/change_on_install@con_clo
connected to auxiliary database: clone (not mounted)

10.Run the RMAN DUPLICATE DATABASE command.

RMAN> run{#Allocate the channel for the duplication work
allocate auxiliary channel ch1 type disk;
#Duplicate the target to clone
duplicate target database to clon;}

11. Startup the clone database.

[vamsi@vamsi ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 9.2.0.1.0 Production
on Tue Apr 29 11:31:13 2008
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 Production

SQL> sho parameter db_name
___NAME_____TYPE_____VALUE_
__db_name____string______clon__

12. Create all temp files for the temporary tablespaces.

SQL> create temporary tablespace temp tempfile '/data/cloning/clon/data/temp01.dbf' size 100m
autoextend on;
Tablespace crated;

Conclusion :

Cloning is the easiest method to duplicate a production database, Depending on the requirement one of the above methods can be effectively used to clone a production database. Care should be taken while setting the paths for the clone database as there is a possibility of corrupting the production database by improper setting of the paths for the clone. ie. The clones path should not conflict with the production database path.