Search code examples
importoracle10gimpdp

Oracle: importing data pump dump without knowledge dump file content


Old approach for exporting/importing whole schema:

 exp user/pwdp@server FILE=export.dmp OWNER=user ROWS=Y
 imp newuser/pwd@server FULL=Y FILE=export.dmp

New approach:

 expdp user/pwdp@server DUMPFILE=export.dp DIRECTORY=exportfolder 

However had a problem with importing:

 impdp newuser/pwdp@server DUMPFILE=export.dp DIRECTORY=exportfolder

will not import anything:

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORA-31655: no data or metadata objects selected for job
ORA-39154: Objects from foreign schemas have been removed from import
Master table "NEWUSER"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "NEWUSER"."SYS_IMPORT_FULL_01":  newuser/********@server
DUMPFILE=export.dp DIRECTORY=exportfolder
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Job "NEWUSER"."SYS_IMPORT_FULL_01" successfully completed at 19:13:04

Adding schemas option will not help (result is same, oracle does not allow import non-owned objects):

impdp newuser/pwdp@server DUMPFILE=export.dp DIRECTORY=exportfolder schemas=user

And only one working approach which I found:

impdp newuser/pwdp@server DUMPFILE=export.dp DIRECTORY=exportfolder remap_schema=newuser:user

So the question is how to import schema data pump dump without knowledge which schema was exported?

(Of course I can look to first 512 bytes of export file and find string like "USER"."SYS_EXPORT_SCHEMA_01"), but may be exists another approach?


Solution

  • First, technically you are not using the full=y correctly:

    imp newuser/pwd@server FULL=Y FILE=export.dmp
    

    You should rather do:

    imp newuser/pwd@server touser=newuser fromuser=user FILE=export.dmp
    

    Which is similar to impdp remap_schema command.

    However, I do understand that what you are trying to do is import a schema from one user to the other without knowing the source user before hand. I just had to mention this because if you don't know the source user, then it can be easily assumed you don't know the content of the datafile; and if you don't know the content of the datafile, you could be importing a lot more users and data than you think you ought to by issuing a full=y.

    Point: A full=y import means to import every user and their associated content; regardless of the user you are using to log into the database and start the import.

    Having said my disclaimer, impdp has the exact same functionality in respect to a full import - just use full=y

    impdp newuser/pwdp@server DUMPFILE=export.dp DIRECTORY=exportfolder full=y
    

    UPDATE

    this will works in newuser have privilege: IMP_FULL_DATABASE
    
    execution `grant IMP_FULL_DATABASE to newuser` solved it.
    

    References: http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_import.htm#sthref301