Cloning" an Oracle
Database simply allows the DBA to create another database w/o using the traditional
IMPORT/EXPORT route.
Exporting and then importing of a database generally takes a long time, and after the import the DBA
must go through numerous checks of the new database to make sure that all
objects imported successfully, and are in a valid state.
Cloning of an Oracle database produces a exact snapshot of the source database taken at the
time of the clone.
Cloning works on both 8 & 9 versions of the RDBMS, but produces an unexpected side-effect. For more information about this, click here.
It is helpful to have a working knowledge of Oracle before doing this, although the steps are
fairly straightforward.
SVRMGR> connect internal
Connected.
SVRMGR> shutdown immediate
3. Now comes the hard part. You will have to find the text-based copy
of your controlfile which will be saved in the trace directory. This directory
will be contained in the directory pointed to by USER_DUMP_DEST
in the database initialization parameter file. Typically, this is the $ORACLE_HOME/rdbms/log
directory.
All the trace files in this directory will be named with an obscure
PID label and '.trc' extension. The trace file that is a backup copy of
the database controlfile will have the word 'CONTROLFILE' in it, so search
all trace files for this string.
On Unix systems, position yourself into the USER_DUMP_DEST dir and type
the following:
grep -i CONTROLFILE *.trc
Once you find a match, take a look at it, it should similar look like
the one below. Be SURE that it contains the keywords 'STARTUP NOMOUNT'
and 'CREATE CONTROLFILE'
Thu Jul 23 22:04:39 1998
Thu Jul 23 22:04:39
1998
*** SESSION ID:(6.1)
1998.07.23.22.04.39.084
# The following commands
will create a new control file and use it
# to open the database.
# No data other than
log history will be lost. Additional logs may
# be required for media
recovery of offline data files. Use this
# only if the current
version of all online logs are available.
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE
DATABASE "SEED" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 30
MAXINSTANCES 1
MAXLOGHISTORY 100
LOGFILE
GROUP 1 '/oradata/SEED/log_SEED_01.rdo'
SIZE 1M,
GROUP 2 '/oradata/SEED/log_SEED_02.rdo'
SIZE 1M
DATAFILE
'/oradata/SEED/system_SEED_01.dbf'
;
# Recovery is required
if any of the datafiles are restored backups,
# or if the last shutdown
was not normal or immediate.
RECOVER DATABASE
# Database can now be
opened normally.
ALTER DATABASE OPEN;
You'll have to edit this file and perform the following changes
(a) Delete all lines at the top of the trace file up to but NOT INCLUDING STARTUP NOMOUNT
(b) Delete all lines that start with '#', which are comments
(c) On the the that starts with CREATE CONTROLFILE, change 'REUSE' to 'SET' Change the old database name to the new one, and change 'NORESETLOGS' to 'RESETLOGS'
(d) Change the locations of all logfiles and datafiles to the location of the datafiles and logfiles for the new database.
(e) Delete the line 'RECOVER DATABASE'
(f) Change the line 'ALTER DATABASE OPEN' to 'ALTER DATABASE OPEN RESETLOGS'
Save the trace file with a more managable filename, like clone.sql
Once you are done editing the above file, it should
look something like the one shown below. In this example, we are copying
the SEED database into a database named TEST with /oradata/TEST containing
all Oracle datafiles and logfiles.
5. Once you have copied all the associated datafiles, you are ready
to create the new database. The actual cloning process simply creates a
new set of Oracle controlfiles for the new database. Set your $ORACLE_SID
to point to the name of the new database. The actual command to do this
will depend on the type of shell you are using.
{for /bin/sh, /bin/ksh,
/bin/bash}
ORACLE_SID={name
of new database} ; export ORACLE_SID
{for /bin/csh, /bin/tcsh}
setenv ORACLE_SID
{name of new database}
for our example above,
we would enter the following:
$ ORACLE_SID=TEST
; export ORACLE_SID {sh, ksh, bash}
OR
% setenv ORACLE_SID
TEST {csh, tsch}
6. Invoke Oracle's Server Manager (svrmgrl) or SQL*DBA. Execute a 'connect
internal' to the new database and run the newly edited script.
bash-2.02$ svrmgrl
Oracle Server Manager
Release 2.3.3.0.0 - Production
Copyright (c) Oracle
Corporation 1994, 1995. All rights reserved.
Oracle7 Server Release
7.3.3.0.0 - Production Release
With the distributed,
replication, parallel query and Spatial Data options
PL/SQL Release 2.3.3.0.0
- Production
SVRMGR> connect internal
Connected.
SVRMGR> @clone.sql
Statement processed.
7. If you have no errors, you now have another copy of your database.
As a general rule, you may want to shutdown/startup this new database just
to make sure there are no problems.
8. You can now go back and restart the original database. Simply reset
$ORACLE_SID to point to the original database name, and invoke svrmgrl
or sqldba and restart.