이번 시간에는 10g 에서 새롭게 선보인  강력한 TOOL  인  DATAPUMP 에 대해 소개해본다.
일단 운영자 입장에서 PUMP 를 쓰면서 좋다고 느끼는 점은 속도의 향상과  손쉬운 TABLESPACE 변경등을 꼽을수 있겠다. 특히 속도 같은 경우 파티션 테이블일 경우 엄청난 속도 향상 체감을 느낀다.
그리고 TABLESPACE 변경 같은 경우 기존 EXPORT/IMPORT  사용시에는 까다로운 작업이 필요했었는데
DATAPUMP 에서는 파라미터 한줄로 아주 간단하게 변경이 가능하다.
물론 이것 외에도 쥔장이 모른는  훨씬 많고 좋은 기능들이 있을것이다.
하지만 쥔장이 운영하는 입장에서 자주 사용하는 케이스를 TEST 후 정리해본다.

시나리오는 다음과 같다.
 
[ 시나리오 ]
RCHWIN 이라는 유저의 특정 TABLE 인 PUMP_TEST  와 그에따른  INDEX 를 RCHWIN_2  의 유저에 이관한다.
단 TABLESPACE 는 TABLE 과 INDEX  모두 TS_TABLE 과 TS_INDEX 에서  TS_PUMP  로 바뀐다.
 
  
[ 1. CREATE ]
DATAPUMP 에서는  기존 EXPORT 와 달리 DMP 파일과 LOG 파일을 남길 디렉토리를 지정해야 한다.
아래는 /PUMP_TEST/ 디렉토리에 PUMP_DIR  DIRECTORY NAME 을 만든다.
 

SQL>create directory PUMP_DIR as '/PUMP_TEST/';
Directory created.


 
[2. EXPDP ]
기존 EXPORT 와 같이 par 파일이 사용가능하다.
EXPORT 할 대상 TABLE 이 많다면 command 창에서 모두 나열해서 쓰는것보다
par 파일에 대상 TABLE 을 넣고 작업한다면 추후 동일한 작업을 할경우 TABLE LIST 만 변경하면 되니 작업이 더 효율적일 것이다.
쥔장의 운영자 입장에서 볼때 exp/imp 건 expdp/impdp 건 간에 가급적이면  par 파일을 만들어 쓰길 선호한다.
 

[TEST] /PUMP_TEST/> cat PUMP_TEST.par
directory=PUMP_DIR
dumpfile=PUMP_TEST.dmp
logfile=PUMP_TEST.log
CONTENT=ALL
TABLES=
RCHWIN.PUMP_TEST

 

 

