ORACLE 数据泵之NETWORK_LINK

简介:  数据泵之NETWORK_LINK blog结构图:   1  环境介绍   SOURCE DB...

 数据泵之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  impexp简介

 

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

 

来验证expimp

 

我们在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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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 星期二 210 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一并将数据及其索引触发器等都导入到了目标端,这样就省了很多事情了。

相关实践学习
数据库实验室挑战任务-初级任务
本场景介绍如何开通属于你的免费云数据库,在RDS-MySQL中完成对学生成绩的详情查询,执行指定类型SQL。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
目录
相关文章
|
8月前
|
Oracle 关系型数据库 数据库
通过数据泵expdp、impdp方式备份与还原(导出与导入)Oracle数据库
通过数据泵expdp、impdp方式备份与还原(导出与导入)Oracle数据库
|
11月前
|
SQL Oracle 关系型数据库
Oracle-数据泵expdp/impdp实操
Oracle-数据泵expdp/impdp实操
260 0
|
Oracle 关系型数据库 OLAP
Oracle 11.2.0.4数据泵expdp导出报DBMS_AW_EXP等信息
Oracle 11.2.0.4数据泵expdp导出报DBMS_AW_EXP等信息
255 0
|
Oracle 关系型数据库
Oracle数据泵导出导入报错stopped due to fatal error
Oracle数据泵导出导入报错stopped due to fatal error
463 0
|
SQL Oracle 关系型数据库
Oracle 数据泵迁移用户创建 SQL语句
在进行数据泵迁移时,通常是按照用户进行导入导出,因此需要确认当前数据库中存在那些非系统用户!
|
Oracle 关系型数据库 数据库
Oracle之数据泵导入/导出数据
以前习惯用imp/exp导入导出数据,现在我们来搞一把数据泵导入导出的方法。它比之于imp/exp的方式的优点自不必说---速度快! 但是很不幸,我在导出数据的时候报错了,我擦,这特么就尴尬了。
1376 0
|
Oracle 关系型数据库 数据库
|
SQL Oracle 关系型数据库