Page 1

Cloning a Database

Administration Tips

Cloning a Database Cloning a database means creating an identical copy of a database, either on the same machine as the original, or on a different one. Additonally, it means changing the database name, and the Instance name. But those are both optional steps if the clone is being created on a different machine. Even when it's all happening on the one machine, the only requirement is to change the Instance name -changing the database name remains entirely optional. What follows is therefore a set of instructions that takes things one step at a time: first, the clone. Second the renaming of the Instance. Third (if you really want to) is the renaming of the Database. You can do it all in one go. But, if different machines are involved, there's strictly no requirement for steps 2 and 3 -so I've kept them separate. It goes without saying (I hope) that if you are cloning onto a new machine, the Oracle executables and environment variables (like ORACLE_BASE and ORACLE_HOME) need to be in place before you even start. Step 1 : The Actual Cloning • • • •

• •

In the source database, issue the following command: ALTER DATABASE BACKUP CONTROLFILE TO TRACE; Perform a clean shutdown of the source database Copy the source Data Files and Redo Logs to the clone location Locate the Control File trace script made earlier: o Clear out the junk at the top, so that the first line reads STARTUP NOMOUNT. o Add in a line right at the top which connects as a Privileged User (for example, CONNECT / AS SYSDBA) o Add to the STARTUP NOMOUNT line a reference to where the new init.ora is to be located (i.e., the line should read STARTUP NOMOUNT PFILE=/SOMEWHERE/INIT<SID>.ORA) o Also edit edit all the file locations mentioned in the trace file so that they point to appropriate clone locations. For example, when it says LOGFILE GROUP 1 'D:\ODATA\BLAH\LOG1A.RDO’, change that to read ‘C:\SOMEWHERE_NEW\LOG1A.RDO'. Do that for all file location references. Copy the init.ora from the source database, and edit it so that it is appropriate for the Clone. Make sure you edit: o CONTROL_FILES= (point to where you want the clone's Control Files created) o LOG_ARCHIVE_DEST (and variants) (the source archives must not be overwritten by the clone's) o USER_DUMP_DEST & BACKGROUND_DUMP_DEST (source trace files must not be overwritten by the clone) Start Server Manager or SQL Plus for the clone. Run the Trace File script (ie, type @NAME_OF_SCRIPT). That will then connect you as per the connect line you added to the script, startup in the nomount stage, and

Copyright © Howard Rogers 2001

10/31/2001

Page 1 of 3


Cloning a Database

Administration Tips

issue the 'create controlfile' commands. At the end of the exercise, your database should be left in the fully open state, with all the required controlfiles in place. At this point, you make sure everything is working perfectly. Once you know it is, it is time to consider re-naming the Instance and the Database Step 2 : Changing the Instance Name • • • •

Shutdown the new clone database Exit completely out of SQL Plus or Server Manager (you can't set an environment variable if you simply shell out of those applications). Use the appropriate O/S command to set a new ORACLE_SID. On Unix, that means type EXPORT ORACLE_SID=XXX, and on NT, that means type SET ORACLE_SID=XXX Run SQL Plus or Server Manager once more, connect as a Privileged User, and issue the STARTUP PFILE=/WHEREVER/<NAME OF INIT.ORA> command.

Note that on NT you'd have to use ORADIM (or, for versions before 8i, ORADIM80 or ORADIM73) to create a Service for the new Instance name before you can start it up (you still need to change the ORACLE_SID as well). On Unix, the change of ORACLE_SID is sufficient in itself. Also note that I'm assuming here that you're using Operating System authentication for the Privileged User. If you've got a Password File instead, you'll need to copy the Password File from the primary database into the standard default location, and change its name to be ORAPW<SID>, otherwise you'll never get authenticated properly.

Step 3 : Changing the Database Name • • • •

Whilst connected to the Clone database, issue the Alter Database Backup Controlfile to Trace command once more. Perform a clean Shutdown of the clone. (Shutdown Immediate will do, but don't try a Shutdown Abort). Delete all clone Control Files Locate the Control File trace script created earlier and make the following amendments to it: o strip out all the rubbish at the top so that the first line reads STARTUP NOMOUNT. o Add in a line right at the top which connects as a Privileged User (for example, CONNECT / AS SYSDBA). o Add to the "startup nomount" line a reference to where the new init.ora is to be located (i.e., the line should read STARTUP NOMOUNT PFILE=/SOMEWHERE/INIT<SID>.ORA). o Change the CREATE CONTROLFILE REUSE 'X' NORESETLOGS..... line to read CREATE CONTROLFILE SET 'Y' RESETLOGS..... In other words, X is the old

Copyright © Howard Rogers 2001

10/31/2001

Page 2 of 3


Cloning a Database

• •

Administration Tips

name, and Y is the new one. And yes, you're going to have to do a Resetlogs after this procedure. o Finally, change the line ALTER DATABASE OPEN to ALTER DATABASE OPEN RESETLOGS. Edit the clone init.ora and change the db_name parameter to match the new database name Start SQL Plus or Server Manager and run the Control File trace script (by typing @NAME_OF_SCRIPT). As before, the database should eventually be left in the fully open state. Do a SELECT * FROM V$DATABASE to check that the database name really has changed. If you care about your clone, you should now perform a clean shutdown and backup, because the resetlogs that was issued will have rendered all prior backups and archives of the primary system completely useless as a way of recovering the clone.

Note that where these instructions refer to 'starting SQL Plus or Server Manager', they are assuming at least an Oracle 8i database. In all versions prior to that, Server Manager was the only tool able to perform startups and shutdowns.

Copyright © Howard Rogers 2001

10/31/2001

Page 3 of 3

Microsoft Word - Cloning a Database  

CONNECT / AS SYSDBA) o Add to the STARTUP NOMOUNT line a reference to where the new init.ora is to be located (i.e., the line should read ST...