Showing posts with label emp/dmp. Show all posts
Showing posts with label emp/dmp. Show all posts

Friday, 8 March 2013

DATA PUMP ARCHITECTURE AND STEPS TO PERFORME EXPORT/IMPORT USING DATAPUMP


INTRODUCTION
Oracle Data pump utility enables very fast bulk data and metadata movement between Oracle databases. It provides parallel Export and Import utilities (expdp and impdp) and Web-based Oracle Enterprise Manager Interface.Data Pump Export and Import utilities are typically much faster than the original Export and Import Utilities. A single thread of Data Pump Export is about twice as fast as original Export, while Data Pump Import is 15-45 times fast than original Import.Data Pump jobs can be restarted without loss of data, whether or not the stoppage was voluntary or involuntary.Data Pump jobs support fine-grained object selection. Virtually any type of object can be included or excluded in a Data Pump job. Data Pump supports the ability to load one instance directly from another (network import) and unload a remote instance (network export).

DATA PUMP ARCHITECTURE
Oracle Data Pump is made up of three distinct parts:
•              The command-line clients, expdp and impdp
•              The DBMS_DATAPUMP PL/SQL package (also known as the Data Pump API)
•              The DBMS_METADATA PL/SQL package (also known as the Metadata API) 
EXPDP – Client interface to the Data Pump Export utility. The interface closely resembles its predecessor, Oracle Export.
IMPDP – Client interface to the Data Pump Import utility. The interface closely resembles its predecessor, Oracle Import.
Grid Control Interface – This is a web based interface, which provides access to the DBMS_DATA_PUMP PL/SQL package.
STEPS:
Creating Directory Objects
In order to use Data Pump, the database administrator must create a directory object and grant privileges to the user on that directory object. If a directory object is not specified, a default directory object called data_pump_dir is provided. The default Data_pump_dir is available only to privileged users unless access is granted by the DBA.
CONN / AS SYSDBA
CREATE OR REPLACE DIRECTORY test_dir AS '/u01/app/oracle/oradata/';

After a directory is created, we need to grant READ and WRITE permission on the directory to other users. For example, to allow the Oracle database to read and to write to files on behalf of user test in the directory named by test_dir, you must execute the following command:
GRANT READ, WRITE ON DIRECTORY test_dir TO test;
Once the directory is granted, we can export a user’s object with command arguments that are very similar to exp and imp:
Schema Exports/Imports
The OWNER parameter of exp has been replaced by the SCHEMAS parameter which is used to specify the schemas to be exported. The following is an example of the schema export and import syntax.
expdp test/test@tsn schemas=TEST directory=TEST_DIR dumpfile=TEST.dmp logfile=expdpTEST.log
impdp test/test@tsn schemas=TEST directory=TEST_DIR dumpfile=TEST.dmp logfile=impdpTEST.log

Table Exports/Imports
The TABLES parameter is used to specify the tables that are to be exported. The following is an example of the table export and import syntax.

expdp test/test@tsn tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=expdpEMP_DEPT.log
impdp test/test@tsn tables=EMP,DEPT directory=TEST_DIR dumpfile=EMP_DEPT.dmp logfile=impdpEMP_DEPT.log

TABLE_EXISTS_ACTION – The original imp would allow rows to be appended to existing tables if IGNORE=Y was specified. The TABLE_EXISTS_ACTION parameter for Data Pump impdp provides four options:
1. SKIP is the default: A table is skipped if it already exists.
2. APPEND will append rows if the target table’s geometry is compatible.
3. TRUNCATE will truncate the table, then load rows from the source if the geometries     are compatible and truncation is possible. For example, it is not possible to truncate a table if it is the target of referential constraints.
4. REPLACE will drop the existing table, then create and load it from the source.
INCLUDE and EXCLUDE
The INCLUDE and EXCLUDE parameters can be used to limit the export/import to specific objects. When the INCLUDE parameter is used, only those objects specified by it will be included in the export/import. When the EXCLUDE parameter is used, all objects except those specified by it will be included in the export/import. The two parameters are mutually exclusive, so use the parameter that requires the least entries to give you the result you require. The basic syntax for both parameters is the same. 
expdp test/test@tsn schemas=TEST include=TABLE:"IN ('EMP', 'DEPT')" directory=TEST_DIR dumpfile=TEST.dmp logfile=expdpTEST.log
expdp test/test@tsn schemas=TEST exclude=TABLE:"= 'BONUS'" directory=TEST_DIR dumpfile=TEST.dmp
logfile=expdpTEST.log
Other filters
INCLUDE=VIEW
INCLUDE=PACKAGE:"LIKE '%API'"

