資料泵基礎(impdp/expdp)

leon830216發表於2014-03-01
支援資料庫版本:10gR2

- 注意事項

expdp可以在客戶端或伺服器端執行,但檔案最終儲存在伺服器端
exp命令在哪裡執行,就匯出到哪裡
dbms_datapump --- pl/sql中呼叫

- 前期準備

建立轉存目錄
create directory backup_dir as 'c:\backup_dir'

賦予使用者訪問許可權
grant read,write on directory backup_dir to scott

查詢建立了哪些目錄
select * from dba_directories

匯入匯出命令
- 如果採用sysdba使用者
expdp 'sys/admin as sysdba'

- 表 --- tables=go.emp,scott.dept
匯出匯入指定表,表相關物件(索引,約束等,這些物件需要於表在相同表空間或匯出使用者具有匯出許可權)
向其他使用者匯入需要imp_full_database許可權
表可以指定 *
tables=scott.emp:p1   --- 表分割槽
tables=scott.e%

- 案(預設模式) --- schemas=scott,hr
有exp_full_database許可權則可以到處其他schema的表
預設不會匯出在本schema的物件的在其他schema中的關聯物件(如emp表的index在其他schema中時)
除非那個schema也在列表中出現,匯入也同樣

- 匯出表空間 --- tablespaces=users01,users02
到處指定表空間中,屬於本使用者的物件
匯出指定表空間中所有物件,需要exp_full_database許可權

- 匯出資料庫 --- full=y
需要exp_full_database許可權
grant exp_full_database to go

- 傳輸表空間 --- transport_tablespaces
需要exp/imp_full_database
匯出的是原資料,需要複製dmp和資料檔案到目標庫

- 過濾物件或資料
過濾資料
如果沒有指定表名則針對所有被匯出的表
建議放在parfile中
query=emp:"where id>5",dept:"where id<2"
sample=emp:50,dept:10 --- 匯出資料的百分比 

過濾物件
指定任何物件型別和物件名字(支援*)
建議放在parfile中
include,exclude不能同時出現
exclude=index:"like 'IDX_EMP%'",constraint:"like 'CHK_EMP%'",grant
---------------------------------------------------------------------------------
多種情況對應

- 指定過濾條件 --- tables,include,exclude,query
注意tables和include條件中的大小寫,和跳脫字元
expdp go/go tables=\(go.e%\) directory=dump_file_dir query=\"where mgr=7698\" dumpfile=emp.dmp;
expdp go/go include=table:\"like \'E%\'\" directory=dump_file_dir query=emp:\"where mgr=7698\" dumpfile=expdp.dmp;

- 跨資料庫鏈方式匯出 --- network_link
間接實現匯出遠端資料庫物件到本地 ???

- 並行方式(不支援標準版) --- parallel + filesize
小資料量不一定能提高效率,設定不合理可能會影響效率
expdp go/go directory=dump_file_dir dumpfile=expdp.dmp parallel=2 filesize=30m;

- 僅匯入物件定義 --- content=all,data_only,metadata_only

- 匯入時清楚物件儲存的原資料 --- table_exists_action=skip,append,truncate,replace

- 匯入時重定義schema和表空間
remap_schema=scott:go,go:scott --- 同一impdp不能指定scott:go,scott:hr
remap_tablespace=users01:users02,users03:users04

- 退出輸出模式,進入互動管理模式 --- CTL+C
- 連線到輸出模式 --- expdp go/go attach=job_name
不指定attach則自動連線到當前任務
-- 執行管理操作
Export> add_file=exp_1_%U.dmp,exp_2_%U.dmp --- 新增輸出檔案,僅用於expdp
Export> continue_client --- 回到輸出模式
Export> exit_client --- 退出,回到OS命令列,expdp轉為後臺執行
Export> filesize=1G --- 指定最大檔案大小(G,M,K,B)
Export> help --- 顯示幫助

- 引數檔案
建立expdp.par
userid=go/go
schemas=scott,hr
dumpfile=scott%U.dmp
directory=backup_dir
logfile=scott.log
job_name=export_job

執行匯出
expdp go/go parfile=c:\backup\expdp.par

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

相關文章