I am currently working on a customer project to create database clones using storage snapshots. The advantages are obvious, because using a storage snapshot as a clone not only saves space, but is also extremely fast compared to a full clone.
This post is not about explaining in detail how to implement the snapshot clone technically, but it should point out an important point to think about when creating the source DB with the DBCA.

A short overview how the snapshot cloning is done with ASM:

  • Set Source DB in backup mode
  • Create a snapshot of the whole ASM disk group on storage level
  • Deactivate backup mode on source DB
  • Present snapshot of LUNS on test server
  • Rename diskgroup with renamedg utility
  • Mount diskgroup under new name in ASM
  • adjust db_unique_name in ASM
  • create new control files for the DB
  • open DB with open resetlogs

The point I want to go into here is ” adjust db_unique_name in ASM”. If you create e.g. on the diskgroup +DATA a new DB, the directory structure in the ASM for the DB looks like this:

+DATA/PROD_SITE1
+DATA/PROD_SITE1/CONTROLFILE
+DATA/PROD_SITE1/DATAFILE
+DATA/PROD_SITE1/ONLINELOG
+DATA/PROD_SITE1/TEMPFILE

 

If we assume that our cloned database should be named TEST01 and we have renamed the diskgroup in ASM from + DATA to +DATA_TEST, after mounting the new diskgroup the directory structure on this diskgroup looks like this:

+DATA_TEST/PROD_SITE1
+DATA_TEST/PROD_SITE1/CONTROLFILE
+DATA_TEST/PROD_SITE1/DATAFILE
+DATA_TEST/PROD_SITE1/ONLINELOG
+DATA_TEST/PROD_SITE1/TEMPFILE

 

Before we can create new controlfiles with the DB name TEST01 we have to rename in ASM the directory with the db_unique_name from PROD_SITE1 to TEST01_SITE1.
In ASM there is no mv command, so the directories have to be adjusted with SQL statement on the ASM instance. This works as follows:

SQL> alter diskgroup DATA_TEST rename directory '+DATA_TEST/PROD_SITE1' to '+DATA_TEST/TEST01_SITE1';

ERROR at line 1:
ORA-15032: not all alterations performed
ORA-15177: cannot operate on system aliases

Here we have a problem. In ASM there are two types of directories. “System Generated (Y)” and “manually created (N)”.
If i query the directory in asmcmd i see, that my database that was created with dbca has a “System generated” name.

ASMCMD> ls -la

Type  Redund  Striped  Time  Sys  Name
                             Y    ASM/
                             Y    PROD_SITE1/

 

When Oracle creates a directory it is always System generated and when manually created with mkdir in asm it is “non System generated”.
You have to know that a “System generated directory” can never be renamed. This is not possible in ASM and there is no workaround for this.
Because we created our source DB with the DBCA, the directory PROD_SITE1 was created as “System generated”, so we don’t have the possibility to change the path for the datafiles to our new name TEST01_SITE1.

One possibility would be to add the new control files anyway and still refer to the old db_unique_name as path. With this the DB could be started and if you query e.g. v$datafile afterwards you would still see the wrong db-unique_name there.
To correct this we could force an online move of the datafile, but the disadvantage is that we copy the whole DB once in ASM and that is exactly what we want to prevent with the snapshot cloning.

alter database move datafile {DATAFILE_PATH} to '+DATA_TEST';

So what is the solution for this problem?
We have to make sure already when creating the source DB (PROD) that the DBCA does not create the directory as “system generated”, so that after cloning  we have the possibility to rename it on the new diskgroup.

For this in the DBCA there is the parameter

-datafileDestination

If this parameter is set explicitly during the DBCA create database statement, the directory is created in ASM as “manually generated” and therefore it can be renamed later.