Skip to Main Content
  • Questions
  • Attach existing Oracle datafile to database

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Kenneth.

Asked: January 02, 2005 - 10:50 am UTC

Last updated: June 29, 2006 - 7:18 am UTC

Version: 10g: 10.1.0.2

Viewed 10K+ times! This question is

You Asked

I have an Oracle 9iV2 datafile (.dbf file) that contains some tables that I would like to get into my 10g database.
If I create a new tablespace using the "use existing datafile" option and givinf the existing filename, I expect to see the data but I do not: The new space seems empty, and 10g does not recognise its initial size.
So, what is the easiest method of attaching an existing datafile to my database and getting hold of the table it contains ?

Many thanks
Ken.

and Tom said...

that'll never work - to say "just use the existing datafile"

the dictionary information, which we keep in system, that describes the segments in the file, how they are laid out, their names -- etc -- it is NOT in that datafile.


You can however use the EXP tool to "transport" the tablespace from 9i to 10g. Transporting will create a dmp file with this needed metadata, and let you copy the dbf files from 9i to 10g and reattach them.

If you have my book "Expert One on One Oracle" -- I go over doing that in some detail -- but a search for transportable tablespace on this site, or a peek at the Server Utilities guide (exp chapter) will cover it as well.

Rating

  (11 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Attach existing Oracle datafile to database (2)

Kenneth Spencer, January 03, 2005 - 9:43 am UTC

Thankyou for your helpful reply.

I have studied the "transport_tablespace" entries in your questions and answers and looked at the EXP parameters etc in the database utilities documentation. However, I am not there yet so I would like a little more help.

My Oracle 9iV2 datafile is not currently plugged into a 9i database as we no longer have 9i running.
Therefore, as I cannot export the tables from my datafile directly (EXP does not appear to accept a datafile filename, rather a tablespace name), I created a tablespace in our 10g database and added our existing 9iV2 datafile and set it to read-only status.

I ran EXP with "transport_tablespace=Y" and "tablespaces=old_tspace_name" and "rows=Y".
EXP reported the following (with other messages):
"Note: table data (rows) will not be exported." (Presumably this is correct).
It then appeared to export the various items of metadata, although no tables were listed. I allowed other options to be their defaults.

Then I ran IMP with "transport_tablespace=Y" and "tablespaces=old_tspace_name" and "datafile=old_tspace_name.dbf".
IMP reported the following (with other messages):
IMP-00003 Oracle error 1565 encountered.
ORA-01565 Error in identifying file "OLD_TSPACE_NAME.DBF"
ORA-27041 Unable to open file
OSD-04002 Unable to open file
O/S-Error The system cannot find the file specified.

I know that the file is present, and I have tried running IMP with the datafile attached to the 10g database and unnattached (in case the file was locked by Oracle).

I cannot see why the file cannot be found by IMP. May I ask for further help with this ?

Many thanks (and Happy New Year!)
Ken.

Tom Kyte
January 03, 2005 - 9:56 am UTC

needs to be plugged in.

otherwise that file is just a bunch of bytes and bits and not anything else.


You NEED to have 9i
You NEED to have this tablespace there in 9i
so you can use 9i EXP to create the metadata (we sort of need the data from the 9i SYSTEM TABLESPACE to tell us what the bits and bytes *mean* in that file)

Sorry -- but until you restore the 9i database -- that file is just a file, nothing more or less.

Attach existing Oracle datafile to database (3)

Kenneth Spencer, January 03, 2005 - 2:54 pm UTC

Thankyou again for replying.

I somehow thought that it might be the case. It is a pity because I was hoping I might be able to get at the data without having to reinstall Oracle 9i.

Dare I say it: In MS SQLServer you can take any datafile and simply "attach" it to your database with no real fuss or bother. Maybe in Oracle 11 we could feed in a request for "One-step attachment of datafiles into a database" ?

Thanks for your help.
Ken.

Tom Kyte
January 03, 2005 - 10:29 pm UTC

no you can't you have to "export" it out too.

else point us to the direct reference that refutes that.

Sql Server

John French, January 03, 2005 - 4:16 pm UTC

Sql Server does not attach a File to the Server. It does an automatic Import of the contents of the Export Dump just like Oracle.

Pity you know nothing about either databases. You have a job!!!!!!!!

Attach existing Oracle datafile to database (4)

Kenneth Spencer, January 03, 2005 - 6:44 pm UTC

John, maybe you didn't really intend your response to sound as uncharitable as it did !
And, while not wishing to make nor to prolong an argument with you, MS SQL Server Enterprise Manager menu options "Action -> All Tasks -> Attach Database ... " leads to a handy little dialogue that includes "MDF file of database to attach" including a browse button. I assure you that I have attached such a file without having run an export dump on the database that originally contained the file. Hence my comment !
As for how much I know about either database - I make no claims whatsoever on that score.

Many thanks.
Ken.

Tom Kyte
January 03, 2005 - 10:42 pm UTC

sql server doesn't store all data in a single mdf file, so what do you do when you have a real database with all of the files -- when THEIR DICTIONARY isn't there?


you have a single file from an oracle database -- without a dictionary, without the metadata..... it is just bits in a file.

and I believe you had to have used the sp_detach_db procedure to detach it no?

</code> http://databasejournal.com/features/mssql/article.php/2224361 <code>


seems there MIGHT be a special case when the entire database is a single file - however, now you would be comparing apples to flying toaster ovens as you don't HAVE the entire database in a single file.

And you cannot see any problem with this???

A reader, January 03, 2005 - 9:18 pm UTC

"I assure you that I have attached such a file without having run an export dump on the database that originally contained the file."

Granted I know very little about SQLServer. If it really is this easy, then this to me says that the database vendor has NO CONCEPT of security! Someone can simply take a copy of a data file without having to run any of the database utilities thus bypassing any kind security like EXP or OS privs would provide.

Sounds scary to me.

Attach existing Oracle datafile to database (5)

Kenneth Spencer, January 04, 2005 - 7:26 am UTC

Thankyou for the comments about SQLServer. Just to add - I didn't run the sp_detach_db procedure against the file and it is not a single file database. In fact I have attached several different datafiles to several databases using the menu option mentioned, in SQLServer 2k. Thinking back to SQLServer v6/6.5/7 I think you had to do it by running the procedures whereas in the later versions Enterprise Manager also had the option on its menus.

However, may I please get back to my Oracle question ?
I have accpted that I need to get the metadata from the original SYSTEM tablespace. As I still have all the datafiles (including the SYSTEM) from my 9i database, and if possible I wish to avoid reinstalling 10g, will 10g accept all the 9i datafiles if I were to temporarily move to the 9i files so i can then do the EXP ? or are you saying that I HAVE to reinstall 9i.

When I get an answer to that, I reckon I should close this correspondence eh ? At least for my part. And thanks for all the contributions !

Regards
Ken.



Tom Kyte
January 04, 2005 - 8:38 am UTC

you can restore the 9i database and upgrade it if you in fact have ALL of the files.

to Ken

bob, January 04, 2005 - 7:36 am UTC

as Tom said earlier, you have to reinstall 9i, and use the 9i exp tool to create the metadata from a living 9i instance.

Attach existing Oracle datafile to database (6 and last)

Kenneth Spencer, January 04, 2005 - 10:58 am UTC

I have all the files.
Many thanks !

Ken.

Remarks

reader, January 04, 2005 - 11:30 pm UTC

I don't mean to be a preacher, but one shouldn't comment on anybody's knowledge or judge anybody. I think the purpose of this website is to gain more and more knowledge and experience in order to make oracle world better & better. We should listen what the other person has to say or what is he experiencing.

Tom is doing a great job by sharing his precious knowledge and time with us, I think we should make a heavy use of it.

TTS from 9.2.0.5 DB into 9.2.0.6 DB

A reader, June 28, 2006 - 9:59 pm UTC

Hi Tom,

I need to refresh the Dev database (running on 9.2.0.6)
with ST database (running on 9.2.0.5).

My first apporach is using "Transportable tablespace feature" using export/import.

Question is, Will transportable tablespace method works across different Oracle9i releases ?


Thanks

Tom Kyte
June 29, 2006 - 7:18 am UTC

yes, backwards compatible.

9205 transports to 9206



Thanks

A reader, June 29, 2006 - 9:42 am UTC