阅读 123

ORACLE 数据泵之NETWORK_LINK

 数据泵之NETWORK_LINK


blog结构图:

image

 

1  环境介绍


SOURCE DB(虚拟机)

TARGET DB(虚拟机)

CLIENT(笔记本)

EXP/IMP

11.2.0.3.0

11.2.0.1.0

11.2.0.1.0

EXPDP/IMPDP

11.2.0.3.0

11.2.0.1.0

11.2.0.1.0

HOST IP

192.168.59.130

192.168.59.128

192.168.59.1

host 平台

内存

RHEL 6.5

MemTotal:  2.6g

windows XP

MemTotal:  2g

windows 8.1

MemTotal:  20g

DB VERSION

11.2.0.3.0

11.2.0.1.0

ORACLE_SID

orclasm

orcl

tnsname

orclasm

orclxp


 

注意: 本实验所有的代码无特殊说明均在client客户端执行

 

 

 

图形关系如下:

image

 

 

2  imp和exp简介

 

首先来看这句话: expdp属于服务端工具,而exp属于客户端工具,expdp生成的文件默认是存放在服务端的,而exp生成的文件是存放在客户端的

 

来验证exp和imp:

 

我们在client客户端执行:

C:\Users\Administrator>exp  lhr/lhr@orclasm  tables=xb_log_lhr  file=e:\e1.dmp  log=E:\exp_table.log  buffer=41943040

 

Export: Release 11.2.0.1.0 - Production on 星期二 2月 10 15:55:25 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集

 

即将导出指定的表通过常规路径...

. . 正在导出表                      XB_LOG_LHR导出了          56 行

成功终止导出, 没有出现警告。

 

C:\Users\Administrator>imp  lhr/lhr@orclxp  tables=xb_log_lhr  file=e:\e1.dmp  log=E:\exp_table.log  buffer=41943040

 

Import: Release 11.2.0.1.0 - Production on 星期二 2月 10 15:59:42 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

经由常规路径由 EXPORT:V11.02.00 创建的导出文件

已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入

. 正在将 LHR 的对象导入到 LHR

. 正在将 LHR 的对象导入到 LHR

. . 正在导入表                    "XB_LOG_LHR"导入了          56 行

成功终止导入, 没有出现警告。

 

而文件也的确是在本机的:

wps2C1.tmp 

 

 

3  expdp不使用network_link

根据expdp的语法,我们执行如下脚本:

 

 

C:\Users\Administrator>expdp lhr/lhr@orclasm directory=DATA_PUMP_DIR dumpfile=exptable.dmp TABLES=xb_log_lhr LOGFILE=expdp_table.log

 

Export: Release 11.2.0.1.0 - Production on 星期二 2月 10 16:37:40 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, Automatic Storage Management, OLAP, Data Mining

and Real Application Testing options

