--=================================
-- 數據泵 IMPDP 導入工具的使用
--=================================
???
??? 數據的導入導出時數據庫經常處理的作業之一, Oracle 提供了 IMP 和 IMPDP 以及 SQL * Loader 等工具來完成數據的導入工作,其中 IMP 服務于早期的 9i 之前的版本,在 10g 及后續版本, Oracle 提供了數據泵高速導入工具,本文主要介紹 IMPDP 的使用方法,關于高速導出工具請參照: 數據泵EXPDP 導出工具的使用 。 SQL * Loader 請參照: SQL*Loader 使用方法 。
?
一、數據泵的體系結構
??? 數據泵的體系結構在數據泵 EXPDP 導出工具的使用已列出,再此不再贅述。
?
二、 IMPDP 支持的接口及導入模式
??? 導入接口
??????? 使用命令行帶參數的
??????? 使用命令行帶參數文件
??????? 使用命令行交互
??????? 使用 database console ( GUI )
??? 幾種常用的導入模式
??????? 導入表
??????? 導入方案
??????? 導入表空間
??????? 導入數據庫
??????? 傳輸表空間模式
???????????????
???????
三、演示如何導入
??? 1. 關于查看 impdp 的幫助,使用以下命令
??????? [oracle@oradb ~]$ impdp - ? ? 或 [oracle@oradb ~]$ impdp - help ? 前者提供幫助信息并開啟命令行交互模式
???
??? 2. 導入表
??????? -- 將表 dept,emp 導入到 scott 方案中
??????? impdp scott / tiger directory = dump_scott dumpfile = tab . dmp tables = dept , emp
?
??????? -- 將表 dept 和 emp 從 scott 方案導入到 system 方案中,對于方案的轉移,必須使用 remap_shcema 參數
??????? impdp system / manage directory = dump_scott dumpfile = tab . dmp tables = scott . dept , scott . emp remap_schema = scott : system
?
??? 3. 導入方案
??????? -- 將 dump_scott 目錄下的 schema.dmp 導入到 scott 方案中
??????? impdp scott / tiger directory = dump_scott dumpfile = schema . dmp schemas = scott
???????
??????? -- 將 scott 方案中的所有對象轉移到 system 方案中
??????? impdp system / redhat directory = dump_scott dumpfile = schema . dmp schemas = scott remap_schema = scott : system
?
??? 4. 導入表空間
??????? impdp system / redhat directory = dump_scott dumpfile = tablespace . dmp tablespaces = user01
???????
??? 5. 導入數據庫
??????? impdp system / redhat directory = dump_scott dumpfile = full . dmp full = y ?????
???????
??? 6. 將數據對象原樣導回 ( 演示從 Windows 客戶端來實現,數據庫基于 Linux 系統 )
??????? 從 Windows 客戶端來導出 scott . emp 表,導出后刪除該表,再原樣導回
??????? 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. 將導出的對象使用 remap_schema 參數轉移到不同的方案
??????? a . 將 dept 從 scott 用戶導入到 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 方案下的所有對象導入到 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 參數轉移到不同的數據文件 ( 用于不同平臺之間存在不同命名方式時 )
??????? 下面的示例首先創建了一個參數文件,參數文件名為 payroll . par
??????????? directory = pump_scott
??????????? full = y
??????????? dumpfile = datafile . dmp
??????????? remap_datafile = 'db$:[hrdata.payroll]tbs2.f' : '/db/hrdata/payroll/tbs2.f' ? -- 指明重新映射數據文件
???
??????????? impdp scott / tiger PARFILE = payroll . par
???
??? 9. 使用 remap_tablespace 參數轉移到不同的表空間
??????? impdp scott / scott remap_tablespace = users : tbs1 directory = dpump_scott dumpfile = users . dmp
???????
??? 10. 并行導入:
??????? 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
?
四、數據泵 impdp 參數:
??? 1.REMAP_DATAFILE
??????? 該選項用于將源數據文件名轉變為目標數據文件名 , 在不同平臺之間搬移表空間時需要該選項 .
??????? REMAP_DATAFILE = source_datafie : target_datafile
?
??? 2.REMAP_SCHEMA
??????? 該選項用于將源方案的所有對象裝載到目標方案中 .
??????? REMAP_SCHEMA = source_schema : target_schema
?
??? 3.REMAP_TABLESPACE
??????? 將源表空間的所有對象導入到目標表空間中
??????? REMAP_TABLESPACE = source_tablespace : target : tablespace
?
??? 4.REUSE_DATAFILES
??????? 該選項指定建立表空間時是否覆蓋已存在的數據文件 . 默認為 N
??????? REUSE_DATAFIELS ={ Y | N}
?
??? 5.SKIP_UNUSABLE_INDEXES
??????? 指定導入是是否跳過不可使用的索引 , 默認為 N
?
??? 6 , sqlfile ? 參數允許創建 DDL 腳本文件
??????? impdp scott / tiger directory = dump_scott dumpfile = a1 . dmp sqlfile = c . sql
??????? 默認放在 directory 下,因此不要指定絕對路徑
?
??? 7.STREAMS_CONFIGURATION
??????? 指定是否導入流元數據 ( Stream Matadata ), 默認值為 Y .
?
??? 8.TABLE_EXISTS_ACTION
??????? 該選項用于指定當表已經存在時導入作業要執行的操作 , 默認為 SKIP
??????? TABBLE_EXISTS_ACTION ={ SKIP | APPEND | TRUNCATE | FRPLACE }
?
??????? 當設置該選項為 SKIP 時 , 導入作業會跳過已存在表處理下一個對象 ;
??????? 當設置為 APPEND 時 , 會追加數據
??? ??? 當設置為 TRUNCATE 時 , 導入作業會截斷表 , 然后為其追加新數據 ;
??????? 當設置為 REPLACE 時 , 導入作業會刪除已存在表 , 重建表并追加數據 ,
??????? 注意 , TRUNCATE 選項不適用與簇表和 NETWORK_LINK 選項
?
??? 9.TRANSFORM
??????? 該選項用于指定是否修改建立對象的 DDL 語句
??????? TRANSFORM = transform_name : value [:object_type]
??????? transform_name 用于指定轉換名 , 其中 SEGMENT_ATTRIBUTES 用于標識段屬性 ( 物理屬性 , 存儲屬性 , 表空間 , 日志等信息 ),
??????? STORAGE 用于標識段存儲屬性 , VALUE 用于指定是否包含段屬性或段存儲屬性 , object_type 用于指定對象類型 .
?
??????? Impdp scott / tiger directory = dump dumpfile = tab . dmp transform = segment_attributes : n : table
?
??? 10.TRANSPORT_DATAFILES
??????? 該選項用于指定搬移空間時要被導入到目標數據庫的數據文件
??????? TRANSPORT_DATAFILE = datafile_name
??? ??? Datafile_name 用于指定被復制到目標數據庫的數據文件
??????? Impdp system / manager DIRECTORY = dump DUMPFILE = tts . dmp
??????? TRANSPORT_DATAFILES = ’ / user01 / data / tbs1 . f’
?
五、影響數據泵性能的相關參數
??????? 對下列參數建議如下設置
??????? disk_asynch_io = true
??????? db_block_checking = false
??????? db_block_checksum = false
?
??????? 對下列參數建議設置更高的值來提高并發
??????? processes ????????????????????
??????? sessions ???
??????? parallel_max_servers ????????????????
???????
??????? 對下列參數應盡可能的調大空間大小
??????? shared_pool_size ???????????????????
??????? undo_tablespace ????????????????????
?
六、更多參考
?
?
?
?
?
? Oracle 聯機重做日志文件(ONLINE LOG FILE)
?
?
?
?
?
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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