Skip to Main Content
  • Questions
  • IMPORT OF SELECT TABLES FROM A BACKUP DUMP FILE

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Subra.

Asked: February 01, 2010 - 9:43 am UTC

Last updated: February 25, 2013 - 11:28 am UTC

Version: 10.2.0.4

Viewed 10K+ times! This question is

You Asked

Hello Tom

Pleasant surprise for me. I knew I had nowhere to go but you to ask for an efficient solution (to a big mess) and luckily, you were accepting questions when I logged in to check. Thanks.

I want to import about 200 tables (into a schema of about 3500) tables from a backup dump file. Unfortunately we cannot rollback the whole database to that point of restore and our only available route is import the before-image data from the backed up dump file. (traditional export and not even data pump).

The problem here is there are hundreds of other tables (besides many in this set of 200 tables) that are referencing these tables via foreign key constraints and some of them with ON DELETE cascade. We cannot afford to lose even a single record from any of the child tables. Basically, I have to delete the data from these 200 tables and import from the dump file.

Can you please suggest the most fail-proof solution?

Thanks a lot

and Tom said...

... from a backup dump file. ...

no such thing exists of course since a dmp file is from export and export is incapable of making backups.

Export can make a logical copy of data, but that is all - never will it create a backup.


... Can you please suggest the most fail-proof solution? ...

there isn't one, you are asking the impossible.

You'll have to drop the referencing foreign keys.
So you can truncate the 200 tables.
So you can import them.
So you can then reinstate the foreign keys - probably with exceptions into (look up the foreign key constraint to see what that is) so you can see the records that have no parents and figure out what to do with them.


Don't forget, if you don't have to go too far back in time, you might be able to use FLASHBACK TABLE.


Rating

  (8 ratings)

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

Comments

Your feedback means everything

Subra, February 01, 2010 - 4:30 pm UTC

Hello Tom

First of all thanks for your response. There's no doubt Export is not a backup. Nor do we treat that as one. I am a proud owner of your invaluable books (or should I call my bible) and I have no doubt that export can even be called a backup. However the situation we have demanded me to check with you if you had anything "magical" to resolve it. With our business needs, we cannot roll back using RMAN backups or even flashback to that state as we want to go 3 weeks backwards. I have already told the business that it's not just possible to restore it, let alone, cleanly. If there's only direction to go (either do or die), I said I could do it but wouldn't guarantee a clean restore.

My desperate strategy was:

1) I generate script for all foreign/unique/primary key constraints and back it up.
2) Delete all foreign key constraints (about 3345 of them)
3) truncate these 200 tables
4) import the data back from the dump
5) Create all the foreign keys but enable novalidate. If I have to make it validate, I am talking about few days here with all 250 GB partitioned tables. The total size of the database is 14 TB.

This will not only cause a problem to our restored tables but also to the entire application which is 24x7 and bread and butter of the business. But that's where we stand now.

Anyway, thanks for your invaluable time.

Regards






Tom Kyte
February 02, 2010 - 10:46 am UTC

... This will not only cause a problem to our restored tables but also to the
entire application which is 24x7 and bread and butter of the business. But
that's where we stand now.
...

it will not only cause a problem, it will make the application a complete wasteland.

You'll have NO data integrity. None.


Your bread with the butter on it, just fell on the floor. Butter side down.


I fail to see how you can restore 200 out of 3,500 tables - all related to each other - and expect it to work.

good luck I guess is all I can say.

IMPORT OF SELECT TABLES FROM A BACKUP DUMP FILE

Massimo Galavotti, February 02, 2010 - 11:39 am UTC

You can use this syntax

CREATE TABLE OT_DMP
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY STAGE_DIR
ACCESS PARAMETERS
( )
LOCATION (STAGE_DIR:'OT.DMP')
)
AS (SELECT * FROM OT);

where OT.DMP is an oracle datapump file and STAGE_DIR is an oracle directory object that point to the direcoty where is the OT.DMP file
Tom Kyte
February 02, 2010 - 12:35 pm UTC

how would that help them?

They can import the data, that is rather straight forward.

Their issue is they want to do 200 out of 3500 tables - all linked by referential integrity - which will be completely blown away by doing only 200 out of 3500 tables - destroying their data integrity

IMPORT OF SELECT TABLES FROM A BACKUP DUMP FILE

Massimo Galavotti, February 02, 2010 - 11:49 am UTC

Or this syntax :

CREATE TABLE OT_EXT
(
FLSYS VARCHAR2(1 BYTE),
CSI_ID NUMBER(16),
ISTA_VERSTATO NUMBER(16),
ITER_ID NUMBER(3),
AZ_ID VARCHAR2(2 BYTE),
OT_ID NUMBER(6),
VER_DTINI TIMESTAMP(0),
VER_DTFINE TIMESTAMP(0),
OT_DES VARCHAR2(70 BYTE),
OT_DESSTA VARCHAR2(250 BYTE),
SER_ID VARCHAR2(2 BYTE),
CATCOMSER_ID NUMBER(3),
COMSER_ID NUMBER(3),
OT_IDEXT VARCHAR2(25 BYTE),
OT_FLTIPOOT VARCHAR2(1 BYTE),
OT_NOTE VARCHAR2(250 BYTE),
SOG_ID NUMBER(10),
TSOG_ID NUMBER(3)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY STAGE_DIR
ACCESS PARAMETERS
( LOGFILE 'ot_read.log' )
LOCATION (STAGE_DIR:'OT.DMP')
)
REJECT LIMIT 0;

