Thursday, July 24, 2008

Easy Clone / Duplicate Oracle 10G database

Today I had a task to clone or duplicate a Oracle 10g database. Being a novice, I took to google and looked for answers. After some research came with a few ways:
  1. Using EM :: Maintenance :: Deployments :: Clone Database option : The problem with it is its needs "An open database in ARCHIVELOG mode" which I dont have. Hence it requires a restart as mentioned in here. Hence I left this option here itself.
  2. Duplicate database using RMAN : A nice article about it is available in here. I tried it and then spend another 2-3 hours to connect to the newly created database. Thereafter I left this method to.
  3. The command line way : Its all using sqlplus and is pretty technical. Details are available here. It works but looked for an easy alternative.
  4. The DBCA way : This I found to be the easiest and the fastest option but sadly it not available in the top results of google. Looks like its one of the least used way to duplicate an Oracle DB but its the best one. To promote it I write this post.

Here's how its done:
  1. Start the Database Configuration Assistant (DBCA). Found at All Programs :: Oracle - OracleDb10g_home1 :: Configuration and Migration Tools :: Database Configuration Assistant. The same can be invoked by typing in "dbca" at the command prompt.
  2. On the "Welcome" screen click the "Next" button.
  3. On the "Operations" screen select the "Manage Templates" option and click the "Next" button.
  4. On the "Template Management" screen select the "Create a database template" option and select the "From and existing database (structure as well as data)" sub-option then click the "Next" button.
  5. On the "Source database" screen select the relevant database instance and click the "Next" button.
  6. On the "Template properties" screen enter a suitable name and description for the template, confirm the location for the template files and click the "Next" button.
  7. On the "Location of database related files" screen choose either to maintain the file locations or to convert to OFA structure (recommended) and click the "Finish" button.
  8. On the "Confirmation" screen click the "OK" button.
  9. Wait while the Database Configuration Assistant progress screen gathers information about the source database, backs up the database and creates the template.
  10. Depending upon the size of the database it will take some time. For my 8 Gig database, it took like 8 mins. Now we have a template created and we will use to create our new database.
  11. Click on "Next Operation".
  12. Select "Create a Database" option and click "Next".
  13. In "Select a template from the following list to create a database" - select the template name which you provided in Step 6 and click "Next".
  14. Provide the new Service Name for the new database. The SID will automatically be set to the service name entered above. Click "Next".
  15. Let the "Configure the Database with Enterprise Manager" remain checked and "Use Database Control for Database Management" remain checked. Click "Next".
  16. Provide the sys password and click "Next".
  17. Let the "File System" option remain checked unless you want to use ASM or raw for your new database.
  18. Let the "Use Database File Locations from Template remain checked. This is important. Click "Next".
  19. Let the default values for Flash Recover Area remain as they are and click "Next".
  20. Let the "No Scripts to run" remain checked an click "Next".
  21. You can keep the default values for Memory and Sizing over here or change it as per your need and Click "Next".
  22. You are now at the final screen wherein you can all your configurations and verify that they are correct. Clicking next, DBCA will do all your job and your DB should be up and running in next 15-20 mins.
  23. Finally before logging in to the new DB using EM, check the tnsnames.ora and see an entry is created for the new database else add one. You can add a new listenere too in you listener.ora if you want and the do a "lsnrctl reload" to reload the listeners.
  24. Finally do a tnsping on your new database to check all's fine.
  25. Log in using EM and you should have you DB ready in Open mode.
  26. Note all user accounts besides the system account are locked and expired so you need to unlock them to allow users to connect to the new DB.
The whole process took some 30-35 mins and it was all Gui and no scripts or errors. Seem to be the best way out to duplicate an Oracle 10g database :)

10 comments:

Unknown said...

Hi Sandeep,
This instruction was a lifesaver for me, thanks. After battling for about 12hrs with differnt ways to clone a db including using RMAN, i found this noe and got it done in about 30mins. Thanks again

Sandeep Kumar said...

You are welcome.

Unknown said...

Hi,

This seems pretty neat, but I have just this one question - What if the new server is at a place where there's no connection to/from the old server - will you still be able to use this GUI approach to succeed. (I'm more familiar with 9i)

I'm thinking that you MIGHT eb able to copy the backup/files you mentioned, from the old to the new server and somehow start the same DBCA GUI on the new server and finish the copy there !?

Thanks in advance :)

xyvyx said...

from what I can tell, you can copy a DBC template file into the {ora home}\assistants\dbca\templates folder, and when you launch DBCA, it will show up in the list of templates.

I'm not certain about the CTL/DFB files... I assume it would work the same way, but since they're binary, I don't know how they reference one another. If simply by name, it might work.

Anonymous said...

Sandeep, thank you for the good info.

I have a question. I have a 10g DB that I want to copy to a spare
disk slice and then use that spare slice
to do a test DB upgrade on.
I've used "cpio" to copy the DB but I can never get
it to start even though this spare slice is mounted with the same path ( /u01 ) as the original.
Do you know why that wouldn't work?
Thanks,
Carl

deva said...

Gr8 post........

Phil said...

Finally a GUI approach! Oracle types seem to hate non-command-prompt approaches...great post

Unknown said...

Hi,

I got this error during creating new dB as follow your instruction. Failed to unlock all EM-related account. Any suggestion? tq

akram said...

if i am cloning a database from prod server to dev server, how the dbca will identify my prod instance and datafile from dev server.

Unknown said...

I see that in Oracle 10, the source database is stopped whilst the template is created. So this is not necessarily a good option for cloning a production database.