Network Exports/Imports (NETWORK_LINK)
The NETWORK_LINK parameter identifies a database link to be used as the source for a network export/import. The following database link will be used to demonstrate its use.
1)             Create database link
CONN test/test
CREATE DATABASE LINK remote_test CONNECT TO test IDENTIFIED BY test USING 'TEST';
2)             Export data using database link
expdp test/test@tsn tables=TEST.EMP network_link=REMOTE_TEST directory=TEST_DIR dumpfile=EMP.dmp logfile=expdpEMP.log
3)               Import data using database link
impdp test/test@tsn tables=TEST.EMP network_link=REMOTE_TEST directory=TEST_DIR logfile=impdpTEST.log remap_schema=TEST:TEST_NEW
We can Imports the objects directly from the source into the local server without being written to a dump file.
Attaching to and Stopping an Existing Job
The ATTACH command attaches the client session to an existing export job and  automatically places you in the interactive-command interface. Export displays a description of the job to which you are attached and also displays the export prompt. A
job name does not have to be specified if there is only one export job that is associated with your schema. The job you attach to can be either currently executing or stopped
Attach /Detach job in case of Export:-
A)            You have  started the export job
expdp mm_stg/mm_stg dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log schemas=mm_stg job_name=SYS_EXPORT_SCHEMA
B)            If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATE
Are you sure you wish to stop this job ([yes]/no): yes
C)             Now you want to restart the job then you need to attach the job
         $ expdp mm_stg/mm_stg attach=SYS_EXPORT_SCHEMA
          Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT

Attach /Detach job in case of Import:-
A)            You have  started the import job
impdp system/sys dumpfile=DPUMP:export3.dmp logfile=DPUMP:export2.log job_name=OEM_NEW_USER_job1
B)            If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATE
Are you sure you wish to stop this job ([yes]/no): yes
C)             Now you want to restart the job then you need to attach the job
impdp system/sys dumpfile=DPUMP:export3.dmp logfile=DPUMP:export2.log   attach=OEM_NEW_USER_job1
Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT
Job Monitor
i.e  Typing "status" at this prompt allows you to monitor the current job.
Export> status

Job: OEM_NEW_USER_JOB1
  Operation: IMPORT
  Mode: FULL
  State: EXECUTING
  Bytes Processed: 535,134,568
  Percent Done: 99
  Current Parallelism: 1
  Job Error Count: 0
  Dump File: /home/oracle/dpump/export3.dmp

Worker 1 Status:
  State: EXECUTING
  Object Type: SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
  Total Objects: 70
  Worker Parallelism: 1
Processing object type SCHEMA_EXPORT/MATERIALIZED_VIEW

EXPDP/IMPDP FEATURES



1) Oracle Data Pump export/imports is 20 to 40 times faster  (I have tested on test server) as compare to  exp/imp, even with parallelism set to 1, because of Oracle Data Pump's use of direct path (when possible).

2)  The INCLUDE and EXCLUDE parameters can be used to limit the export/import to specific objects. i.e  if we have  taken export backup on schema level and  at the time of import  we want to exclude specific table we simply need to specify the table name which we want to exclude from import list.
Imp  test/test schemas=test exclude=TABLE:"= 'TABLE_NAME'" directory=TEST_DIR dumpfile=esport_data.dmp logfile=expdptest.log
We  can Include index ,constraints ,query instead the INDEX=y,n or constraints=y,n in old exp/imp

