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)
Hi,
You should grant read and write permission on directory object.
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…
oh! And thanks a lot for the comment : )
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
If you are on windows, you can map a network destination to a drive letter and then use it as your destination.
N ico
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
@Alzebdeh
The directory parameter for impdp is the directory where your dump file is stored, not where it originated.
Hello Nico,
What if you wish to export the entire database and not just tables?
Jojo
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
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
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
Thank you for the answer and caution. The latter has been taken in good faith.
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
———————————————————————————-
I have exported out a full production schema in a downtime window.
Now I realize that I donot have enough space in the test database, so I want to exclude out some unimportant tables while doing impdp. (I can not take another expdp for a week).
How to exclude out the tables during impdp that exist in the expdp dmp files?
thanks for you help!
Hello,
if you got the data in your dump file then you can extract whatever you want from it.
You might not be able to do an exclude list but you can definitely do an include list using the TABLES= my,list,of,tables
If your DB is well organized you can then pick just the schema you need.
Nico