23
Jan
07

expdp and impdp are great

Before oracle 10g, there was exp and imp tools. They are good export and import tools but I had only one problem with them.

In Thailand, people tend to put all tables in the same schema even if it’s a different application. That is simply because they don’t know any better.

For better administration and security, I want my tables splitted per application in different schemas with limited access to other schemas if required. Additionally to that, I would like to have those tables in a separated tablespace (and datafile).

exp/imp tool allows to move tables from one schema to another schema and the option is logically called fromuser/touser.

The problem is that if I wanted to move the tables to another tabelspace it was a little more tricky. It involves generating the script of the tables using the exp tool. Modify them manually by changing the targetted tablespace and then run them in sqlplus to generate the tables in the new schema and new tablespace.

With expdp and impdp, I can first select the tables I want to move (that will be the same as before using tables option).

The greatness comes with impdp where I can mention the following options: REMAP_SCHEMA (a bit like the fromuser/touser of imp) and REMAP_TABLESPACE. That is really cool.

I had a bit of trouble getting expdp and impdp to work. The thing is that before using them , the DBA must create a directory as follow:

C:\ sqlplus / as sysdba

SQL>CREATE DIRECTORY DATA_PUMP_DIR AS ‘A VALID DIRECTORY’;

SQL>COMMIT;

In my opinion, the commit is not required because create directory is a ddl command. But I was struggling and I saw an example doing like this. I’m not too sure what worked because I had to drop the directory first (just like we drop a table but we mention directory instead) and recreate it. So it might be it or might not. If anyone got any idea, I’m happy to know and the comments would do marvel for this : )

lLet’s get back to work.

It is now possible to call expdp

C:\ expdp system\acomplexepassword@tnsname directory=data_pump_dir dumpfile=Mydump%U.dmp tables=my,big,list,of,tables

And here you go. Your data are exported.

Then use the impdp command as follow:

C:\ impdp system\acomplexepassword@tnsname directory=data_pump_dir dumpfile=mydump01.dmp remap_schema=source_schema:dest_schema remap_tablespace=source_tablespace:dest_tablespace

And this is it.

In 2 command lines, what would have been otherwise a complexe situation becomes very easy.

note:

1) If you don’t have the data_pump_dir directory specified the you’ll get error messages

ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-39087: directory name DATA_PUMP_DIR is invalid

2) The dumpfile name in impdp is called dump01.dmp because I specified the variable %U in the name at export time. It’s an increment. It means you can keep the same name, if the file already exists in the directory then dump02.dmp will be created etc…

3) A valid directory in the example above is a directory that exists on your server (such as D:\dumps)


