Вы находитесь на странице: 1из 4

RMAN - cloning on a Local Host

Expert Oracle Database Tips by Donald BurlesonConsulting

March 25, 2015

RMAN - Creating a Duplicate Database on


a Local Host

Note: It is recommended NOT to clone the production database on the same server or host.
However as a practice, it can be done for any non-production databases.

Once the clone database has been created on the remote host, it is possible to duplicate a
database to the local host, too. For this, the database name and location of database files
should be different. Moreover, tnsnames.ora and listener.ora files should be configured
correctly.

In the following example, there is one production database called test and the goal will be to
clone it to the same host with the name clone_db. Now go through the steps of the process:

Make a copy of the password file for the second database:


$ cp $ORACLE_HOME/dbs/orapwtest $ORACLE_HOME/dbs/orapwclone_db

Configure both listener.ora and tnsnames.ora files to connect to the auxiliary database
(clone_db) that is needed to change the tnsnames.ora and listener.ora file. Change these
files as follows:
listener.ora:
(SID_DESC =
(SID_NAME = clone_db)
(ORACLE_HOME = /u01/oracle/product/10.2.0/db_1)
)
tnsnames.ora
clone_db =
(description =
(address = (protocol = tcp)(host = localhost.localdomain)(port = 1521))
(connect_data =
(server = dedicated)
(service_name = clone_db)
)
)

Do not forget to apply changed parameters to the running listener by running the following
command:

$ lsnrctl reload

Create a parameter file for the auxiliary (clone_db) database:


*.compatible='10.2.0.1.0'
*.control_files='/u03/oracle/clone_db/control01.ctl','/u03/oracle/
clone_db/control02.ctl','/u03/oracle/clone_db/control03.ctl'
*.db_block_size=8192
*.db_name='clone_db'
*.sga_target=285212672

Now, create spfile from this parameter file:

$ export ORACLE_SID=clone_db
$ cd $ORACLE_HOME/dbs
$ sqlplus "/ as sysdba"

SQL>
create
spfile from pfile='pfile_clone_db.ora';
File created.
SQL>

Start up the auxiliary instance in nomount mode:


$ export ORACLE_SID=clone_db
$ sqlplus "/ as sysdba"
SQL>
startup
nomount;

Back up the production database using RMAN:


$ export ORACLE_SID=test
$ rman target /
RMAN> backup database plus archivelog;

Duplicate database using the following script.


Now, as the database is cloned in the same host, a different location for datafiles of the new
database needs to be defined. Here, use set newname to define the new location in run
block. Ensure that this is done correctly for every datafile! Connect to both instances and run
the following run block:

$ export ORACLE_SID=test
$ ./rman target sys/test auxiliary sys/test@clone_db
connected to target database: TEST (DBID=2003066891)
connected to auxiliary database: clone_db (not mounted)

RMAN> run {
set newname for datafile 1 TO
'/u03/oracle/clone_db/system01.dbf';
set newname for datafile 2 TO
'/u03/oracle/clone_db/undotbs01.dbf';
set newname for datafile 3 TO
'/u03/oracle/clone_db/sysaux01.dbf';
set newname for datafile 4 TO
'/u03/oracle/clone_db/users01.dbf';
set newname for tempfile 1 TO '/u03/oracle/clone_db/temp01.dbf';
duplicate target database to clone_db
logfile
'/u03/oracle/clone_db/redo01.log' SIZE 5M,
'/u03/oracle/clone_db/redo02.log' SIZE 5M,
'/u03/oracle/clone_db/redo03.log' SIZE 5M;
}
................
................
database opened
Finished Duplicate Db at 06-DEC-09
RMAN>

If the exact number of the data file to specify in the set newname for datafile < datafile
number> to command is not known, then query in the database as follows:

SQL>
select
file_id,file_name FROM dba_data_files;

For the set newname for tempfile < tempfile number> to command, then:

SQL>
select
file_id,file_name
from
dba_temp_files;

The data and temp file numbers can also be found by connecting to the production database
with RMAN client as follows:

$ export ORACLE_SID=test
$ rman target /
RMAN> show schema;

Here the file number information can be seen. Now, connect to the auxiliary instance and
query datafile locations:

$ export ORACLE_SID=clone_db
$ sqlplus "/ as sysdba"
SQL>
select
name
from
v$database;
NAME
---------
clone_db

SQL>
select
name
from
v$datafile;

NAME
-------------------------------------
/u03/oracle/clone_db/system01.dbf
/u03/oracle/clone_db/undotbs01.dbf
/u03/oracle/clone_db/sysaux01.dbf
/u03/oracle/clone_db/users01.dbf
SQL>

This shows that the clone database of the primary database test1 was created with a
different database name (clone_db) and different directory structure.

Вам также может понравиться