expdp与impdp

参考http://blog.csdn.net/hello985/article/details/13295305数据库

(一)        导出scott用户下的emp表到xx用户下服务器

1.1      建立DIRECTORY,用sys用户建立

create directory DATA_PUMP_DIR as 'D:\dir_dp';性能

 

1.2      在该目录上对scott用户授读写权限
Grant read,write on directory DATA_PUMP_DIR to scott;

--查看目录及权限
 select * from dba_directories;
 select * from user_tab_privs where table_name = 'DATA_PUMP_DIR';spa

 

1.3      执行导出

expdp scott/tiger@orcl tables = emp directory=DATA_PUMP_DIR dumpfile=expdp_emp.dmp logfile=expdp_emp.log .net

--这里将scott用户下的emp表导出到DATA_PUMP_DIR目录中,保存文件为:expdp_emp.dmp,生成日志文件:expdp_emp.log。若要以其它模式导出,修改参数便可。线程

1.4      导入以前准备

若是导入的数据库与导出的数据库不是同一个库,导入以前要重复一、2两步操做,并将导出文件上传到要导入的服务器日志

 

1.5      执行导入

impdp xx/xx@orcl tables = scott.emp directory= DATA_PUMP_DIR dumpfile=expdp_emp.dmp logfile=expdp_imp.log TABLE_EXISTS_ACTION = REPLACE REMAP_SCHEMA=scott:xx对象

 

(二)        附录blog

2.1      更换表空间

  采用remap_tablespace参数
  --导出gwm用户下的全部数据
expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp SCHEMAS=gwm
注:若是是用sys用户导出的用户数据,包括用户建立、受权部分,用自身用户导出则不含这些内容
--如下是将gwm用户下的数据所有导入到表空间gcomm(原来为gmapdata表空间下)下
impdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcomm进程

 

2.2      更换用户名

REMAP_SCHEMA
该选项用于将源方案的全部对象装载到目标方案中.
REMAP_SCHEMA=source_schema:target_schema

 

impdp xx/xx@orcl tables = scott.emp directory= DATA_PUM

P_DIR dumpfile=expdp_emp.dmp logfile=expdp_imp.log TABLE_EXISTS_ACTION = REPLACE  remap_schema=scott:xx remap_tablespace=users:example

 

2.3      expdp导出模式

a、按表导出:
expdp scott/tiger@orcl  tables=scott.emp dumpfile =expdp_test2.dmp logfile=expdp_test2.log directory=dir_dp job_name=my_job

b、按查询条件导出:
expdp scott/tiger@orcl  tables=lttfm.b$i_exch_info dumpfile =expdp_test3.dmp logfile=expdp_test3.log directory=dir_dp job_name=my_job query='"where rownum<11"'

c、按表空间导出:
Expdp scott/tiger@orcl dumpfile=expdp_tablespace.dmp tablespaces=GCOMM.DBF logfile=expdp_tablespace.log directory=dir_dp job_name=my_job

d、导出方案
Expdp scott/tiger@orcl  DIRECTORY=dir_dp DUMPFILE=schema.dmp SCHEMAS=lttfm,gwm

e、导出整个数据库:
expdp scott/tiger@orcl dumpfile =full.dmp full=y logfile=full.log directory=dir_dp job_name=my_job

 

f、按用户导出

expdp scott/tiger@orcl schemas=scott dumpfile=expdp.dmp DIRECTORY=dpdata1;

 

2.4      impdp导入模式:

a、按表导入

p_street_area.dmp文件中的表,此文件是以gwm用户按schemas=scott导出的:
impdp xx/xx@orcl  dumpfile =scott.dmp logfile=imp_scott.log directory= data_pump_dir tables=emp job_name=my_job

b、按用户导入(能够将用户信息直接导入,即若是用户信息不存在的状况下也能够直接导入)
impdp xx/xx@orcl schemas=scott dumpfile =expdp_test.dmp logfile=expdp_test.log directory= data_pump_dir job_name=my_job

