首先标題不知道是否正确,oracle資料泵好像包含了好多概念,目前隻是零星接觸了一下expdp和impdp工具。據百度而來的資料,oracle10g之後推出的這個工具在性能上要比此前的exp和imp要高,而且支援從高版本向低版本導入和導出,是以在需要學習資料導入導出的時候,直接考慮expdp和impdp了。在此,記錄一下這兩個工具的使用方法。
一、準備:建立邏輯目錄,并賦予oracle對其的讀寫權限
1.使用expdp工具時,其轉存儲檔案隻能被存放在directory對象對應的os目錄中,而不能直接指定轉存儲檔案所在的os目錄。在此,先在作業系統建立目錄d:\dump
2.以system等管理者身份登入sqlplus,授予使用者test對目錄對象dmp_dir的讀寫權限。
create directory dmp_dir as ‘d:\dump’
grant read, write on directory dmp_dir to test
二、導出資料
1.全庫導出模式
expdp test/test@orcl directory=dmp_dir dumpfile=fulldb.dmp full=y
2.使用者導出模式
expdp test/test@orcl directory=dmp_dir dumpfile=userdum.dmp schemas=hgmmo
——導出單個使用者資料(dumpfile指定dump檔案名;schemas指定要被導出資料的使用者)
expdp test/test@orcl directory=dmp_dir dumpfile=userdum.dmp schemas=hgmmo,hgmqo
——導出多個使用者資料
3.表導出模式
expdp system/orcl@orcl directory=dmp_dir dumpfile=tabledum.dmp tables=test.emp, test.dept
——導出test使用者的emp和dept兩個表
expdp system/orcl@orcl directory=dmp_dir dumpfile=tabledum.dmp tables=test.emp query='where deptno=20'
——導出表中符合指定條件的資料,使用query條件的語句較長時采用parfile方式,參見:http://hi.baidu.com/sevenqxy/blog/item/055ee6edcdac2e4679f05512.html
4.表空間導出模式
expdp system/orcl@orcl directory=dmp_dir dumpfile=dumptbs.dmp tablespaces=tbs1,tbs2
5.可移動表空間導出模式(隻導出表空間的中繼資料,不真正導出資料)
expdp system/orcl@orcl directory=dmp_dir dumpfile=dumptbs.dmp transport_tablespaces=tbs1
三、導入資料
1.全庫模式導入
impdp test/test@orcl directory=dmp_dir dumpfile=fulldb.dmp full=y
2.使用者模式導入
expdp test/test@orcl directory=dmp_dir dumpfile=userdum.dmp remap_schema=user1:user2
——remap_schema參數相當于imp工具中的fromuser和touser參數,可以實作将一個使用者的資料導入到另一個使用者中
3.表空間模式導入
impdp system/orcl@orcl directory=dmp_dir dumpfile=dumptbs.dmp tablespaces=tbs1
5.追加資料
impdp system/manager directory=dpdata1 dumpfile=expdp.dmp schemas=system table_exists_action=append
四、 将高版本資料導入低版本中
1.查詢oracle版本資訊
sql>show parameter compatible
2.使用version參數導入導出資料
expdp test/test@orcl directory=dmp_dir dumpfile=userdum.dmp schemas=hgmmo version =10.2.0.1.0
impdp test/test@orcl directory=dmp_dir dumpfile=userdum.dmp schemas=hgmmo version =10.2.0.1.0
參數彙總:
----------------------------expdp/impdp的相關參數----------------------------
expdp指令行選項
1. attach
該選項用于在客戶會話與已存在導出作用之間建立關聯.文法如下
attach=[schema_name.]job_name
schema_name用于指定方案名,job_name用于指定導出作業名.注意,如果使用attach選項,在指令行除了連接配接字元串和attach選項外,不能指定任何其他選項,示例如下:
expdp scott/tiger attach=scott.export_job
2. content
該選項用于指定要導出的内容.預設值為all
content={all | data_only | metadata_only}
當設定content為all 時,将導出對象定義及其所有資料.為data_only時,隻導出對象資料,為metadata_only時,隻導出對象定義
expdp scott/tiger directory=dump dumpfile=a.dump
content=metadata_only
3. directory
指定轉儲檔案和日志檔案所在的目錄
directory=directory_object
directory_object用于指定目錄對象名稱.需要注意,目錄對象是使用create directory語句建立的對象,而不是os 目錄
建立目錄:
create directory dump as ‘d:dump’;
查詢建立了那些子目錄:
select * from dba_directories;
4. dumpfile
用于指定轉儲檔案的名稱,預設名稱為expdat.dmp
dumpfile=[directory_object:]file_name [,….]
directory_object用于指定目錄對象名,file_name用于指定轉儲檔案名.需要注意,如果不指定directory_object,導出工具會自動使用directory選項指定的目錄對象
expdp scott/tiger directory=dump1 dumpfile=dump2:a.dmp
5. estimate
指定估算被導出表所占用磁盤空間分方法.預設值是blocks
extimate={blocks | statistics}
設定為blocks時,oracle會按照目标對象所占用的資料塊個數乘以資料塊尺寸估算對象占用的空間,設定為statistics時,根據最近統計值估算對象占用空間
expdp scott/tiger tables=emp estimate=statistics
directory=dump dumpfile=a.dump
6. extimate_only
指定是否隻估算導出作業所占用的磁盤空間,預設值為n
extimate_only={y | n}
設定為y時,導出作用隻估算對象所占用的磁盤空間,而不會執行導出作業,為n時,不僅估算對象所占用的磁盤空間,還會執行導出操作.
expdp scott/tiger estimate_only=y nologfile=y
7. exclude
該選項用于指定執行操作時釋放要排除對象類型或相關對象
exclude=object_type[:name_clause] [,….]
object_type用于指定要排除的對象類型,name_clause用于指定要排除的具體對象.exclude和include不能同時使用
expdp scott/tiger directory=dump dumpfile=a.dup exclude=view
8. filesize
指定導出檔案的最大尺寸,預設為0,(表示檔案尺寸沒有限制)
9. flashback_scn
指定導出特定scn時刻的表資料
flashback_scn=scn_value
scn_value用于辨別scn值.flashback_scn和flashback_time不能同時使用
expdp scott/tiger directory=dump dumpfile=a.dmp
flashback_scn=358523
10. flashback_time
指定導出特定時間點的表資料
flashback_time=”to_timestamp(time_value)”
expdp scott/tiger directory=dump dumpfile=a.dmp flashback_time=
“to_timestamp(’25-08-2004 14:35:00’,’dd-mm-yyyy hh24:mi:ss’)”
11. full
指定資料庫模式導出,預設為n
full={y | n}
為y時,辨別執行資料庫導出.
12. help
指定是否顯示expdp指令行選項的幫助資訊,預設為n
當設定為y時,會顯示導出選項的幫助資訊.
expdp help=y
13. include
指定導出時要包含的對象類型及相關對象
include = object_type[:name_clause] [,… ]
14. job_name
指定要導出作業的名稱,預設為sys_xxx
job_name=jobname_string
15. logfile
指定導出日志檔案檔案的名稱,預設名稱為export.log
logfile=[directory_object:]file_name
directory_object用于指定目錄對象名稱,file_name用于指定導出日志檔案名.如果不指定directory_object.導出作用會自動使用directory的相應選項值.
expdp scott/tiger directory=dump dumpfile=a.dmp logfile=a.log
16. network_link
指定資料庫鍊名,如果要将遠端資料庫對象導出到本地例程的轉儲檔案中,必須設定該選項.
17. nologfile
該選項用于指定禁止生成導出日志檔案,預設值為n.
18. parallel
指定執行導出操作的并行程序個數,預設值為1
19. parfile
指定導出參數檔案的名稱
parfile=[directory_path] file_name
20. query
用于指定過濾導出資料的where條件
query=[schema.] [table_name:] query_clause
schema 用于指定方案名,table_name用于指定表名,query_clause用于指定條件限制子句.query選項不能與 connect=metadata_only,extimate_only,transport_tablespaces等選項同時使用.
expdp scott/tiger directory=dump dumpfiel=a.dmp
tables=emp query=’where deptno=20’
21. schemas
該方案用于指定執行方案模式導出,預設為目前使用者方案.
22. status
指定顯示導出作用程序的詳細狀态,預設值為0
23. tables
指定表模式導出
tables=[schema_name.]table_name[:partition_name][,…]
schema_name用于指定方案名,table_name用于指定導出的表名,partition_name用于指定要導出的分區名.
24. tablespaces
指定要導出表空間清單
25. transport_full_check
該選項用于指定被搬移表空間和未搬移表空間關聯關系的檢查方式,預設為n.
當設定為y時,導出作用會檢查表空間直接的完整關聯關系,如果表空間所在表空間或其索引所在的表空間隻有一個表空間被搬移,将顯示錯誤資訊.當設定為n時, 導出作用隻檢查單端依賴,如果搬移索引所在表空間,但未搬移表所在表空間,将顯示出錯資訊,如果搬移表所在表空間,未搬移索引所在表空間,則不會顯示錯誤資訊.
26. transport_tablespaces
指定執行表空間模式導出
27. version
指定被導出對象的資料庫版本,預設值為compatible.
version={compatible | latest | version_string}
為compatible時,會根據初始化參數compatible生成對象中繼資料;為latest時,會根據資料庫的實際版本生成對象中繼資料.version_string用于指定資料庫版本字元串.調用expdp
使用expdp工具時,其轉儲檔案隻能被存放在directory對象對應的os目錄中,而不能直接指定轉儲檔案所在的os目錄.是以,
使用expdp工具時,必須首先建立directory對象.并且需要為資料庫使用者授予使用directory對象權限.
3) 在同一個資料庫中把一個schema中所有的對象複制到另一個schema中。
一、expdp&impdp和exp&imp的用法差別
1:把使用者usera的對象導到使用者userb,用法差別在于fromuser=usera touser=userb ,remap_schema='usera':'usera' 。例如:imp
system/passwd fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;
impdp system/passwd directory=expdp dumpfile=expdp.dmp remap_schema='usera':'userb' logfile=/oracle/exp.log;
2:更換表空間,用exp/imp的時候,要想更改表所在的表空間,需要手工去處理一下,
如alter table xxx move tablespace_new之類的操作。
用impdp隻要用remap_tablespace='tabspace_old':'tablespace_new'
3:當指定一些表的時候,使用exp/imp 時,tables的用法是 tables=('table1','table2','table3')。
expdp/impdp的用法是tables='table1','table2','table3'
4:是否要導出資料行
exp (rows=y 導出資料行,rows=n 不導出資料行)
expdp content(all:對象+導出資料行,data_only:隻導出對象,metadata_only:隻導出資料的記錄)
把一個使用者的所有内容導出到另一庫裡,這個用expdp/impdp最好了,
有覆寫表的功能參數table_exists_action=replace
一:exp/imp 的指令行選項如下:
二 imp/exp 的功能
a.導出單個使用者單個表
b.導出單個使用者多個表
c.導出單個使用者及其内容
d.導出多個使用者及其内容
e.導出整個資料庫(包括資料)
f.導出整個資料庫(不包括資料)
g.導入單個使用者單個表
如果表t已經存在則導入會報錯, 這時隻要在後面加上 ignore=y ,就可以導入,即使是重複資料也會被導入到表中。導入包含了隐形的送出操作
h.導入單個使用者多個表
i.導入單個使用者及其内容
g.導入多個使用者及其内容
k.導入整個資料庫(包括資料)
l.導入整個資料庫(不包括資料)
m.導出單個、多個表空間
drop tablespace business including contents and datafiles 删除表空間的内容,删除表空間的時候表空間内的user不會被删除,他們的表空間會被指定為預設的表空間。
n.導入單個、多個表空間
導入表空間時,表空間要先建好,否則無法導入。
o.把導出中的部分表資料導入
三. impdp/expdp的功能
a.建立目錄,給所有使用者授予目錄的讀寫權限。
create directory dump_dir as 'e:\oraclepractice'
grant read,write on directory log_dir to public
create directory log_dir as 'e:\oraclepractice'
grant read,write on directory log_dir to public;
b.導出表
反複導出的時候,如果原來的導出檔案名已經存在expdp會報錯退出,這跟exp是不同的。
c.導入表
d.導出使用者
e.導入使用者
f.導出表空間
g.導入表空間
導入表空間的時候如果表空間不存在是不能成功導入的。
h.導出資料庫
i.導入資料庫
熱6已有
2278 次閱讀 2011-03-27 09:48
它山之石:
1:把使用者usera的對象導到使用者userb,用法差別在于fromuser=usera
touser=userb ,remap_schema='usera':'usera' 。例如:imp system/passwd
fromuser=usera touser=userb file=/oracle/exp.dmp log=/oracle/exp.log;
分類: linux
如果導入到某個使用者下面,必須指定fromuser和touser,如果touser的使用者目前還不存在導入也不會成功。而且此使用者需要有以前使用者相同的權限。
full=y
tables=(t,ttt)