ORACLE 資料泵之NETWORK_LINK

531968912發表於2016-08-03

 資料泵之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一併將資料及其索引觸發器等都匯入到了目標端,這樣就省了很多事情了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-1432591/,如需轉載,請註明出處,否則將追究法律責任。

相關文章