ORACLE 資料泵之NETWORK_LINK
資料泵之NETWORK_LINK
blog結構圖:
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客戶端執行
圖形關係如下:
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 行
成功終止匯入, 沒有出現警告。
而檔案也的確是在本機的:
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下載:
將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>
然後再進行匯入操作:
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>
日誌檔案路徑:
這樣操作是否非常麻煩,那麼如何將生成的檔案放在目標資料庫而不放在源資料庫呢,在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>
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>
結果:
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>
.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>
5.3 總結
不生成資料檔案而直徑匯入的方法類似於在目標庫中執行create table xxx as select * from xxx@dblink ,不過impdp+nework_link一併將資料及其索引觸發器等都匯入到了目標端,這樣就省了很多事情了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-1432591/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle邏輯備份之--資料泵Oracle
- Oracle資料泵(Oracle Data Pump) 19cOracle
- Oracle資料庫(資料泵)遷移方案(上)Oracle資料庫
- Oracle資料庫(資料泵)遷移方案(下)Oracle資料庫
- 資料庫升級之-資料泵資料庫
- Oracle expdp資料泵遠端匯出Oracle
- 【ASK_ORACLE】重灌Oracle資料泵(Datapump)工具的方法Oracle
- Oracle Data Pump 11G 資料泵元件Oracle元件
- Oracle資料泵匯出匯入(expdp/impdp)Oracle
- 史上最全Oracle資料泵常用命令Oracle
- Oracle資料泵的匯入和匯出Oracle
- ORACLE 資料泵impdp匯入報錯之ORA-31693 ORA-04098Oracle
- Oracle資料庫的邏輯備份工具-expdp資料泵Oracle資料庫
- Oracle使用資料泵expdp,impdp進行資料匯出匯入Oracle
- 【Datapump】Oracle資料泵遷移資料命令參考(expdp/impdp說明)Oracle
- 【BUILD_ORACLE】使用Oracle資料泵線上不停機克隆/遷移PDBUIOracle
- Oracle 12C新特性-資料泵新引數(LOGTIME)Oracle
- 【DATAPUMP】Oracle資料泵定時備份刪除指令碼Oracle指令碼
- 殺停資料泵
- Oracle用資料泵匯入資料包12899的錯誤碼解決方法Oracle
- OGG之 各種資料泵初始化指令碼指令碼
- Oracle 12C新特性-資料泵新引數(VIEWS_AS_TABLES)OracleView
- 資料泵重建使用者
- 資料泵匯出匯入
- 【DB筆試面試164】在Oracle中,如何徹底停止expdp資料泵程式?筆試面試Oracle
- 【ASK_ORACLE】資料泵由於”Streams AQ: Enqueue Blocked On Low Memory" 問題變慢OracleENQBloC
- Oracle資料泵建立使用者避坑(表空間配額、許可權)Oracle
- Java程式呼叫expdp資料泵實現自動邏輯備份Oracle資料庫的方案設計JavaOracle資料庫
- 使用資料泵(expdp、impdp)遷移資料庫流程資料庫
- ORACLE 資料泵expdp莫名其妙的報錯ORA-31693&ORA-19502&ORA-27063Oracle
- 使用impdp,expdp資料泵進入海量資料遷移
- Oracle資料庫恢復之resetlogsOracle資料庫
- oracle10g expdp資料泵的bug,按schema匯出,匯入impdp時無jobOracle
- 異構資料庫資料遷移 oracle to mysql之oracle sqlloader和mysql load data資料庫OracleMySql
- Oracle insert大量資料經驗之談Oracle
- 【ASK_ORACLE】刪除DBA_DATAPUMP_JOBS檢視中的異常資料泵JOB的方法Oracle
- 【DATAPUMP】Oracle資料泵優化及提高效率的一些引數介紹Oracle優化
- 資料泵的TRANSFORM引數說明及使用ORM
- 細緻入微:如何使用資料泵匯出表的部分列資料