Oracle export and import This is a featured page

Prerequisites/Requirements :


exp
and imp are utilities present in the $ORACLE_HOME/bin directory and are installed when Oracle is installed. Their prime purpose is to move logical objects out of and into the database respectively - for example dumping all of the tables owned by a user to a single file is achieved using the exp utility. It is important to distinguish between dumping data in this manner and backing up the database which is normally achieved using the rman utility.
Starting with Oracle 10g these two utilities are deprecated and the Oracle recommended alternatives are the data pump versions of these utilities which provide a number of new features including the ability to disconnect and reconnect to an interactive session (so a direct logon to the server isn't required) and improved performance. There are still a number of things that cannot be achieved with the data pump utilities - in particular exporting/importing across a named pipe which is a technique used by database administrators when the export file needs to be compressed on the fly or when one wishes to export directly to an import session.

Before executing these commands, the environment should be set correctly for the user in particular if the examples used on this page are followed the $ORACLE_HOME, $ORACLE_SID and $PATH environment variables need to be set appropriately in a unix environment and the %ORACLE_SID% environment variable needs to be set in a windows environment. If you login as the owner of the oracle software (usually the oracle user on unix) these are likely to have been set in the users profile. The Oracle Database instance needs to be up in order to export/import data. Type 'imp help=y' or 'exp help=y' for a detailed explanation of the available options for these utilities. Some brief examples follow to illustrate the usage of these utilities.


Using exp:

To export the entire database to a single file dba.dmp in the current directory.

- Login to server
exp SYSTEM/password FULL=y FILE=dba.dmp LOG=dba.log CONSISTENT=y
or
exp SYSTEM/password PARFILE=params.dat

where params.dat contains the following information

FILE=dba.dmp
GRANTS=y
FULL=y
ROWS=y
LOG=dba.log

To dump a single schema to disk (we use the scott example schema here)

- Login to server which has an Oracle client
exp <user>/<password> FIlE=scott.dmp OWNER=scott


To export specific tables to disk:

- Login to server which has an Oracle client
exp SYSTEM/password FIlE=expdat.dmp TABLES=(scott.emp,hr.countries)
-the above command uses two users : scott and hr
exp <user>/<password> FILE=scott.dmp TABLES=(emp,dept)
the above is only for one user

Using imp:

To import the full database exported in the example above.

imp SYSTEM/password FULL=y FIlE=dba.dmp

To import just the dept and emp tables from the scott schema

imp SYSTEM/password FIlE=dba.dmp FROMUSER=scott TABLES=(dept,emp)

To import tables and change the owner
imp SYSTEM/password FROMUSER=blake TOUSER=scott FILE=blake.dmp TABLES=(unit,manager)


To import just the scott schema exported in the example above

imp <user>/<password> FIlE=scott.dmp

If you do not supply any parameters then you enter an interactive session as illustrated below. (Responses to prompts are shown in blue. from the prompt type imp and press enter

$>imp
Import: Release 9.2.0.6.0 - Production on Thu Mar 29 15:07:43 2007
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Username: SYSTEM
Password: password
Connected to: Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.6.0 - Production
Import file: expdat.dmp > /mention/path/of/dumpFile/includingFileName.dmp
Enter insert buffer size (minimum is 8192) 30720> (press enter to accept default)
Export file created by EXPORT:V09.02.00 via conventional path
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
List contents of import file only (yes/no): no > press enter
Ignore create error due to object existence (yes/no): no > press enter
Import grants (yes/no): yes > press enter
Import table data (yes/no): yes > press enter
Import entire export file (yes/no): no > press enter or type no
Username: give the userName for which you want the data to be imported
Enter table(T) or partition(T:P) names. Null list means all tables for user
Enter table(T) or partition(T:P) name or . if done: press enter
. importing TST_001_V2's objects into TST_001_V2


Good practices
  • Always take care about CHARSETS when you do export and import. Using the wrong ones can convert your data in a lossy manner. The best situation is when your source and destination database have the same character sets, so you can avoid completely any character conversion. You control this behaviour by setting NLS_LANG environment variable appropriately. When not set properly you may see 'Exporting questionable statistics' messages.
  • After doing an export, it is better to check your dump by doing an import with the parameter SHOW=Y. This checks the validity of your dump file.

Other considerations
  • You may need to patch your Oracle client (where you are running exp/imp) to the same level as the Oracle server to prevent errors
  • When importing large amounts of data consider dropping indexes prior to the import to speed up the process and re-creating them once the import is completed
  • The amount of archivelogs that may be created on a large import may fill up your disk
  • On INSERT triggers will fire, consider whether these need to be disabled
  • Increasing the RECORDLENGTH (max 65535) parameter can improve the length of time to perform an import/export as well as DIRECT=y for export



No user avatar
d0hboy
Latest page update: made by d0hboy , Jan 27 2009, 12:36 PM EST (about this update About This Update d0hboy Edited by d0hboy

2 words added
2 words deleted

view changes

- complete history)
More Info: links to this page
Started By Thread Subject Replies Last Post
JohnKK try this 0 May 11 2009, 6:38 AM EDT by JohnKK
Thread started: May 11 2009, 6:38 AM EDT  Watch
hey~why not try this export/Import tool - [www.navicat.com]. It has schedule import and other powerful features.
I am not sure if this will totaly answer your question but it may be of some help.
Do you find this valuable?    
Keyword tags: None
fatsoft ho Import data into a database existing 0 May 9 2009, 3:21 PM EDT by fatsoft
Thread started: May 9 2009, 3:21 PM EDT  Watch
I have a program for the company
This company is more than one section and the database is the same status in each section
Ardid and that the imported data from the branches every day or as needed to the database in the Head Office and sent via Aldata Balimiol for example, how can I, and no error message that the data already exists or tables
Please help put an example of that, thanks
fatah_q@yahoo.com
3  out of 3 found this valuable. Do you?    
Keyword tags: None
osde8info EXP & IMP only restores to same tablespace(s) 3 Apr 24 2009, 8:59 AM EDT by luciofer
Thread started: Mar 12 2008, 8:12 AM EDT  Watch
so if you want to restore/move tables to new tablespaces you must do this manually afterwards :

CREATE SMALLFILE TABLESPACE "USERS_REORG0" DATAFILE '/u1/app/mydb/users01_reorg0.dbf' SIZE 20M
REUSE AUTOEXTEND ON NEXT 2M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO

ALTER TABLE "SCOTT"."DEPT" MOVE TABLESPACE "USERS_REORG0"
ALTER INDEX "SCOTT"."PK_DEPT" REBUILD TABLESPACE "USERS_REORG0"

ALTER TABLE "SCOTT"."EMP" MOVE TABLESPACE "USERS_REORG0"
ALTER INDEX "SCOTT"."PK_EMP" REBUILD TABLESPACE "USERS_REORG0"

etc
etc
22  out of 24 found this valuable. Do you?    
Show Last Reply
Showing 3 of 3 threads for this page

Related Content

  (what's this?Related ContentThanks to keyword tags, links to related pages and threads are added to the bottom of your pages. Up to 15 links are shown, determined by matching tags and by how recently the content was updated; keeping the most current at the top. Share your feedback on Wetpaint Central.)