启动 "LHR"."SYS_EXPORT_TABLE_01":  lhr/********@orclasm directory=DATA_PUMP_DIR dumpfile=exptable.dmp TABLES=xb_log_lhr LOGFILE=expdp_table.log

正在使用 BLOCKS 方法进行估计...

处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

使用 BLOCKS 方法的总估计: 64 KB

处理对象类型 TABLE_EXPORT/TABLE/TABLE

处理对象类型 TABLE_EXPORT/TABLE/COMMENT

处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/TRIGGER

处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

. . 导出了 "LHR"."XB_LOG_LHR"                          18.75 KB      56 行

已成功加载/卸载了主表 "LHR"."SYS_EXPORT_TABLE_01"

******************************************************************************

LHR.SYS_EXPORT_TABLE_01 的转储文件集为:

  /u01/app/oracle/admin/orclasm/dpdump/exptable.dmp

作业 "LHR"."SYS_EXPORT_TABLE_01" 已于 16:38:00 成功完成

 

 

C:\Users\Administrator>

 

 

在服务器端查看可知,文件是存放在linux服务器端的:

 

[oracle@rhel6_lhr dpdump]$ ll

total 156

-rw-r--r-- 1 oracle asmadmin   1391 Feb 10 16:38 expdp_table.log

-rw-r----- 1 oracle asmadmin 151552 Feb 10 16:38 exptable.dmp

[oracle@rhel6_lhr dpdump]$ pwd

/u01/app/oracle/admin/orclasm/dpdump

[oracle@rhel6_lhr dpdump]$

 

而在这种情况下必须将exptable.dmp 拷贝到windows XP上的相应目录下才能使用impdp来进行导入,如下利用ftp下载:

wps2C2.tmp 

 

将exptable.dmp放到windows XP下的虚拟机里:

C:\Users\Administrator>sqlplus lhr/lhr@orclxp

 

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 2月 10 16:46:37 2015

 

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

 

 

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SQL> set line 9999

SQL> SELECT * FROM  dba_directories d WHERE d.directory_name='DATA_PUMP_DIR';

 

OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH

------------------------------ ------------------------------ ---------------------------------------------------------------------

SYS                            DATA_PUMP_DIR                  F:\app\oracle\admin\orcl\dpdump\

 

SQL>

 

wps2C3.tmp 

 

 

然后再进行导入操作:

 

C:\Users\Administrator>impdp lhr/lhr@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp LOGFILE=impdp_table.log

 

Import: Release 11.2.0.1.0 - Production on 星期二 2月 10 16:50:46 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

已成功加载/卸载了主表 "LHR"."SYS_IMPORT_FULL_01"

启动 "LHR"."SYS_IMPORT_FULL_01":  lhr/********@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp LOGFILE=impdp_table.log

处理对象类型 TABLE_EXPORT/TABLE/TABLE

处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

. . 导入了 "LHR"."XB_LOG_LHR"                          18.75 KB      56 行

处理对象类型 TABLE_EXPORT/TABLE/COMMENT

处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/TRIGGER

处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

作业 "LHR"."SYS_IMPORT_FULL_01" 已经完成。

 

 

C:\Users\Administrator>

 

 

日志文件路径:

wps2D4.tmp 

 

 

这样操作是否非常麻烦,那么如何将生成的文件放在目标数据库而不放在源数据库呢,在expdp中使用network_link。

 

 

 

4  expdp使用network_link

 

 

 

4.1  目标数据库创建dblink

C:\Users\Administrator>sqlplus lhr/lhr@orclxp

 

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 2月 10 16:55:43 2015

 

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

 

 

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SQL> create public database link dblk_orclasm connect to lhr identified by lhr using 'orclasm' ;

 

数据库链接已创建。

SQL> SELECT count(1) FROM xb_log_lhr@dblk_orclasm;

 

  COUNT(1)

----------

        56

 

SQL> SELECT count(1) FROM xb_log_lhr;

SELECT count(1) FROM xb_log_lhr

                     *

第 1 行出现错误:

ORA-00942: 表或视图不存在

 

 

SQL>

 

SQL> exit

从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开

 

C:\Users\Administrator>

 

 

wps2D5.tmp 

 

 

4.2  client端或目标数据库执行

注意这里的连接标识符是orclxp,即连接到windows xp系统,是target库。

C:\Users\Administrator>expdp lhr/lhr@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp TABLES=xb_log_lhr  network_link=dblk_orclasm LOGFILE=expdp_table.log

 

Export: Release 11.2.0.1.0 - Production on 星期二 2月 10 17:07:35 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

启动 "LHR"."SYS_EXPORT_TABLE_01":  lhr/********@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp TABLES=xb_log_lhr network_link=dblk_orclasm LOGFILE=expdp_table.log

正在使用 BLOCKS 方法进行估计...

处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

使用 BLOCKS 方法的总估计: 64 KB

处理对象类型 TABLE_EXPORT/TABLE/TABLE

处理对象类型 TABLE_EXPORT/TABLE/COMMENT

处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/TRIGGER

处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

. . 导出了 "LHR"."XB_LOG_LHR"                          18.75 KB      56 行

已成功加载/卸载了主表 "LHR"."SYS_EXPORT_TABLE_01"

******************************************************************************

LHR.SYS_EXPORT_TABLE_01 的转储文件集为:

  F:\APP\ORACLE\ADMIN\ORCL\DPDUMP\EXPTABLE.DMP

作业 "LHR"."SYS_EXPORT_TABLE_01" 已于 17:07:58 成功完成

 

 

C:\Users\Administrator>

 

结果:

wps2D6.tmp 

 

C:\Users\Administrator>impdp lhr/lhr@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp LOGFILE=impdp_table.log

 

Import: Release 11.2.0.1.0 - Production on 星期二 2月 10 17:13:20 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

已成功加载/卸载了主表 "LHR"."SYS_IMPORT_FULL_01"

启动 "LHR"."SYS_IMPORT_FULL_01":  lhr/********@orclxp directory=DATA_PUMP_DIR dumpfile=exptable.dmp LOGFILE=impdp_table.log

处理对象类型 TABLE_EXPORT/TABLE/TABLE

处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

. . 导入了 "LHR"."XB_LOG_LHR"                          18.75 KB      56 行

处理对象类型 TABLE_EXPORT/TABLE/COMMENT

处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/TRIGGER

处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

作业 "LHR"."SYS_IMPORT_FULL_01" 已经完成(于 17:13:23 完成)

 

 

C:\Users\Administrator>

 

 

4.3  总结

采用network_link选项时,所有的操作均在target即目标端执行。

 

 

5  impdp使用network_link

 

如果想不生成dmp文件而直接将需要的数据导入garget数据库,则直接使用impdp带network_link ,这样可以直接impdp,而绕过了expdp的步骤

 

5.1  目标数据库创建dblink

C:\Users\Administrator>sqlplus lhr/lhr@orclxp

 

SQL*Plus: Release 11.2.0.1.0 Production on 星期二 2月 10 16:55:43 2015

 

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

 

 

连接到:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

SQL> create public database link dblk_orclasm connect to lhr identified by lhr using 'orclasm' ;

 

数据库链接已创建。

SQL> SELECT count(1) FROM xb_log_lhr@dblk_orclasm;

 

  COUNT(1)

----------

        56

 

SQL> SELECT count(1) FROM xb_log_lhr;

SELECT count(1) FROM xb_log_lhr

                     *

第 1 行出现错误:

ORA-00942: 表或视图不存在

 

 

SQL>

 

SQL> exit

从 Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options 断开

 

C:\Users\Administrator>

 

 

wps2D7.tmp 

 

.5.2  client或目标端执行

 

C:\Users\Administrator>impdp lhr/lhr@orclxp  network_link=dblk_orclasm directory=DATA_PUMP_DIR TABLES=xb_log_lhr PARALLEL=2

 

Import: Release 11.2.0.1.0 - Production on 星期二 2月 10 17:20:58 2015

 

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

 

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

启动 "LHR"."SYS_IMPORT_TABLE_01":  lhr/********@orclxp network_link=dblk_orclasm directory=DATA_PUMP_DIR TABLES=xb_log_lhr PARALLEL=2

正在使用 BLOCKS 方法进行估计...

处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

使用 BLOCKS 方法的总估计: 64 KB

处理对象类型 TABLE_EXPORT/TABLE/TABLE

. . 导入了 "LHR"."XB_LOG_LHR"                              56 行

处理对象类型 TABLE_EXPORT/TABLE/COMMENT

处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/FUNCTIONAL_INDEX/INDEX

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/INDEX/STATISTICS/FUNCTIONAL_INDEX/INDEX_STATISTICS

处理对象类型 TABLE_EXPORT/TABLE/TRIGGER

处理对象类型 TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

作业 "LHR"."SYS_IMPORT_TABLE_01" 已经完成(于 17:21:10 完成)

 

 

C:\Users\Administrator>

 

wps2D8.tmp 

 

5.3  总结

不生成数据文件而直径导入的方法类似于在目标库中执行create table xxx as select * from xxx@dblink ,不过impdp+nework_link一并将数据及其索引触发器等都导入到了目标端,这样就省了很多事情了。


文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