Friday, January 22, 2010

Thursday, January 14, 2010

How to restore an Oracle database from its original files

Background:
I recently had to bring an Oracle database online from its original files an old laptop hard drive. It had some data on it that I needed to get off, and as usual, Oracle is anything but straightforward. This post describes how I ended up doing it.
To start with, I had to connect the old hard drive to the machine. I did this with a USB-SATA2.5" external adapter. You can find hard drive multi-adapters like these on newegg or any other online hardware store for around $20 - $30.

Running:
- Windows XP SP3
- Oracle 10g

Solution Steps:
1) Locate your current Oracle database files. The default location for this is C:\oracle\product\10.2.0\oradata. Each folder in that directory contains the data files for the database by the same name.

2) I'll call the database you're trying to restore "OldDatabase". If the path for OldDatabase folder was different from your current Oracle data folders, this might not work (but of course the drive letter will be different if you're using an old disk drive via USB). If it doesn't work, see if you can install Oracle into a directory on the new machine that has the same path as the old one had.

3) Make sure you don't have any databases in your current Oracle installation that have the same name as OldDatabase. If they match and you continue anyways, things will get very screwed up. If you do have a match, see if you can migrate the matching new one to another new database with a different name. You might want to back up that db's files first.

4) Now, go ahead and create a new database with all the default settings and the same name as OldDatabase. You can do this via the Database Configuration Assistant that should have been included with your Oracle installation. I found mine under Start > All Programs > Oracle - OraDb10g_home1 > Configuration and Migration Tools.

5) Go into your Administration Assistant for Windows (in the same start menu folder as the Database Config Assist.) and find your newly created database, right click it, and choose Stop Service.

6) The data files for the new database you just created are now in your current oradata folder. Copy the contents of your old OldDatabase folder into the new one by the same name, replacing all files (you might want to back up your new folder first).

7) Back in the Admin. Assist., right-click your new database and choose Start Service. With any luck, you'll be able to connect to it in a few moments, and it will look just like your old database!

Hope this helps!