There are several ways to clone an ASM based database, some of them result in a directory structure that do not match the current database name, i.e, the source database directory structure is built this way:
+DATADG/proddb/controlfile
+DATADG/proddb/onlineredolog
... etc
2) Creating a set of directories and moving the database oracle files over to it
For instance if the database to be cloned is a billing system we may set the db_unique_name at database creation to "billing", in this case we will get for all our clones a generic root directory named "billing" instead of one that is the name of source database in the group.
When using Database Configuration Assistant (DBCA) you can set manually the parameter db_unique_name by choosing parameters -> advanced parameters configuration.
The static parameter db_unique_name can be changed at any moment, it will require an instance restart to become active.
If you are using Oracle Managed Files (OMF) The new unique_db_name is used as root directory for any new oracle files created from the moment the new name is made active.
Following you can see an example of a database created with a db_unique_name='generic' and a db_name='redhorse'
NAME
---------
REDHORSE
SQL> select * from global_name;
GLOBAL_NAME
--------------------------------------------------------------------------------
REDHORSE
SQL> select db_unique_name from v$database;
DB_UNIQUE_NAME
------------------------------
GENERIC
SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
+DB1DATADG/generic/datafile/system.292.643421261
+DB1DATADG/generic/datafile/undotbs1.293.643421325
+DB1DATADG/generic/datafile/sysaux.294.643421347
+DB1DATADG/generic/datafile/users.296.643421387
2. Creating a set of directories and moving the database oracle files over to it
Once the clone is created you will manually create the directories matching the new name, and move the oracle files from the old directory to the new directory using rman, i.e.:
- Create a set of directories reflecting the new database structure, in my case the original database was cpdg1 and the clone is cpdg2.
(it may happen that your spfile is siting on an alias with the name of the database, you will need to remove the alias to be able to create the directories)
CONTROLFILE/
DATAFILE/
ONLINELOG/
PARAMETERFILE/
TEMPFILE/
ASMCMD> mkdir cpdg2
ASMCMD> mkdir cpdg2/CONTROLFILE/
ASMCMD> mkdir cpdg2/DATAFILE/
ASMCMD> mkdir cpdg2/PARAMETERFILE/
ASMCMD> mkdir cpdg2/TEMPFILE
- From now on every create of an oracle file on database cpdg2 will go to the cpdg2 directory, i.e.
NAME
---------
CPDG2
SQL> create tablespace users2;
Tablespace created.
SQL> select file_name from dba_data_files where tablespace='USERS2';
FILE_NAME
-------------------------------------------------------
+DB3CLNDG/cpdg2/datafile/users2.267.643260907
- To move tablespaces based on the old directory cpdg1 set the tablespace offline and move the datafiles with rman
Tablespace altered.
- Start an rman session
RMAN> '+DB3CLNDG';
Starting backup at 06/01/2008 03:42:53
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004
name=+DB3CLNDG/cpdg1/datafile/users.264.640191515
output file name=+DB3CLNDG/cpdg2/datafile/users.268.643261377
tag=TAG20080106T034255 RECID=1 STAMP=643261380 channel ORA_DISK_1:
datafile copy complete, elapsed time: 00:00:07 Finished backup at
06/01/2008 03:43:03
RMAN> switch tablespace users to copy;
datafile 4 switched to datafile copy
"+DB3CLNDG/cpdg2/datafile/users.268.643261377"
- Bring the tablespace online again
Tablespace altered.
SQL> select file_name from dba_data_files where tablespace_name='USERS';
FILE_NAME
-----------------------------------------------------
+DB3CLNDG/cpdg2/datafile/users.268.643261377
- Now you can delete the old file
+DB3CLNDG/cpdg1/datafile/users.264.640191515
users.264.640191515
{oracle} /oradisk/app01/oracle/product/11db/dbs [pollux.com] > asmcmd rm
+DB3CLNDG/cpdg1/datafile/users.264.640191515
{oracle} /oradisk/app01/oracle/product/11db/dbs [pollux.com] > asmcmd ls
+DB3CLNDG/cpdg1/datafile/users.264.640191515
ASMCMD-08002: entry 'users.264.640191515' does not exist in directory
'+DB3CLNDG/cpdg1/datafile/'
Comments (1)
Great tips, Alejandro. Thanks for putting this together. I'm sure the technical steps for these techniques are in the docs somewhere, but are there any Metalink notes or other "official" sources that pull all the steps together as neatly as you've done here?
Dan
Posted by Dan Norris | January 8, 2008 11:01 AM
Posted on January 8, 2008 11:01