3) Using  NETWORK_LINK parameter  we can exp/imp over the database link. i.e Imports the objects
are directly from the source into the local server without being written to a dump file.
impdp test/test@test tables=table_name  network_link=REMOTE_TEST directory=TEST_DIR logfile=impdptest.log remap_schema=Test:TEST_new                                                  
In above example emp table of test schema  exists on remote server directly imported on local server test_new  schema

4) Datapump have ability to write in many dump files simultaneously using parallel parameter.

5) Estimate parameters helps you estimate the size of export without taking export. It will help you create the required space or take backup on the disk having sufficient space , reduce the probability of exp fails due to lack space

6) Remapping capabilities of datapump you can remap user ,tablespaces , make it easy to transfer data from one tablespace to other tablespaces.
             impdp system\password@tnsname directory=data_pump_dir dumpfile=mydump01.dmp                         remap_schema=source_schema:dest_schema remap_tablespace=source_tablespace:dest_tablespace

7) In the expdp dump file always create on the server even if you taking the export from client dump file will creates on the server, it improves performance and no need to data transfer using network.

8)  Datapump have ability to restart job that have fails due to lack of space or due to other reasons

9)   The ability to detach from and reattach to long-running jobs without affecting the job itself. This allows DBAs and other operations personnel to monitor jobs from multiple locations. In exp if export/import is fails then you have to perform it again but expdp we don't need to bother about it .Because here you can attach or detach the job .
Steps :
A)
expdp mm_stg/mm_stg dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log schemas=mm_stg job_name=SYS_EXPORT_SCHEMA
B) If you want to pause the job for some time then press CTL+C , type the command given below
Export> STOP_JOB=IMMEDIATEAre you sure you wish to stop this job ([yes]/no): yes
C)  Now you want to restart the job then you need to attach the job
         $ expdp mm_stg/mm_stg attach=SYS_EXPORT_SCHEMA
          Export> START_JOB
          Export> STATUS=600
          Export> CONTINUE_CLIENT
10) It has its own performance tuning features

11) It supports interactive mode that allows the dba to monitor or interact with ongoing jobs

12)  The Data Pump method for moving data between different database versions is different from the method used by original Export and Import. With original Export, you had to run  an older version of Export to produce a dump file that was compatible with an older database version. With Data Pump, you use the current Export version and simply use  the VERSION parameter to specify the target database version. You cannot specify  versions earlier than Oracle Database 10g (since Data Pump did not exist before 10g).
Example:
> expdp username/password TABLES=test.emp VERSION=10.1 dumpfile=DPUMP:export.dmp logfile= DPUMP:export.log

CONCLUSIONOracle Data Pump is a great tool for the fast movement of data between the databases and much of this performance improvement is derived from the use of parameter “parallelism.”  New export and import clients, expdp and impdp, that fully exploit the Data Pump Infrastructure. They are implemented as complete supersets of the original exp and imp, and will eventually replace them.


Tuesday, 22 May 2012

Converting to AL32UTF8 Character Set from the Oracle Default of WE8MSWIN1252


Scenario

Current database uses WE8MSWIN1252 we need to migrate new database uses AL32UTF8 encoding.

Method Opted:
Export/Import you can use data pump utility to do the same

STEPS:
1) Explicitly set the NLS_LANG enviornment variable to the characterset of the source database.

#export NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252

2) Export the source database with export utility .take export backup using full option

#exp system/sys file=orcl_full.dmp log=orcl_full.log full=y consistent=y statistics=none buffer=10000000

3) Create a new database with AL32UTF8.

4) Set old nls_lang enviorment variable before import in new databas

#export NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252

5) Import data in schema

# imp Username/password file=sigma.dmp log=import_SIGMAUAT_BACKUP.log fromuser= scott_backup touser=scott

Related Issues :

Ora-12899 value to large for the column string

Cause : column length is less the n data nedd to import/ insert into perticuler column

Solution: Increase the column length