You can read the manual for a full explain of syntax.

Best Regards

@Massimo

Alexander, February 02, 2010 - 11:51 am UTC

He said he has an exp, not a expdb. Doubt you can use an external table against that.

He could however, restore a backup to a test database to the desired point in time, Then use expdb, then use the external table, THEN write a bunch of custom code to put things back.

I think I'd rather fight Mike Tyson than go through that though.

Desperate measures

Jason Martin, February 02, 2010 - 2:51 pm UTC

If you have FK constraints referencing these 200 tables, and know that there will be 'missing' rows after you restore them, then you have no way to maintain consistency. Setting novalidate may not work as your application may not handle the missing parent keys gracefully, or it may not help in that your app will try to join tables together and the parentless rows will be invisible to the app.

One thought is to load the tables into a different schema and do some sort of MERGE operation to the 'live' tables, if that makes any logical sense for your schema.

Nightmare

Subra, February 03, 2010 - 6:56 am UTC

Don't think I can run a merge on 200 tables and even if I manage to spend 20 hours writing scripts for that, there's no guarantee that I will be able to re-enable validate the foreign keys.

So we'll have to wait what Business have to say about this. If it was notified immediately, we could have done a restore of database up to that point but it's too late.


external table

sumit, February 23, 2013 - 3:30 am UTC

CREATE TABLE OT_DMP
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY "/dmfiles_new/Statements/"
ACCESS PARAMETERS
( )
LOCATION ("/dmfiles_new/Statements/":'OT.DMP')
)
AS (SELECT * FROM emp);


Hello here i want data from table into file so..in directory path "dup" file is generating but i am unable to see or open this file..
please help me how to see the data.i tried with txt file also..
Tom Kyte
February 25, 2013 - 11:25 am UTC

it is a binary file, it is in datapump format - so there is nothing for you to see here.

you can use the unix utility strings on it to see "some" stuff.


but if you just cannot "see" it, it would be a permissions issue, you'll need your DBA to help you out.

Although you should be able to "bfile" it and read it using plsql just to prove it exists.

external table

sumit, February 23, 2013 - 4:53 am UTC

now i able to see this dmp file but like this what is this and i need in txt format what to do for that.please reply
<ROWSET>
<ROW>
<STRMTABLE_T>
<VERS_MAJOR>1</VERS_MAJOR>
<VERS_MINOR>0 </VERS_MINOR>
<VERS_DPAPI>3</VERS_DPAPI>
<ENDIANNESS>0</ENDIANNESS>
<CHARSET>AL32UTF8</CHARSET>
<NCHARSET>AL16UTF16</NCHARSET>
<DBTIMEZONE>+05:30</DBTIMEZONE>
<OWNER_NAME>DM32TEST</OWNER_NAME>
<NAME>TEST_TEST1</NAME>
<COL_LIST>
<COL_LIST_ITEM>
<COL_NUM>1</COL_NUM>
<NAME>COUNTRY_CODE</NAME>
<TYPE_NUM>1</TYPE_NUM>
<LENGTH>5</LENGTH>
<PRECISION_NUM>0</PRECISION_NUM>
<SCALE>0</SCALE>
<CHARSETID>873</CHARSETID>
<CHARSETFORM>1</CHARSETFORM>
<CHARLENGTH>5</CHARLENGTH>
</COL_LIST_ITEM>
<COL_LIST_ITEM>
<COL_NUM>2</COL_NUM>
<NAME>COUNTRY_NAME</NAME>
<TYPE_NUM>1</TYPE_NUM>
<LENGTH>50</LENGTH>
<PRECISION_NUM>0</PRECISION_NUM>
<SCALE>0</SCALE>
<CHARSETID>873</CHARSETID>
<CHARSETFORM>1</CHARSETFORM>
<CHARLENGTH>50</CHARLENGTH>
</COL_LIST_ITEM>
<COL_LIST_ITEM>
<COL_NUM>3</COL_NUM>
<NAME>COUNTRY_LANGUAGE</NAME>
<TYPE_NUM>1</TYPE_NUM>
<LENGTH>50</LENGTH>
<PRECISION_NUM>0</PRECISION_NUM>
<SCALE>0</SCALE>
<CHARSETID>873</CHARSETID>
<CHARSETFORM>1</CHARSETFORM>
<CHARLENGTH>50</CHARLENGTH>
</COL_LIST_ITEM>
</COL_LIST>
</STRMTABLE_T>
</ROW>
</ROWSET>

Tom Kyte
February 25, 2013 - 11:28 am UTC

external tables with datapump format are binary, they are not text files. there is no "sql command" to create a flat file.

see
http://asktom.oracle.com/Misc/httpasktomoraclecomtkyteflat.html

if you want a simple data unloader to a flat file.


If you want to move this data to another oracle database, just copy the file and issue a create table statement to be able to query it.

More to Explore

Data Pump

All of the database utilities including Data Pump are explained in the Utilities guide.