Академический Документы
Профессиональный Документы
Культура Документы
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:
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
$ export ORACLE_SID=clone_db
$ cd $ORACLE_HOME/dbs
$ sqlplus "/ as sysdba"
SQL>
create
spfile from pfile='pfile_clone_db.ora';
File created.
SQL>
$ 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.