天天看點

Oracle10g 資料泵導出指令 expdp 使用總結

 expdp使用

使用expdp工具時,其轉儲檔案隻能被存放在directory對象對應的os目錄中,而不能直接指定轉儲檔案所在的os目錄.是以使用expdp工具時,必須首先建立directory對象.并且需要為資料庫使用者授予使用directory對象權限.

首先得建directory:

sql> conn /as sysdba

sql> create or replace directory dir_dump  as '/u01/backup/';

sql> grant read,write on directory dir_dump to public;

1) 導出scott整個schema

--預設導出登陸賬号的schema

$ expdp scott/tiger@db_esuite parfile=/orahome/expdp.par

expdp.par内容:

    directory=dir_dump

    dumpfile=scott_full.dmp

    logfile=scott_full.log

--其他賬号登陸, 在參數中指定schemas

$ expdp system/oracle@db_esuite parfile=/orahome/expdp.par

    schemas=scott

2) 導出scott下的dept,emp表

    dumpfile=scott.dmp

    logfile=scott.log

    tables=dept,emp

3) 導出scott下除emp之外的表

    exclude=table:"='emp'"

4) 導出scott下的存儲過程

    include=procedure

5) 導出scott下以'e'開頭的表

    include=table:"like 'e%'"   //可以改成not like,就導出不以e開頭的表

6) 帶query導出

    tables=emp,dept

    query=emp:"where empno>=8000"

    query=dept:"where deptno>=10 and deptno<=40"

注: 處理這樣帶查詢的多表導出, 如果多表之間有外健關聯, 可能需要注意查詢條件所篩選的資料是否符合這樣的外健限制, 比如 emp中有一欄位是 deptno, 是關聯dept中的主鍵, 如果"where empno>=8000"中得出的deptno=50的話, 那麼, 你的dept的條件"where deptno>=10 and deptno<=40"就不包含deptno=50的資料, 那麼在導入的時候就會出現錯誤.

 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 目錄,示例如下:

expdp scott/tiger directory=dump dumpfile=a.dump

建立目錄:

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

一般情況下, 當用預設值(blocks)時, 日志中估計的檔案大小會比實際expdp出來的檔案大, 用statistics時會跟實際大小差不多.

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

在expdp的幫助檔案中, 可以看到存在exclude和include參數, 這兩個參數文檔中介紹的指令格式存在問題, 正确用法是:

exclude=object_type[:name_clause][,...]

include=object_type[:name_clause][,...]

示例:

expdp   schema=scott exclude=sequence,table:"in('emp','dept')"

impdp   schema=scott include=function,package,procedure,table:"='emp'"

有了這些還不夠, 由于指令中包含了多個特殊字元, 在不同的作業系統下需要通過轉義字元才能使上面的指令順利執行,

如:

exclude=table:\"in('bigtale')\"

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][,… ]

expdp scott/tiger directory=dump dumpfile=a.dmp include=trigger

14. job_name

指定要導出作用的名稱,預設為sys_xxx.文法如下:

job_name=jobname_string

expdp scott/tiger directory=dump dumpfile=a.dmp include=trigger job_name=exp_trigger

後面想臨時停止expdp任務時可以按ctrl+c組合鍵,退 出目前互動模式,退出之後導出操作不會停止,這不同于oracle以前的exp. 以前的exp,如果退出互動式模式,就會出錯終止導出任務. 在 oracle10g中,由于expdp是資料庫内部定義的任務,已經與用戶端無關. 退出互動之後,會進入export的指令行模式,此時支援 status等檢視指令:

export> status

如果想停止改任務,可以發出stop_job指令:

export> stop_job

如果有指令行提示: "是否确實要停止此作業([y]/n):" 或 "are you sure you wish to stop this job ([yes]/no):", 回答應是yes或者no, 回答是yes以後會退出目前的export界面.

接下來可以通過指令行再次連接配接到這個任務:

expdp test/test@acf attach=expfull

通過start_job指令重新啟動導出:

export> start_job

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

指定資料庫鍊名,如果要将遠端資料庫對象導出到本地例程的轉儲檔案中,必須設定該選項.

expdp中使用連接配接字元串和network_link的差別:

expdp屬于服務端工具,而exp屬于用戶端工具,expdp生成的檔案預設是存放在服務端的,而exp生成的檔案是存放在用戶端.

expdp username/password@connect_string //對于使用這種格式來說,directory使用源資料庫建立的,生成的檔案存放在服務端。

如何将生成的檔案放在目标資料庫而不放在源資料庫呢,在expdp中使用network_link. 比如在本機expdp遠端伺服器的資料庫,先在本機建立到服務端的dblink,然後建立directory及授權,然後expdp.

a) 建立到服務端的dblink

conn aa/aacc

create database link link_name connect to bb identified by password using 'connect_string';

b) 建立directory

conn / as sysdba

create or replace directory dir as 'directory';

grant read,write on directory dir to bb;

c) 通過network_link導出

expdp aa/aacc directory=dir network_link=link_name ...

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用于指定資料庫版本字元串.