[TEST] /PUMP_TEST/> expdp system/패스워드 parfile=PUMP_TEST.par
Export: Release 10.2.0.3.0 - 64bit Production on Wednesday, 11 March, 2009 11:03:38
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining Scoring Engine options
Starting "SYSTEM"."SYS_EXPORT_TABLE_05":  system/******** parfile=PUMP_TEST.par
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 608 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "RCHWIN"."PUMP_TEST"            523.4 MB  681097 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_05" successfully loaded/unloaded
******************************************************************************
Dump file set for SYSTEM.SYS_EXPORT_TABLE_05 is:
  /PUMP_TEST//PUMP_TEST.dmp
Job "SYSTEM"."SYS_EXPORT_TABLE_05" successfully completed at 11:12:24


 
[ 3. IMPDP ]
expdp 받은 TABLE 을 impdp 를 진행한다.
조건은 아래와 같다.
RCHWIN 이라는 유저의 특정 TABLE 인 PUMP_TEST  와 그에따른  INDEX 를 RCHWIN_2  의 유저에 이관한다.
단 TABLESPACE 는 TABLE 과 INDEX  모두 TS_TABLE 과 TS_INDEX 에서  TS_PUMP  로 바뀐다.
 

 

[TEST] /PUMP_TEST/> cat imp_PUMP_TEST.par
"imp_PUMP_TEST.par" 6
, 134

directory=PUMP_DIR
dumpfile=PUMP_TEST.dmp
logfile=imp_PUMP_TEST.log
REMAP_TABLESPACE=TS_TABLE:TS_PUMP

REMAP_TABLESPACE=TS_INDEX:TS_PUMP
REMAP_SCHEMA=RCHWIN:RCHWIN_2

 

 

[TEST] /PUMP_TEST/> imp system/패스워드 parfile=imp_PUMP_TEST.par
LRM-00101: unknown parameter name 'directory'
LRM-00113: error when processing file 'imp_PUMP_TEST.par'
IMP-00022: failed to process parameters, type 'IMP HELP=Y' for help
IMP-00000: Import terminated unsuccessfully
[TEST] /PUMP_TEST/> impdp parfile=imp_PUMP_TEST.par
Import: Release 10.2.0.3.0 - 64bit Production on Wednesday, 11 March, 2009 11:21:24
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Username: system
Password:
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining Scoring Engine options
Master table "SYSTEM"."SYS_IMPORT_FULL_05" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_05":  system/******** parfile=imp_PUMP_TEST.par
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "RCHWIN_2"."PUMP_TEST"       523.4 MB  681097 rows
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX

 
 
[ 4. IMPORT 확인 ]
RCHWIN 계정의 TABLE 및 INDEX 가 RCHWIN_2 로 정상적으로 이관이 되었는지 확인해보고
TABLESPACE 또한 지정한것으로 바뀌었는지 확인해보자.
 

SQL> select owner, segment_name, segment_type, tablespace_name, bytes/1024/1024 from dba_segments
where segment_name='PUMP_TEST';
OWNER       SEGMENT_NAME      SEGMENT_TYPE       TABLESPACE_NAME        BYTES/1024/1024
------------------------------ ---------------------------------------------------------------------------------------
RCHWIN             PUMP_TEST         TABLE              TS_TABLE                                608
RCHWIN_2         PUMP_TEST          TABLE               TS_PUMP                               656
2 rows selected.

 

SQL> select owner, index_name,  tablespace_name from dba_indexes
where table_name='PUMP_TEST';
OWNER                          INDEX_NAME                     TABLESPACE_NAME              
------------------------------ ------------------------------ ------------------------------
RCHWIN                         PUMP_TEST_2IX     TS_INDEX                     
RCHWIN                         PUMP_TEST_PK      TS_INDEX                     
RCHWIN                         PUMP_TEST_1IX     TS_INDEX                     
RCHWIN_2                     PUMP_TEST_2IX     TS_PUMP                    
RCHWIN_2                     PUMP_TEST_PK      TS_PUMP                     
RCHWIN_2                     PUMP_TEST_1IX     TS_PUMP              

  
[* 참조 *]
 
- 자주 사용되는 파라미터
DATA_ONLY - 이미 존재하는 테이블에 대해서만 데이터를 load 시킨다. 없던 객체를 생성 시키지 않는다.
METADATA_ONLY - DATA 없이 객체만 받는다.  EXPORT 에서 ROWS=N 과 같은 파라미터이다.
 
- DIRECTORY 확인 방법
 : 기존에 생성되어 있는 DIRECTORY NAME 의 실제 DIRECTORY 를 확인하는 방법
 

SQL> SELECT * FROM DBA_DIRECTORIES;

OWNER                DIRECTORY_NAME                 DIRECTORY_PATH
-------------------- ------------------------------ ------------------------------------------
SYS                          PUMP_TEST                         /PUMP_TEST/

 
- DATAPUMP 사용법
 

[TEST] /PUMP_TEST/>  expdp help=y

Export: Release 10.2.0.3.0 - 64bit Production on Wednesday, 11 March, 2009 16:26:18

Copyright (c) 2003, 2005, Oracle.  All rights reserved.


The Data Pump export utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:

   Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Export runs by entering the 'expdp' command followed
by various parameters. To specify parameters, you use keywords:

   Format:  expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
   Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
               or TABLES=(T1:P1,T1:P2), if T1 is partitioned table

USERID must be the first parameter on the command line.

Keyword               Description (Default)
------------------------------------------------------------------------------
ATTACH                Attach to existing job, e.g. ATTACH [=job name].
COMPRESSION           Reduce size of dumpfile contents where valid
                      keyword values are: (METADATA_ONLY) and NONE.
CONTENT               Specifies data to unload where the valid keywords are:
                      (ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY             Directory object to be used for dumpfiles and logfiles.
DUMPFILE              List of destination dump files (expdat.dmp),
                      e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD   Password key for creating encrypted column data.
ESTIMATE              Calculate job estimates where the valid keywords are:
                      (BLOCKS) and STATISTICS.
ESTIMATE_ONLY         Calculate job estimates without performing the export.
EXCLUDE               Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FILESIZE              Specify the size of each dumpfile in units of bytes.
FLASHBACK_SCN         SCN used to set session snapshot back to.
FLASHBACK_TIME        Time used to get the SCN closest to the specified time.
FULL                  Export entire database (N).
HELP                  Display Help messages (N).
INCLUDE               Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME              Name of export job to create.
LOGFILE               Log file name (export.log).
NETWORK_LINK          Name of remote database link to the source system.
NOLOGFILE             Do not write logfile (N).
PARALLEL              Change the number of active workers for current job.
PARFILE               Specify parameter file.
QUERY                 Predicate clause used to export a subset of a table.
SAMPLE                Percentage of data to be exported;
SCHEMAS               List of schemas to export (login schema).
STATUS                Frequency (secs) job status is to be monitored where
                      the default (0) will show new status when available.
TABLES                Identifies a list of tables to export - one schema only.
TABLESPACES           Identifies a list of tablespaces to export.
TRANSPORT_FULL_CHECK  Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be unloaded.
VERSION               Version of objects to export where valid keywords are:
                      (COMPATIBLE), LATEST, or any valid database version.

The following commands are valid while in interactive mode.
Note: abbreviations are allowed

Command               Description
------------------------------------------------------------------------------
ADD_FILE              Add dumpfile to dumpfile set.
CONTINUE_CLIENT       Return to logging mode. Job will be re-started if idle.
EXIT_CLIENT           Quit client session and leave job running.
FILESIZE              Default filesize (bytes) for subsequent ADD_FILE commands.
HELP                  Summarize interactive commands.
KILL_JOB              Detach and delete job.
PARALLEL              Change the number of active workers for current job.
                      PARALLEL=<number of workers>.
START_JOB             Start/resume current job.
STATUS                Frequency (secs) job status is to be monitored where
                      the default (0) will show new status when available.
                      STATUS[=interval]
STOP_JOB              Orderly shutdown of job execution and exits the client.
                      STOP_JOB=IMMEDIATE performs an immediate shutdown of the
                      Data Pump job.

 

 

[TEST] /PUMP_TEST/>  impdp help=y

 


Import: Release 10.2.0.3.0 - 64bit Production on Wednesday, 11 March, 2009 16:27:16

Copyright (c) 2003, 2005, Oracle.  All rights reserved.


The Data Pump Import utility provides a mechanism for transferring data objects
between Oracle databases. The utility is invoked with the following command:

     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Import runs by entering the 'impdp' command followed
by various parameters. To specify parameters, you use keywords:

     Format:  impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)
     Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

USERID must be the first parameter on the command line.

Keyword               Description (Default)
------------------------------------------------------------------------------
ATTACH                Attach to existing job, e.g. ATTACH [=job name].
CONTENT               Specifies data to load where the valid keywords are:
                      (ALL), DATA_ONLY, and METADATA_ONLY.
DIRECTORY             Directory object to be used for dump, log, and sql files.
DUMPFILE              List of dumpfiles to import from (expdat.dmp),
                      e.g. DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp.
ENCRYPTION_PASSWORD   Password key for accessing encrypted column data.
                      This parameter is not valid for network import jobs.
ESTIMATE              Calculate job estimates where the valid keywords are:
                      (BLOCKS) and STATISTICS.
EXCLUDE               Exclude specific object types, e.g. EXCLUDE=TABLE:EMP.
FLASHBACK_SCN         SCN used to set session snapshot back to.
FLASHBACK_TIME        Time used to get the SCN closest to the specified time.
FULL                  Import everything from source (Y).
HELP                  Display help messages (N).
INCLUDE               Include specific object types, e.g. INCLUDE=TABLE_DATA.
JOB_NAME              Name of import job to create.
LOGFILE               Log file name (import.log).
NETWORK_LINK          Name of remote database link to the source system.
NOLOGFILE             Do not write logfile.
PARALLEL              Change the number of active workers for current job.
PARFILE               Specify parameter file.
QUERY                 Predicate clause used to import a subset of a table.
REMAP_DATAFILE        Redefine datafile references in all DDL statements.
REMAP_SCHEMA          Objects from one schema are loaded into another schema.
REMAP_TABLESPACE      Tablespace object are remapped to another tablespace.
REUSE_DATAFILES       Tablespace will be initialized if it already exists (N).
SCHEMAS               List of schemas to import.
SKIP_UNUSABLE_INDEXES Skip indexes that were set to the Index Unusable state.
SQLFILE               Write all the SQL DDL to a specified file.
STATUS                Frequency (secs) job status is to be monitored where
                      the default (0) will show new status when available.
STREAMS_CONFIGURATION Enable the loading of Streams metadata
TABLE_EXISTS_ACTION   Action to take if imported object already exists.
                      Valid keywords: (SKIP), APPEND, REPLACE and TRUNCATE.
TABLES                Identifies a list of tables to import.
TABLESPACES           Identifies a list of tablespaces to import.
TRANSFORM             Metadata transform to apply to applicable objects.
                      Valid transform keywords: SEGMENT_ATTRIBUTES, STORAGE
                      OID, and PCTSPACE.
TRANSPORT_DATAFILES   List of datafiles to be imported by transportable mode.
TRANSPORT_FULL_CHECK  Verify storage segments of all tables (N).
TRANSPORT_TABLESPACES List of tablespaces from which metadata will be loaded.
                      Only valid in NETWORK_LINK mode import operations.
VERSION               Version of objects to export where valid keywords are:
                      (COMPATIBLE), LATEST, or any valid database version.
                      Only valid for NETWORK_LINK and SQLFILE.

The following commands are valid while in interactive mode.
Note: abbreviations are allowed

Command               Description (Default)
------------------------------------------------------------------------------
CONTINUE_CLIENT       Return to logging mode. Job will be re-started if idle.
EXIT_CLIENT           Quit client session and leave job running.
HELP                  Summarize interactive commands.
KILL_JOB              Detach and delete job.
PARALLEL              Change the number of active workers for current job.
                      PARALLEL=<number of workers>.
START_JOB             Start/resume current job.
                      START_JOB=SKIP_CURRENT will start the job after skipping
                      any action which was in progress when job was stopped.
STATUS                Frequency (secs) job status is to be monitored where
                      the default (0) will show new status when available.
                      STATUS[=interval]
STOP_JOB              Orderly shutdown of job execution and exits the client.
                      STOP_JOB=IMMEDIATE performs an immediate shutdown of the
                      Data Pump job.

 

  dbtown-rchwin.jpg
 이 글의 권한은 dbtown.net 에 있습니다.
자료를 스크랩하실땐 출처를 밝혀주세요 ^^