How to Clone an Oracle Database using the RMAN DUPLICATE
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
1-Install the Oracle database Software on the new host(if you haven't done yet)
2-Create the Target Database(on any host as long as the hosts can communicate to each other)
3-Create the listener.ora and tnsnames.ora files for the new Target Database(stb)
4-Create entries in the tnsnames.ora files on both server(pri and stb)
5-Create an Oracle Password File for the Auxiliary Instance
6-Establish Oracle Net Connectivity to the Auxiliary Instance
7-Create a full backup on the pri database
8-Create the rename script
8-Put the stb database in nomount mode
9-Connect to RMAN
10-Run the DUPLICATE command/script(datafile rename and other parameters are treated at this point)
1-Install the Oracle database Software on the new host(if you haven't done yet)
If you haven't done it yet and you have problems doing it follow this howto article on how to install Oracle Database Software.
2-Create the Target Database(on any host as long as the hosts can communicate to each other)
In this task you will create a new database from scratch. This will receive our duplicate database.
You can create the database using DBCA(which i recommend).
3-Create the listener.ora and tnsnames.ora files for the new Target Database(stb)
We will need to make sure the the new stb database will be available for connections. So for this you need to add specific entries in the
listener.ora file and also in the tnsnames.ora file.
Normally the network configurations are located in the $ORACLE_HOME/network/admin or in my case /oracle/app/product/11.2.0/dbhome_1/network/admin ; the listener.ora and tnsnames.ora can be create by hand
or using the NETMGR tool provided by Oracle.
Here is an example of listener entry for the stb database:
Here is an example of listener entry for the stb database:
Start you listener and make sure you can access your database using tns alias.
Here is an example how you can do this:
Start listener
4-Create entries in the tnsnames.ora files on both server(pri and stb)
Test connection using TNS alias
Before doing so you need to create tns aliases for both your database instances(pri and stb).
In both hosts network directories make sure you create the tnsnames.ora file and edit the file by adding the
following entry.
I will use my tns aliases as an example.
Make sure your hosts can recognize each other by name. If not add the necessary entry into you /etc/hosts file.
Test that you can ping both instances.
5-Create an Oracle Password File for the Auxiliary Instance
When we create duplicate via RMAN we need to create a orapw file in the stb instance.
What i use to do in order to avoid problems i make sue that the sys user on my stb instance will have the same
password as the sys user in the pri instance.
Let's get to work then:
Once the stb sys password was alter create a new password file.
6-Establish/Check Oracle Net Connectivity to the Auxiliary Instance
You need to do this from both server(primary and standby)
7-Create a full backup on the pri database.
8-Create the rename script.
This is needed because the hosts have different mount points and you need to alter the location.
We will use this two scripts to create the rename rman script.
Run the scripts on the pri instance.
Script to rename datafile to point to the new mount/point location.
Script to rename temp files to point to the new mount/point location.
Create the RMAN script that will be used.
9-Put the stb database in nomount mode
In order to run the RMAN duplicate commnad you need to have your stb instance in nomount mode.
Connect to RMAN(connect on the stb host)
10-Run the DUPLICATE command/script(datafile rename and other parameters are treated at this point)
Done !