Explanation: When a database is created using byte semantics, the size of the char and varchar data types are specified in bytes ,not character .when database use single byte encoding then number of character is equivalent to the number of bytes .But if database using multiple charcter set then charcter is no longer equivalent to the bytes

During migration to new character set ,it is important to verify the column width of exisiting char and varchar column because thay may need to extended to support an encoding the required multibyte storage

 Single-Byte and Multibyte Encoding



Character
WE8MSWIN 1252 Encoding
AL32UTF8 Encoding
Ä
E4
C3 A4
Ö
F6
C3 B6
©
A9
C2 A9
€
80
E2 82 AC







Thursday, 10 May 2012

Foreign key constraint issues in export/import


If export has been done at the table level and If child table (Table with foriegn key) has been exported first and parent table later ( Table with primary key) then there will be issue at importing because import of tables takes place in the same order as export has taken .There will be  constraints error in importing child tables. In that case we have to import first all for  parent table and in after that import chid tables . i.e we have to perform import twice. Once the  parents tables  and second time child tables  So to avoid this workaround, one should be prudent in picking the tables order in export.   

Example:
In the given eample  table x have  foriegn key reference  with the table y.   Tables export takes in the order x and y.

 exp scott/tiger@mediamat FILE=/home/oracle/expdrec/exp.dmp LOG=/home/oracle/expdrec/exp.LOG  CONSISTENT=y tables=x,y

Export: Release 10.2.0.4.0 - Production on Mon May 9 09:47:52 2011

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


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
Export done in US7ASCII character set and AL16UTF16 NCHAR character set
server uses WE8ISO8859P1 character set (possible charset conversion)

About to export specified tables via Conventional Path ...
. . exporting table                              X          2 rows exported
. . exporting table                              Y          2 rows exported
Export terminated successfully without warnings.
[oracle@mediamath-server archs]$ imp impuser/impuser@mediamat FILE=/home/oracle/expdrec/exp.dmp LOG=/home/oracle/expdrec/exp.LOG ignore=y  tables=y,x  fromuser=scott touser=impuser

Import: Release 10.2.0.4.0 - Production on Mon May 9 11:26:26 2011

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


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

Export file created by EXPORT:V10.02.01 via conventional path

Warning: the objects were exported by SCOTT, not by you

import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses WE8ISO8859P1 character set (possible charset conversion)
. importing SCOTT's objects into IMPUSER
. . importing table                            "X"     127136 rows imported
. . importing table                            "Y"     127209 rows imported
IMP-00017: following statement failed with ORACLE error 2298:
 "ALTER TABLE "Y" ADD FOREIGN KEY ("AA_ID") REFERENCES "X" ("AA_ID") ENABLE"
IMP-00003: ORACLE error 2298 encountered
ORA-02298: cannot validate (IMPUSER.SYS_C0059272) - parent keys not found
Import terminated successfully with warnings.

Some case studies in export/import

1)   Import in data tablespace from diffrent tablespace

If you want to import  from one tablespace to other .then INDEXFILE can solve your purpose.
Issue is here  how to change the tablespace name in which table has to be import . firstly  using INDEXFILE we have to create the file can give statements of create the tables and indexes.
Now we have to  make some changes in the file  in unix “sed “   commands can help to trim the file

At window environment  can simply use find replace from a file.



EXAMPLE : -
 imp  impuser/impuser@mediamat FILE=/home/oracle/expdrec/exp.dmp  LOG=/home/oracle/expdrec/impuser.LOG FROMUSER=scott TOUSER=impuser commit=y indexFILE=/home/oracle/expdrec/index.txt


1)Find the name of tablespace from indexfile using following command

[oracle@mediamath-server ~]$ cat /home/oracle/expdrec/index.txt|grep 'TABLESPACE "'  

2)Following command  replace tablespace name [Source tablespace  :exp_tablespace and destination tablespace :imp_tablespace]

sed -e "s/exp_tablespace/imp_tablespace/g" /home/oracle/expdrec/index.txt >/home/oracle/expdrec/index1

