Saturday, October 19, 2013

[Oracle] Import Database Dumps using "impdp" command

Below are few commands to import database dump in Oracle 11g.

--1. Drop existing user, if already exists:
DROP USER <dest_db> CASCADE;

--2. Create user and schema and grant rights:
CREATE USER <dest_db> PROFILE "DEFAULT" IDENTIFIED BY <password> 
     TEMPORARY TABLESPACE "TEMP" ACCOUNT UNLOCK ;
GRANT "RESOURCE", "CONNECT", "DBA" TO <dest_db>;

--3. test if impdp is support, from command prompt, just write:
impdp

/*it should say:
Import: Release 11.2.0.1.0 - Production on Sat Feb 16 21:13:27 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
*/

--4. To import through dmp file, from command prompt, just write:
impdp <Dest_db>/<password> remap_schema=<source_db>:<dest_db> directory=DATA_PUMP_DIR EXCLUDE=STATISTICS dumpfile=<source_db_dumpfile>.dmp

--where, DATA_PUMP_DIR is the default Oracle directory. To verify write:
select * from ALL_DIRECTORIES

--5. If it says tablespace <tablespace> doesnot exists, then use:
impdp <dest_db>/<password> remap_schema=<source_db>:<dest_db> remap_tablespace=<dest_tablespace>:<source_tablespace> directory=DATA_PUMP_DIR EXCLUDE=STATISTICS dumpfile=<source_db_dumpfile>.dmp

-- where USERS is the table space of destination user, to verify:
select default_tablespace from dba_users where username='<dest_db>';

--6. If it says "only one COMPRESS or NOCOMPRESS clause may be specified", then use following command:
impdp <dest_db>/<password> remap_schema=<source_db>:<dest_db> remap_tablespace=<dest_tablespace>:<source_tablespace> directory=DATA_PUMP_DIR EXCLUDE=STATISTICS dumpfile=<source_db_dumpfile>.dmp transform=segment_attributes:n 

--7. Verify if import is successful by getting the object count both valid/invalid.
select count(*) from user_objects;
select count(*) from user_objects where status='INVALID';

Enjoy!

No comments:

Post a Comment