这里不再介绍数据泵的原理、作用,默认你是开发人员或者dba。
expdp-impdp有很多优良的特性,其中最主要可能是速度快,之前做过测试expdp-impdp是普通exp-imp速度的2-3倍。另外使用exp-imp的时候如果建表的时候指定了表空间,如:create table test(varchar2(10) name ,number10 id) TABLESPACE example STORAGE (INITIAL 6144 NEXT 6144 MINEXTENTS 1 MAXEXTENTS 5 ); 这个时候目标库导入的时候必须有example表空间,否则导入不了。impdp就可以使用REMAP_TABLESPACE选项重新分配tablespace映射关系。
但是使用中也发现一些问题,比如用户名若使用sys断开跟命令连接之后无法再通过ATTACH参数连接到这个job,另外如果程序异常退出在视图 dba_datapump_jobs会一直有这个导数进程的job,有时候会堵塞进程造成性能问题,我们生产数据库发现过类似问题。
下面是我经常使用的两个参数文件,多数情况下使用这个参数就可以满足平时数据处理:
more expdp.par
userid=dbmgr/passwd
DIRECTORY=expdir
DUMPFILE=expdp.dmp
tables=S_ORG_EXT_IMP
logfile=expdp.log
more impdp.par
userid='/ as sysdba '
DIRECTORY=expdir
DUMPFILE=expdp.dmp
tables=S_ORG_EXT_IMP
logfile=impdp.log
job_name=impdp
REMAP_SCHEMA=dbmgr:siebel
TABLE_EXISTS_ACTION=APPEND
expdp-impdp跟exp-imp不同,需要先在数据库中建一个目录,如下:
SQL> create directory expdir as '/paic/block/secexg/backup/secexgbak/exp_full_20101118';
Directory created.
[oracle@cnsz040605 banksl1_0915_bk]$ expdp -help
Export: Release 10.1.0.4.2 - Production on Thursday, 16 September, 2010 0:45
Copyright (c) 2003, 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].
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.
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.
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.
ADD_FILE=
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=
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.
[oracle@cnsz040605 banksl1_0915_bk]$ impdp -help
Import: Release 10.1.0.4.2 - Production on Thursday, 16 September, 2010 0:44
Copyright (c) 2003, 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.
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 (Y/N) to specific objects.
Valid transform. keywords: SEGMENT_ATTRIBUTES and STORAGE.
ex. TRANSFORM=SEGMENT_ATTRIBUTES:N:TABLE.
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=
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.
调用IMPDP
1, 导入表
Impdp scott/tiger DIRECTORY=dump_dir DUMPFILE=tab.dmp
TABLES=dept,emp
Impdp system/manage DIRECTORY=dump_dir DUMPFILE=tab.dmp
TABLES=scott.dept,scott.emp REMAP_SCHEMA=SCOTT:SYSTEM
第一种方法表示将DEPT和EMP表导入到SCOTT方案中,第二种方法表示将DEPT和EMP表导入的SYSTEM方案中。
注意,如果要将表导入到其他方案中,必须指定REMAP SCHEMA选项。
2,导入方案
Impdp scott/tiger DIRECTORY=dump_dir DUMPFILE=schema.dmp
SCHEMAS=scott
Impdp system/manager DIRECTORY=dump_dir DUMPFILE=schema.dmp
SCHEMAS=scott REMAP_SCHEMA=scott:system
3,导入表空间
Impdp system/manager DIRECTORY=dump_dir DUMPFILE=tablespace.dmp
TABLESPACES=user01
4,导入数据库
Impdp system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y
EXPDP/IMPDP的停止与重启动:
EXPDP和IMPDP的本质在于,通过API调用,把传统的EXP/IMP类交付式模式的操作,转变成数据库内部的job任务,从而实现了任务的可终止与重启动。
c:\expdp test/test@acf directory=dpdata dumpfile=full.dmp full=y job_name=expfull在执行过程中,可以拿下Ctrl+C组合键,退出当前交互模式,退出之后,导出操作不会停止,这不同于Oracle以前的EXP.以前的EXP,如果退出交互式模式,就会出错终止导出任务。
在Oracle 10中,由于EXPDP是数据库内部定义的任务,已经与客户端无关。退出交互之后,会进入export的命令行模式,此时支持status等查看命令:
Export> status
如果想停止改任务,可以发出stop_job命令
Export> stop_job
如果有命令行提示
是否确实要停止此作业([Y]/N):
或Are you sure you wish to stop this job ([yes]/no):
回答应是yes或者no
接下来可以通过命令行再次连接到这个任务
c:\expdp test/test@acf attach=expfull
通过start_job命令重新启动导出
Export> start_job
在plsql下查看任务名:
SQL>select * from DBA_DATAPUMP_JOBS ——查看job
在plsq下查看对应session:
SQL>select sid, serial#
2 from v$session s, dba_datapump_sessions d
3 where s.saddr = d.saddr;
下列命令在交互模式下有效。
注: 允许使用缩写命令 说明 (默认)
------------------------------------------------------------------------------
CONTINUE_CLIENT 返回到记录模式。如果处于空闲状态, 将重新启动作业。
EXIT_CLIENT 退出客户机会话并使作业处于运行状态。
HELP 总结交互命令。
KILL_JOB 分离和删除作业。
PARALLEL 更改当前作业的活动 worker 的数目。
PARALLEL=
START_JOB=SKIP_CURRENT 在开始作业之前将跳过作业停止时执行的任意操作。
STATUS 在默认值 (0) 将显示可用时的新状态的情况下,要监视的频率 (以秒计) 作业状态。
STATUS[=interval] STOP_JOB 顺序关闭执行的作业并退出客户机。
STOP_JOB=IMMEDIATE 将立即关闭数据泵作业。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15779287/viewspace-678451/ ,如需转载,请注明出处,否则将追究法律责任。