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';

 

1.3      执行导出

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

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

1.4      导入之前准备

如果导入的数据库与导出的数据库不是同一个库,导入之前要重复1、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

 

(二)        附录

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

 

 

原文地址:https://www.cnblogs.com/zuo-zijing/p/3973254.html