--=================================
-- 數(shù)據(jù)泵 IMPDP 導(dǎo)入工具的使用
--=================================
???
??? 數(shù)據(jù)的導(dǎo)入導(dǎo)出時數(shù)據(jù)庫經(jīng)常處理的作業(yè)之一, Oracle 提供了 IMP 和 IMPDP 以及 SQL * Loader 等工具來完成數(shù)據(jù)的導(dǎo)入工作,其中 IMP 服務(wù)于早期的 9i 之前的版本,在 10g 及后續(xù)版本, Oracle 提供了數(shù)據(jù)泵高速導(dǎo)入工具,本文主要介紹 IMPDP 的使用方法,關(guān)于高速導(dǎo)出工具請參照: 數(shù)據(jù)泵EXPDP 導(dǎo)出工具的使用 。 SQL * Loader 請參照: SQL*Loader 使用方法 。
?
一、數(shù)據(jù)泵的體系結(jié)構(gòu)
??? 數(shù)據(jù)泵的體系結(jié)構(gòu)在數(shù)據(jù)泵 EXPDP 導(dǎo)出工具的使用已列出,再此不再贅述。
?
二、 IMPDP 支持的接口及導(dǎo)入模式
??? 導(dǎo)入接口
??????? 使用命令行帶參數(shù)的
??????? 使用命令行帶參數(shù)文件
??????? 使用命令行交互
??????? 使用 database console ( GUI )
??? 幾種常用的導(dǎo)入模式
??????? 導(dǎo)入表
??????? 導(dǎo)入方案
??????? 導(dǎo)入表空間
??????? 導(dǎo)入數(shù)據(jù)庫
??????? 傳輸表空間模式
???????????????
???????
三、演示如何導(dǎo)入
??? 1. 關(guān)于查看 impdp 的幫助,使用以下命令
??????? [oracle@oradb ~]$ impdp - ? ? 或 [oracle@oradb ~]$ impdp - help ? 前者提供幫助信息并開啟命令行交互模式
???
??? 2. 導(dǎo)入表
??????? -- 將表 dept,emp 導(dǎo)入到 scott 方案中
??????? impdp scott / tiger directory = dump_scott dumpfile = tab . dmp tables = dept , emp
?
??????? -- 將表 dept 和 emp 從 scott 方案導(dǎo)入到 system 方案中,對于方案的轉(zhuǎn)移,必須使用 remap_shcema 參數(shù)
??????? impdp system / manage directory = dump_scott dumpfile = tab . dmp tables = scott . dept , scott . emp remap_schema = scott : system
?
??? 3. 導(dǎo)入方案
??????? -- 將 dump_scott 目錄下的 schema.dmp 導(dǎo)入到 scott 方案中
??????? impdp scott / tiger directory = dump_scott dumpfile = schema . dmp schemas = scott
???????
??????? -- 將 scott 方案中的所有對象轉(zhuǎn)移到 system 方案中
??????? impdp system / redhat directory = dump_scott dumpfile = schema . dmp schemas = scott remap_schema = scott : system
?
??? 4. 導(dǎo)入表空間
??????? impdp system / redhat directory = dump_scott dumpfile = tablespace . dmp tablespaces = user01
???????
??? 5. 導(dǎo)入數(shù)據(jù)庫
??????? impdp system / redhat directory = dump_scott dumpfile = full . dmp full = y ?????
???????
??? 6. 將數(shù)據(jù)對象原樣導(dǎo)回 ( 演示從 Windows 客戶端來實現(xiàn),數(shù)據(jù)庫基于 Linux 系統(tǒng) )
??????? 從 Windows 客戶端來導(dǎo)出 scott . emp 表,導(dǎo)出后刪除該表,再原樣導(dǎo)回
??????? C : / > expdp scott / tiger@list2 directory = dump_scott dumpfile = emp . dmp tables = emp
???????
??????? C : / > sqlplus scott / tiger@list2
?
??????? SQL * Plus : Release 10.2.0.1.0 - Production on 星期一 9 月 20 20 : 50 : 35 2010
?
??????? Copyright ( c ) 1982 , 2005 , Oracle . ? All rights reserved .
?
??????? Connected to :
??????? Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
??????? With the Partitioning , OLAP and Data Mining options
?
??????? SQL > drop table emp ;
?
??????? Table dropped .
?
??????? SQL > commit ;
?
??????? Commit complete .
??????? SQL > select count ( 1 ) from emp ;
??????? select count ( 1 ) from emp
??????????????????????????? ? *
??????? ERROR at line 1 :
??????? ORA - 00942 : table or view does not exist
??????? SQL > host impdp scott / tiger@list2 directory = dump_scott dumpfile = emp . dmp
?
??????? SQL > select count ( 1 ) from emp ;
??????? ? COUNT ( 1 )
??????? ----------
??????????????? 14 ?????
?
??? 7. 將導(dǎo)出的對象使用 remap_schema 參數(shù)轉(zhuǎn)移到不同的方案
??????? a . 將 dept 從 scott 用戶導(dǎo)入到 system 用戶下
??????????? expdp scott / tiger directory = dump_scott dumpfile = dept . dmp tables = dept
???????????????
??????????? 方法一:
??????????? impdp system / redhat tables = scott . dept directory = dump_scott dumpfile = dept . dmp remap_schema = scott : system
?
??????????? 方法二:
??????????? sql > grant imp_full_database to scott ;
??????????? impdp scott / tiger directory = dump_scott dumpfile = dept . dmp tables = dept
??????????????? ? remap_schema = scott : system table_exists_action = replace
???
??????? b . 將 scott 方案下的所有對象導(dǎo)入到 system 方案下
??????????? expdp scott / tiger directory = dump_scott dumpfile = allobj . dmp schemas = scott
??????????? impdp scott / tiger directory = dump_scott dumpfile = allobj . dmp remap_schema = scott : system table_exists_action = replace
?
??? 8. 使用 remap_datafile 參數(shù)轉(zhuǎn)移到不同的數(shù)據(jù)文件 ( 用于不同平臺之間存在不同命名方式時 )
??????? 下面的示例首先創(chuàng)建了一個參數(shù)文件,參數(shù)文件名為 payroll . par
??????????? directory = pump_scott
??????????? full = y
??????????? dumpfile = datafile . dmp
??????????? remap_datafile = 'db$:[hrdata.payroll]tbs2.f' : '/db/hrdata/payroll/tbs2.f' ? -- 指明重新映射數(shù)據(jù)文件
???
??????????? impdp scott / tiger PARFILE = payroll . par
???
??? 9. 使用 remap_tablespace 參數(shù)轉(zhuǎn)移到不同的表空間
??????? impdp scott / scott remap_tablespace = users : tbs1 directory = dpump_scott dumpfile = users . dmp
???????
??? 10. 并行導(dǎo)入:
??????? expdp e / e directory = dump_e dumpfile = a_ % u . dmp schemas = e parallel = 3
?
??????? impdp e / e directory = dump_e dumpfile = a_ % u . dmp schemas = e parallel = 3 table_exists_action = replace
?
四、數(shù)據(jù)泵 impdp 參數(shù):
??? 1.REMAP_DATAFILE
??????? 該選項用于將源數(shù)據(jù)文件名轉(zhuǎn)變?yōu)槟繕?biāo)數(shù)據(jù)文件名 , 在不同平臺之間搬移表空間時需要該選項 .
??????? REMAP_DATAFILE = source_datafie : target_datafile
?
??? 2.REMAP_SCHEMA
??????? 該選項用于將源方案的所有對象裝載到目標(biāo)方案中 .
??????? REMAP_SCHEMA = source_schema : target_schema
?
??? 3.REMAP_TABLESPACE
??????? 將源表空間的所有對象導(dǎo)入到目標(biāo)表空間中
??????? REMAP_TABLESPACE = source_tablespace : target : tablespace
?
??? 4.REUSE_DATAFILES
??????? 該選項指定建立表空間時是否覆蓋已存在的數(shù)據(jù)文件 . 默認(rèn)為 N
??????? REUSE_DATAFIELS ={ Y | N}
?
??? 5.SKIP_UNUSABLE_INDEXES
??????? 指定導(dǎo)入是是否跳過不可使用的索引 , 默認(rèn)為 N
?
??? 6 , sqlfile ? 參數(shù)允許創(chuàng)建 DDL 腳本文件
??????? impdp scott / tiger directory = dump_scott dumpfile = a1 . dmp sqlfile = c . sql
??????? 默認(rèn)放在 directory 下,因此不要指定絕對路徑
?
??? 7.STREAMS_CONFIGURATION
??????? 指定是否導(dǎo)入流元數(shù)據(jù) ( Stream Matadata ), 默認(rèn)值為 Y .
?
??? 8.TABLE_EXISTS_ACTION
??????? 該選項用于指定當(dāng)表已經(jīng)存在時導(dǎo)入作業(yè)要執(zhí)行的操作 , 默認(rèn)為 SKIP
??????? TABBLE_EXISTS_ACTION ={ SKIP | APPEND | TRUNCATE | FRPLACE }
?
??????? 當(dāng)設(shè)置該選項為 SKIP 時 , 導(dǎo)入作業(yè)會跳過已存在表處理下一個對象 ;
??????? 當(dāng)設(shè)置為 APPEND 時 , 會追加數(shù)據(jù)
??? ??? 當(dāng)設(shè)置為 TRUNCATE 時 , 導(dǎo)入作業(yè)會截斷表 , 然后為其追加新數(shù)據(jù) ;
??????? 當(dāng)設(shè)置為 REPLACE 時 , 導(dǎo)入作業(yè)會刪除已存在表 , 重建表并追加數(shù)據(jù) ,
??????? 注意 , TRUNCATE 選項不適用與簇表和 NETWORK_LINK 選項
?
??? 9.TRANSFORM
??????? 該選項用于指定是否修改建立對象的 DDL 語句
??????? TRANSFORM = transform_name : value [:object_type]
??????? transform_name 用于指定轉(zhuǎn)換名 , 其中 SEGMENT_ATTRIBUTES 用于標(biāo)識段屬性 ( 物理屬性 , 存儲屬性 , 表空間 , 日志等信息 ),
??????? STORAGE 用于標(biāo)識段存儲屬性 , VALUE 用于指定是否包含段屬性或段存儲屬性 , object_type 用于指定對象類型 .
?
??????? Impdp scott / tiger directory = dump dumpfile = tab . dmp transform = segment_attributes : n : table
?
??? 10.TRANSPORT_DATAFILES
??????? 該選項用于指定搬移空間時要被導(dǎo)入到目標(biāo)數(shù)據(jù)庫的數(shù)據(jù)文件
??????? TRANSPORT_DATAFILE = datafile_name
??? ??? Datafile_name 用于指定被復(fù)制到目標(biāo)數(shù)據(jù)庫的數(shù)據(jù)文件
??????? Impdp system / manager DIRECTORY = dump DUMPFILE = tts . dmp
??????? TRANSPORT_DATAFILES = ’ / user01 / data / tbs1 . f’
?
五、影響數(shù)據(jù)泵性能的相關(guān)參數(shù)
??????? 對下列參數(shù)建議如下設(shè)置
??????? disk_asynch_io = true
??????? db_block_checking = false
??????? db_block_checksum = false
?
??????? 對下列參數(shù)建議設(shè)置更高的值來提高并發(fā)
??????? processes ????????????????????
??????? sessions ???
??????? parallel_max_servers ????????????????
???????
??????? 對下列參數(shù)應(yīng)盡可能的調(diào)大空間大小
??????? shared_pool_size ???????????????????
??????? undo_tablespace ????????????????????
?
六、更多參考
?
?
SPFILE 錯誤導(dǎo)致數(shù)據(jù)庫無法啟動
?
Oracle 用戶、對象權(quán)限、系統(tǒng)權(quán)限
?
?
? Oracle 聯(lián)機(jī)重做日志文件(ONLINE LOG FILE)
?
?
?
?
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