3)Replace the  string REM to blank space[comments]

sed -e "s/REM//g" /home/oracle/expdrec/index1.sql >/home/oracle/expdrec/index.sql                                         

4)Delete the rows having the rows counts number

sed '/rows/d' /home/oracle/expdrec/index.sql >/home/oracle/expdrec/index1.sql


Run the script after connecting the user 

SQL>@/home/oracle/expdrec/index1.sql

SQL> table created
SQL>index created

SQL> select tablespace_name ,table_name from user_tables;

TABLESPACE_NAME                TABLE_NAME
------------------------------ ------------------------------
             imp_tablespace                BONUS
              mp_tablespace               COMP



2)  export and import of table  case sensitive
Export
[oracle@mediamath-server ~]$ exp scott/tiger@mediamat file=/home/oracle/expdrec/exp.dmp log=/home/oracle/expdrec/exp.log statistics=ESTIMATE tables=MM_STG.TBL_TEST,SCOTT.EMP,SCOTT.COMP,SCOTT.\"TEST_data\"  consistent=y

Import

If table name is case sensitive like  TEST_data  then import table name shoud be  in sigle quotes( ' '  )  followed by double quotes ( “”) .by default it  reads  table name in the upper case.

Example:-

[oracle@mediamath-server expdrec]$  imp impuser/impuser@mediamat FILE=/home/oracle/expdrec/exp.dmp LOG=/home/oracle/expdrec/imp.log tables=TBL_TEST,EMP,COMP,'\"TEST_data\"' FROMUSER=MM_STG  FROMUSER=SCOTT FROMUSER=impuser ignore=y

Import: Release 10.2.0.4.0 - Production on Thu May 5 14:28:25 2011

. . importing table                    "TEST_data"         11 rows imported
. importing MM_STG's objects into IMPUSER
. importing SCOTT's objects into SCOTT
About to enable constraints...
Import terminated successfully with warnings.

3) 
Import  tables in of different users.

 Dump file contains the data of multiple user . And have to import data in multiple or single  users.
i.e dump file contain data of  user MM_STG  and SCOTT  and want to import data in the IMPUSER
the we have to specifies  fromuser parameter for  both the users  MM_STG and SCOTT and specifies touser=IMPUSER  both the above users.if you specifies touser only once then first user import data in impuser and all other search the schema same as their name .if exists then insert data otherwise raise error
 Import the data from different user  specifies  multiple "fromuser" and "touser" options in pair.


EXAMPLE:-

[oracle@mediamath-server expdrec]$  imp impuser/impuser@mediamat FILE=/home/oracle/expdrec/exp.dmp LOG=/home/oracle/expdrec/imp.log tables=TBL_TEST,EMP,COMP   FROMUSER=MM_STG  TOUSER=impuser   FROMUSER=SCOTT  TOUSER=impuser ignore=y


     
Import: Release 10.2.0.4.0 - Production on Thu May 5 14:28:25 2011

Copyright (c) 1982, 2007, Oracle.  All rights reserved.


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

Export FILE created by EXPORT:V10.02.01 via conventional path

Warning: the objects were exported by SCOTT, not by you

import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses WE8ISO8859P1 character set (possible charset conversion)
. importing MM_STG's objects into IMPUSER
. . importing table                     "TBL_TEST"          4 rows imported
. importing SCOTT's objects into IMPUSER
. . importing table                          "EMP"
. . importing table                         "COMP"        232 rows imported
. . importing table                    "TEST_data"         11 rows imported

4)  Export tables  from using query


To export the tables  with selected  rows with specific conditions  we simply use QUERY clause with export command.


{oracle@mediamath-server expdrec]$  exp scott/tiger  FILE=/home/oracle/expdrec/exp.dmp LOG=/home/oracle/expdrec/imp.log STATISTICS=none TABLES=emp QUERY==\"where HIREDATE \< to_date\(\'03-DEC-1981\',\'dd-mm-yyyy\'\)\"