c、不经过expdp的步骤生成dmp文件而直接导入的方法:
--从源数据库中向目标数据库导入表p_street_area
impdp xx/xx@orcl directory= DATA_PUMP_DIR NETWORK_LINK=igisdb tables=p_street_area logfile=p_street_area.log  job_name=my_job
igisdb是目的数据库与源数据的连接名,dir_dp是目的数据库上的目录

 

2.5      CONTENT

EXP和IMP的ROWS参数常常会被用到,而在数据泵中,这个功能被CONTENT参数所取代。一样,CONTENT参数在EXPDP/IMPDP两个命令中均可以指定。其中CONTENT参数的ALL选项对应EXP/IMP的ROWS=Y,而CONTENT参数的METADATA_ONLY对应EXP/IMP的ROWS=N。

数据泵还能实现EXP/IMP所不能实现的功能,就是只导出数据,而不导出表结果即DATA_ONLY参数。

expdp scott/tiger directory=d_output dumpfile=yangtk_data.dp content=data_only

固然传统的EXP/IMP虽然不能实现不导出表结构,可是在IMP的时候使用IGNORE=Y参数,能够忽略表已经存在而致使的建表操做,从这个意义上讲,变相实现了只导入数据的功能。

2.6      并行操做(PARALLEL)

您能够经过 PARALLEL 参数为导出使用一个以上的线程来显著地加速做业。每一个线程建立一个单独的转储文件,所以参数 dumpfile 应当拥有和并行度同样多的项目。您能够指定通配符做为文件名,而不是显式地输入各个文件名,例如:

expdp scott/tiger@orcl schemas=scott directory=DATA_PUMP_DIR

dumpfile=expdp_emp_%U.dmp logfile=expdp_emp.log parallel=4

 

impdp xx/xx@orcl  directory= DATA_PUMP_DIR dumpfile=expdp_emp_%U.dmp logfile=expdp_imp.log TABLE_EXISTS_ACTION = REPLACE remap_schema=scott:xx remap_tablespace=users:example parallel=4


注意:dumpfile 参数拥有一个通配符 %U,它指示文件将按须要建立,格式将为expCASES_nn.dmp,其中nn 从 01 开始,而后按须要向上增长。

在并行模式下,状态屏幕将显示四个工做进程。(在默认模式下,只有一个进程是可见的)全部的工做进程同步取出数据,并在状态屏幕上显示它们的进度。

分离访问数据文件和转储目录文件系统的输入/输出通道是很重要的。不然,与维护 Data Pump 做业相关的开销可能超过并行线程的效益,并所以而下降性能。并行方式只有在表的数量多于并行值而且表很大时才是有效的。

   1) 对于导出的parallel
     对于导出来讲,因为dump文件只能由一个线程进行操做(包括I/O处理),所以若是输出的DUMP文件只有一个,即便你指定再多的并行,实际工做仍然是一个,并且还会触发ORA-39095错误。所以,建议设置该参数小于或等于生成的DUMP文件数量。那么,如何控制生成的DUMP文件数量呢?
     EXPDP命令提供了一个FILESIZE参数,用来指定单个DUMP文件的最大容量,要有效的利用parallel参数,filesize参数必不可少。
     举例:某用户对象占用了4G左右的空间,实际导出后的DUMP文件约为3G,咱们尝试在导出该用户时指定并行度为4,设置单个文件不超过500M,则语法以下:
    $ expdp user/pwd directory=dump_file dumpfile=expdp_20100820_%U.dmp logfile=expdp_20100820.log filesize=500M parallel=4

   2) 对于导入的parallel
     对于导入来讲,使用parallel参数则要简单的多,我认为导入更能体现parallel参数的优点。参数设置为几,则认为同时将几张表的内容导入到库中。
    举例:某dmp文件中包含了200张表,咱们尝试在导入该DMP文件时指定并行度为10,则语法以下:
   $ impdp user/pwd directory=dump_file dumpfile=expdp_20100820.dmp logfile=impdp_20100820.log parallel=10

相关文章
相关标签/搜索