13 Responses to “expdp and impdp are great”


  1. 1 Siddhartha
    March 3, 2007 at 7:47 am

    Hi,

    You should grant read and write permission on directory object.

  2. April 4, 2007 at 7:14 am

    Hi.

    You are right. That would be for a *nix system though (How I wish my company use it).

    But on windows it’s pretty much open…

  3. April 4, 2007 at 7:14 am

    oh! And thanks a lot for the comment : )

  4. 4 Niraj
    June 26, 2007 at 1:39 pm

    Hi All,

    It is good , but i like to generate my .dmp file in destination server.

    Example.

    From svr01 i m taking export dump (expdp) of svr02(sid->BEA)

    How can ii do that.
    Please assist.

    Thanks
    -Niraj

  5. October 25, 2007 at 6:04 am

    If you are on windows, you can map a network destination to a drive letter and then use it as your destination.

    N ico

  6. 6 Alzebdeh
    March 14, 2008 at 6:16 am

    Hello,
    What if I got the dump from the DBA and wanted to apply the impdp on my personal PC and I do not know the name of the directory and I have only the dump. Then what to do and how to import the file to my local database?

    Alzebdeh

  7. 7 Victor
    June 25, 2008 at 6:25 pm

    @Alzebdeh

    The directory parameter for impdp is the directory where your dump file is stored, not where it originated.

  8. 8 jojo
    January 13, 2009 at 8:23 pm

    Hello Nico,

    What if you wish to export the entire database and not just tables?

    Jojo

  9. January 14, 2009 at 3:22 am

    Hi.

    set oracle_sid=[oraclesid]

    expdp help=y

    if not 10g then exp help = y

    either way there’s an option full=y

    expdp userid=nicolas/goodpassword directory=oracle_configured_directory file=test.dmp full=y

    not sure to remember exactly the parameter name but you should be able to square that up with expdp help=y.

    Of course it works the other way around: imp help=y and impdp help=y

    impdp is a new tool coming with 10g. Use it preferably.

    regards,

    Nico

  10. 10 jojo
    January 14, 2009 at 5:52 am

    Hello Nico,

    Thank you for the information. I looked up the syntax and below is what I found.

    “expdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=expdpDB10G.log

    Please permit me to ask these questions – i am a newbie in these tasks,

    1) does it mean that the data now resides in DB10G.dmp (w.r.t to example above).

    2) if yes, does it also mean that the exported database (DB10G.dmp) could be imported into Oracle Express Edition (for example) with the code below – and the exact copy restored with doing additional work (e.g. copying control files ect)?

    impdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=impdpDB10G.log

    3) I guess the original database remains intact – i.e. upon using “expdp”

    I would appreciate usual prompt response.

    Regards
    Emmanuel

  11. January 15, 2009 at 12:27 am

    Hi again,

    provided you’ve created TEST_DIR, yes it should :)

    1) Yes it means that all schemas are now in DB10G.dmp however, the impdp won’t create a new DB and table spaces for you

    2) related to 1), before you are able to import, you will have to create the tablespace if they don’t exist yet. The easiest way to know what’s missing is to run the command and look for errors.

    3) The database is untouched when working with expdp. And if you did use impdp on your production database, it wouldn’t transfer the data if the table already exists unless you specified so.

    note: Don’t specify usual prompt response >< I’m not working for you. I do it because it pleases me. The best you could get from it is a non response…

    Nico

  12. 12 jojo
    January 18, 2009 at 1:14 pm

    Thank you for the answer and caution. The latter has been taken in good faith.

  13. 13 jojo
    January 18, 2009 at 3:38 pm

    Hello Nico,

    Please, any help on the error messages below?

    ————————————————————————————
    ;;;
    Export: Release 10.2.0.1.0 – Production on Sunday, 18 January, 2009 15:46:53

    Copyright (c) 2003, 2005, Oracle. All rights reserved.
    ;;;
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – Production
    With the Partitioning, OLAP and Data Mining options
    Starting “JOJO”.”SYS_EXPORT_FULL_01″: jojo/********@masterit full=y include=grant include=index directory=item_dir dumpfile=jojo.dmp content=all
    Estimate in progress using BLOCKS method…
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
    Total estimation using BLOCKS method: 0 KB
    Processing object type DATABASE_EXPORT/GRANT/SYSTEM_GRANT/PROC_SYSTEM_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/GRANT/SYSTEM_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/SEQUENCE/GRANT/OWNER_GRANT/OBJECT_GRANT
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4845,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4844,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4843,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    Processing object type DATABASE_EXPORT/SYSTEM_PROCOBJACT/GRANT/PROCOBJ_GRANT
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4845,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4844,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4843,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/GRANT/CROSS_SCHEMA/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
    Processing object type DATABASE_EXPORT/SCHEMA/PACKAGE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/FUNCTION/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/PROCEDURE/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/VIEW/GRANT/OWNER_GRANT/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/VIEW/GRANT/CROSS_SCHEMA/OBJECT_GRANT
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/FUNCTIONAL_AND_BITMAP/INDEX
    Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/FUNCTIONAL_AND_BITMAP/INDEX_STATISTICS
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4845,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4844,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    ORA-39127: unexpected error from call to export_string := SYS.DBMS_RMGR_GROUP_EXPORT.grant_exp(4843,1,…)
    ORA-06502: PL/SQL: numeric or value error: NULL index table key value
    ORA-06512: at “SYS.DBMS_RMGR_GROUP_EXPORT”, line 130
    ORA-06512: at line 1
    ORA-06512: at “SYS.DBMS_METADATA”, line 5111
    Master table “JOJO”.”SYS_EXPORT_FULL_01″ successfully loaded/unloaded
    ******************************************************************************
    Dump file set for JOJO.SYS_EXPORT_FULL_01 is:
    C:\EXP_ITEM\JOJO.DMP
    Job “JOJO”.”SYS_EXPORT_FULL_01″ completed with 9 error(s) at 15:47:25
    ———————————————————————————-


Leave a Reply




 

January 2007
M T W T F S S
« Oct   Feb »
1234567
891011121314
15161718192021
22232425262728
293031  

Pages

a

Blog Stats

  • 145,900 DB lovers