How To : How to clone/duplicate a database with added datafile with no backup

posted Mar 16, 2011, 11:48 AM by Sachchida Ojha
How can I clone/duplicate a database and change it's name if a datafile backup is missing. Archivelog files are available for recreating the datafile using 'alter database create datafile'.

I.e., a datafile was added to the database, but not yet backed up. Archive files are available to recreate this datafile. How can a clone/duplicate database be created in this scenario?

Issues to consider:

1. The RMAN duplicate command will want to create a new controlfile. However, the new datafile will not be added to the controlfile.
2. If a new controlfile is created with a database name change, the datafile cannot be added after the fact.
3. You cannot create a datafile (using alter database) if that datafile is not listed in the controlfile.

You will not be able to use the RMAN duplicate in this scenario.  The RMAN duplicate command would fail with errors on the newly added datafile, like:

ORA-01565: error in identifying file 'H:\BACKUP1\INDX03.DBF'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 2) The system cannot find the file specified.

Another possibility would be errors like:

RMAN-03002: failure of Duplicate Db command at 03/22/2007 10:16:22
RMAN-03015: error occurred in stored script Memory Script
ORA-00283: recovery session canceled due to errors
RMAN-11003: failure during parse/execution of SQL statement: alter database recover logfile '/mnt/backup-sbta08/arch/pva/arch0000044783.arc'
ORA-00283: recovery session canceled due to errors
ORA-01244: unnamed datafile(s) added to controlfile by media recovery
ORA-01110: data file 93: '/pva/oradata/pva/tag_d0_01.dbf'

NOTE:  In Oracle10g, RMAN will create the datafiles on recovery, so this may not be an issue.

NOTE:  The same issue can apply to creating a duplicate database for standby, when datafiles are added to the primary after the backup.

Instead, you MUST use a current controlfile of the target database, to create the clone. Then the database name/DBID can be changed using the NID utility.


NOTE: Target database must be shutdown if the clone is created on the same server.

1. copy production controlfile in the clone location.
2. startup mount clone database
3. select name from v$datafile
-- issue 'alter database rename file .... to .....; /* this renames the datafile location. It is
must be issued for every datafile existing - thus missing datafile will not be included in this
4. select name from v$logfile
-- issue ''alter database rename file .... to .....; /* this rename will place the redo log files
in the proper location when clone database is opened.
5. issue:
alter database create datafile AS ;

6. Restore the database
7. recover database using backup controlfile until cancel;
-- apply all archives you have
8. alter database open resetlogs;
9. shutdown database
10. startup mount
11. exit sql and issue at the operating system:
/* NOTE: If you plan to register this database in RMAN the dbid must also be changed using the NID utility */
12. shutdown database
13. edit init.ora changing db_name parameter
14. startup cloned database
15. verify name change:
select name from v$database
show parameter db_name