impdp和expdp使用總結

2021-09-12 09:47:31 字數 3553 閱讀 8575

今天在專案中遇到了如下情況:備份恢復一張資料量比較大(大約200w條記錄,約119m大小)的表時,使用慣用的exp/imp工具進行操作時,工具直接卡死(或是操作時間過長)。於是想起之前使用過的impdp/expdp資料幫浦工具,其優點在於大資料量匯入匯出時高效快捷。使用資料幫浦後,漫長的大表匯出過程變得快速高效,想到自己好久沒有進行技術總結,故在此將impdp/expdp的使用總結一下,以便之後查閱。

建立語句:

create or replace directory dmp as 'd:/dmp'

其中dmp為directory名稱,as後接directory路徑,需要在指定路徑下自行建立指定資料夾。

建立directory所需許可權:create any directory

該選項用於指定要匯出的內容.預設值為all

content=

當設定content為all時,將匯出物件定義及其所有資料.為data_only時,只匯出物件資料,為metadata_only時,只匯出物件定義

用於指定轉儲檔案的名稱,預設名稱為expdat.dmp

dumpfile=[directory_object:]file_name [,….]

directory_object用於指定目錄物件名,file_name用於指定轉儲檔名.需要注意,如果不指定directory_object,匯出工具會自動使用directory選項指定的目錄物件

建立directory

create directory dir_dp as 'd:/oracle/dir_dp';

授權

grant read,write on directory dir_name to user_name;

檢視目錄及許可權

select privilege, directory_name, directory_path from user_tab_privs t, all_directories d

where t.table_name(+) = d.directory_name order by 2, 1;

執行匯出

expdp zftang/zftang@fgisdb schemas=zftang directory=dir_dp dumpfile =expdp_test1.dmp logfile=expdp_test1.log;

備註:

expdp zftang/zftang@fgisdb schemas=schema_name directory=dir_name dumpfile =dmp_name.dmp

logfile=log_name.log,job_name=myjob_name;

按表模式匯出:

expdp zftang/zftang@fgisdb tables=zftang.b$i_exch_info,zftang.b$i_manhole_info dumpfile =expdp_test2.dmp logfile=expdp_test2.log directory=dir_dp job_name=my_job

按查詢條件匯出:

expdp zftang/zftang@fgisdb tables=zftang.b$i_exch_info dumpfile =expdp_test3.dmp logfile=expdp_test3.log directory=dir_dp job_name=my_job query='"where rownum<11"'

按表空間匯出:

expdp zftang/zftang@fgisdb dumpfile=expdp_tablespace.dmp tablespaces=gcomm.dbf logfile=expdp_tablespace.log directory=dir_dp job_name=my_job

匯出方案:

expdp zftang/zftang directory=dir_dp dumpfile=schema.dmp schemas=zftang,gwm

匯出整個資料庫:

expdp zftang/zftang@fgisdb dumpfile =full.dmp full=y logfile=full.log directory=dir_dp job_name=my_job

按表匯入:

p_street_area.dmp檔案中的表,此檔案是以gwm使用者按schemas=gwm匯出的:

impdp gwm/gwm@fgisdb dumpfile =p_street_area.dmp logfile=imp_p_street_area.log directory=dir_dp tables=p_street_area job_name=my_job

按使用者匯入(可以將使用者資訊直接匯入,即如果使用者資訊不存在的情況下也可以直接匯入):

impdp gwm/gwm@fgisdb schemas=gwm dumpfile =expdp_test.dmp logfile=expdp_test.log directory=dir_dp job_name=my_job

不通過expdp的步驟生成dmp檔案而直接匯入的方法:

--從源資料庫中向目標資料庫匯入表p_street_area

impdp gwm/gwm directory=dir_dp network_link=igisdb tables=p_street_area logfile=p_street_area.log job_name=my_job

igisdb是目的資料庫與源資料的鏈結名,dir_dp是目的資料庫上的目錄

更換表空間

採用remap_tablespace引數

--匯出gwm使用者下的所有資料

expdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp schemas=gwm

注:

如果是用sys使用者匯出的使用者資料,包括使用者建立、授權部分,用自身使用者匯出則不含這些內容

--以下是將gwm使用者下的資料全部匯入到表空間gcomm(原來為gmapdata表空間下)下:

impdp system/orcl directory=data_pump_dir dumpfile=gwm.dmp remap_tablespace=gmapdata:gcomm

oracle使用expdp和impdp搭建資料庫

檢視幫助 expdp help parallel 是並行數,expdp和impdp都可以使用這個引數 expdp匯出 1.建立資料幫浦路徑 sql create or replace directory imostdb as opt oracle imost directory created.需確...

使用expdp和impdp遠端匯入匯出庫

tnames.ora增加 html view plain copy orcl description address list address protocol tcp host 遠端主機ip port 1521 connect data service name 遠端服務名 html view p...

oracle的expdp和impdp命令研究

建立遠端資料連線 create database link db mzdb11 connect to ytmztwo identified by ytmztwo909 using mzdb11 建立本地目錄 create directory db mz as c 授權使用者讀寫 grant read...