十年網(wǎng)站開(kāi)發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專(zhuān)業(yè)推廣+無(wú)憂售后,網(wǎng)站問(wèn)題一站解決
這篇文章主要介紹“Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些”,在日常操作中,相信很多人在Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”O(jiān)racle數(shù)據(jù)泵技術(shù)常用操作有哪些”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的烏什網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
1.為什么選擇數(shù)據(jù)泵
數(shù)據(jù)泵是Oracle 10g開(kāi)始引入的新技術(shù),對(duì)現(xiàn)在來(lái)說(shuō)已經(jīng)不是新技術(shù)了,11g都已經(jīng)結(jié)束標(biāo)準(zhǔn)支持期了。技術(shù)更新
從10g版本開(kāi)始,數(shù)據(jù)泵技術(shù)跟隨新版本進(jìn)行不斷的完善,對(duì)新版本的Oracle數(shù)據(jù)庫(kù)具有更強(qiáng)的適應(yīng)性。BUG更少
數(shù)據(jù)泵可以使用直接路徑、并行等特性,對(duì)大數(shù)據(jù)量的遷移來(lái)說(shuō),具有更好的性能,可以減少大量導(dǎo)入導(dǎo)出時(shí)間。性能更好
exp/imp不能導(dǎo)出空表,而且由于從10g開(kāi)始停止更新,后面版本引入的新對(duì)象都不支持導(dǎo)出,如自定義對(duì)象。功能更強(qiáng)
1.1.與exp/imp的主要區(qū)別
? exp/imp是客戶端工具,可以在客戶端使用;數(shù)據(jù)泵是服務(wù)端工具,只能在服務(wù)端使用。
? exp/imp不能導(dǎo)出空表;數(shù)據(jù)泵可以。
? exp/imp跟數(shù)據(jù)泵導(dǎo)出的文件不能通用。
2.基本概念
數(shù)據(jù)泵的命令行命令是expdp/impdp,是一種數(shù)據(jù)庫(kù)之間移動(dòng)數(shù)據(jù)的工具。
目錄(directory)是Oracle的一種對(duì)象類(lèi)型,可以認(rèn)為是一個(gè)指向物理存儲(chǔ)路徑的指針,用來(lái)指定數(shù)據(jù)泵導(dǎo)出導(dǎo)入文件使用的路徑。
模式(schema)是一組數(shù)據(jù)庫(kù)對(duì)象的集合,一般一個(gè)用戶對(duì)應(yīng)一個(gè)schema。
3.基本步驟
3.1創(chuàng)建目錄
SQL> create directory dump_dir as '/home/oracle/dump'; |
dump_dir 是目錄名稱(chēng);可以根據(jù)實(shí)際情況自己定義,不重復(fù)即可,如果系統(tǒng)中已經(jīng)存在,可以直接使用;
/home/oracle/dump 是操作系統(tǒng)物理路徑;必須保證該路徑真實(shí)存在,并具有足夠空間存放備份文件;
3.2授權(quán)
SQL> grant read,write on directory dump_dir to public; |
dump_dir 是上面創(chuàng)建得目錄名稱(chēng);
public 表示這個(gè)目錄是公開(kāi)的;也可以針對(duì)某個(gè)用戶授權(quán);
3.3執(zhí)行導(dǎo)入導(dǎo)出
$ expdp system/dbmanager directory=dump_dir full=Y dumpfile=full_20190101.dmp logfile=full_expdp_20190101.log |
$ impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log |
system 是導(dǎo)出命令所用的用戶;
dbmanager 是system用戶的密碼;
dump_dir 是上面創(chuàng)建得目錄名稱(chēng);
full=Y 表示全庫(kù)導(dǎo)出;
dumpfile/logfile 根據(jù)實(shí)際情況命名即可;該命名需要能夠描述備份的內(nèi)容及時(shí)間等基本信息;該命名重復(fù)的話會(huì)覆蓋;
4.常用方式
4.1 expdp導(dǎo)出
##導(dǎo)出一張表,例: expdp system/dbmanager directory=dump_dir dumpfile=emp_20190101.dmp logfile=emp_expdp_20190101.log tables=scott.emp ##導(dǎo)出多張表,例: expdp system/dbmanager directory=dump_dir dumpfile=empdept_20190101.dmp logfile=empdept_expdp_20190101.log tables=\(scott.emp,scott.dept\) ##導(dǎo)出一個(gè)用戶(導(dǎo)出這個(gè)用戶的所有對(duì)象),例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp logfile=scott_expdp_20190101.log schemas=scott ##導(dǎo)出多個(gè)用戶,例: expdp system/dbmanager directory=dump_dir dumpfile=scotthr_20190101.dmp logfile=scotthr_expdp_20190101.log schemas=\(scott,hr\) ##導(dǎo)出整個(gè)數(shù)據(jù)庫(kù)(sys的用戶數(shù)據(jù)不會(huì)被導(dǎo)出),例: expdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_expdp_20190101.log full=y ##并行導(dǎo)出,例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101_%U.dmp logfile=scott_expdp_20190101.log schemas=scott parallel=8 ##導(dǎo)出用戶元數(shù)據(jù)(包含表定義、存儲(chǔ)過(guò)程、函數(shù)等等),例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp logfile=scott_expdp_20190101.log schemas=scott content=metadata_only ##導(dǎo)出用戶存儲(chǔ)過(guò)程,例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp logfile=scott_expdp_20190101.log schemas=scott include=procedure ##導(dǎo)出用戶函數(shù)和視圖,例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp logfile=scott_expdp_20190101.log schemas=scott include=\(function,view\) ##導(dǎo)出一個(gè)用戶,但不包括索引,例: expdp system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp logfile=scott_expdp_20190101.log schemas=scott exclude=index |
4.2 impdp導(dǎo)入
##導(dǎo)入dmp文件中的所有數(shù)據(jù),例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log full=y ##導(dǎo)入一張表,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log tables=scott.emp ##導(dǎo)入多張表,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log tables=\(scott.emp,scott.dept\) ##導(dǎo)入一個(gè)用戶,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log schemas=scott ##導(dǎo)入多個(gè)用戶,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log schemas=\(scott,hr\) ##并行導(dǎo)入,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101_%U.dmp logfile=full_impdp_20190101.log parallel=5 ##導(dǎo)入元數(shù)據(jù)(包含表定義、存儲(chǔ)過(guò)程、函數(shù)等等),例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log content=metadata_only ##導(dǎo)入存儲(chǔ)過(guò)程,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log include=procedure ##導(dǎo)入函數(shù)和視圖,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log include=\(function,view\) ##導(dǎo)入數(shù)據(jù),但不包括索引,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log exclude=index ##重命名表名導(dǎo)入,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log remap_table=scott.emp:emp1 ##重命名schema名導(dǎo)入,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log remap_schema=scott:tim ##重命名表空間名導(dǎo)入,例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log remap_tablespace=users:pams ##將dmp文件的ddl語(yǔ)句導(dǎo)入到一個(gè)文件,不導(dǎo)入數(shù)據(jù)庫(kù),例: impdp system/dbmanager directory=dump_dir dumpfile=full_20190101.dmp logfile=full_impdp_20190101.log sqlfile=import.sql |
5.常用參數(shù)
5.1 expdp參數(shù)說(shuō)明
attach=[schema_name.]job_name 說(shuō)明:nodefault。連接到作業(yè),進(jìn)入交互模式。 ##導(dǎo)出模式,以下五個(gè)參數(shù)互斥: full=[ Y | N] 說(shuō)明:導(dǎo)出所有數(shù)據(jù)和元數(shù)據(jù)。要執(zhí)行完全導(dǎo)出,需要具有datapump_exp_full_database角色。 schemas=schema_name[,...] 說(shuō)明:導(dǎo)出用戶。 tables=[schema_name.]table_name[:partition_name][,...] 說(shuō)明:導(dǎo)出表。 tablespaces=tablespace_name[,...] 說(shuō)明:導(dǎo)出表空間。 transport_tablespaces=tablespace_name[,...] 說(shuō)明:導(dǎo)出可移動(dòng)表空間。 ##過(guò)濾條件,以下三個(gè)參數(shù)互斥: query=[schema.][table_name:] query_clause 說(shuō)明:按查詢條件導(dǎo)出。 exclude=object_type[:name_clause][,...] 說(shuō)明:排除特定的對(duì)象類(lèi)型。 include=object_type[:name_clause][,...] 說(shuō)明:包括特定的對(duì)象類(lèi)型。 ##其他參數(shù): directory=directory_object 說(shuō)明:導(dǎo)出路徑。 dumpfile=file_name[,...] 說(shuō)明:導(dǎo)出的文件名。 logfile=file_name 說(shuō)明:導(dǎo)出的日志文件名。 content=[ all| data_only | metadata_only] 說(shuō)明:指定要導(dǎo)出的數(shù)據(jù)。 parallel=integer 說(shuō)明:并行度,該值應(yīng)小于等于dmp文件數(shù)量,或可以為'dumpfile='使用替換變量'%U'。RAC環(huán)境中,并行度大于1時(shí),注意目錄應(yīng)該為共享目錄。 compression=[ all | data_only | metadata_only| none ] 說(shuō)明:壓縮。 parfile=[directory_path]file_name 說(shuō)明:指定導(dǎo)出參數(shù)文件名稱(chēng)。 filesize=integer[b|kb|mb|gb|tb] 說(shuō)明:指定每個(gè)dmp文件的最大大小。如果此參數(shù)小于將要導(dǎo)出的數(shù)據(jù)大小,將報(bào)錯(cuò)ORA-39095。 |
5.2 impdp參數(shù)說(shuō)明
attach=job_name 說(shuō)明:連接到作業(yè),進(jìn)入交互模式。 導(dǎo)入模式,以下五個(gè)參數(shù)互斥。 full=[ Y| N ] 說(shuō)明:導(dǎo)入dmp文件的所有數(shù)據(jù)和元數(shù)據(jù)。 schemas=schema_name[,...] 說(shuō)明:導(dǎo)入用戶。 tables=[schema_name.]table_name[:partition_name][,...] 說(shuō)明:導(dǎo)入表。 tablespaces=tablespace_name[,...] 說(shuō)明:導(dǎo)入表空間。 transport_tablespaces=tablespace_name[,...] 說(shuō)明:導(dǎo)入可移動(dòng)表空間。 過(guò)濾條件,以下三個(gè)參數(shù)互斥: query=[schema.][table_name:] query_clause 說(shuō)明:按查詢條件導(dǎo)入。 exclude=object_type[:name_clause][,...] 說(shuō)明:排除特定的對(duì)象類(lèi)型。 include=object_type[:name_clause][,...] 說(shuō)明:包括特定的對(duì)象類(lèi)型。 其他參數(shù): directory=directory_object 說(shuō)明:導(dǎo)入路徑。 dumpfile=file_name[,...] 說(shuō)明:導(dǎo)入的文件名。 logfile=file_name 說(shuō)明:導(dǎo)入的日志文件名。 content=[ all| data_only | metadata_only ] 說(shuō)明:指定要導(dǎo)入的數(shù)據(jù)。 parallel=integer 說(shuō)明:并行度,該值應(yīng)小于等于dmp文件數(shù)量,或可以為'dumpfile='使用替換變量'%U'。 parfile=[directory_path]file_name 說(shuō)明:指定導(dǎo)入?yún)?shù)文件名稱(chēng)。 REMAP_TABLE=[schema.]old_tablename[.partition]:new_tablename 說(shuō)明:允許導(dǎo)入期間重命名表名。 REMAP_SCHEMA=source_schema:target_schema 說(shuō)明:允許導(dǎo)入期間重命名schema名。 REMAP_TABLESPACE=source_tablespace:target_tablespace 說(shuō)明:允許導(dǎo)入期間重命名表空間名。 SQLFILE=[directory_object:]file_name 說(shuō)明:根據(jù)其他參數(shù),將所有的 SQL DDL 寫(xiě)入指定的文件。 TABLE_EXISTS_ACTION=[ SKIP| APPEND| TRUNCATE | REPLACE ] 說(shuō)明:default:skip(if content=data_onlyis specified,then the default is append) |
6.注意事項(xiàng)
6.1 directory相關(guān)SQL語(yǔ)句:
##查看目錄 select * from dba_directories; ##創(chuàng)建目錄 create directory dump_dir as '/home/oracle/tmp'; ##目錄授權(quán) grant read,write on directory my_dir to public; |
6.2 expdp導(dǎo)出
1、導(dǎo)數(shù)的數(shù)據(jù)庫(kù)用戶需要擁有對(duì)directory_object的讀寫(xiě)權(quán)限。 2、操作系統(tǒng)中需要已經(jīng)存在directory_object指定的路徑。 3、oracle用戶擁有對(duì)directory_object指定路徑的讀寫(xiě)權(quán)限。 4、system用戶導(dǎo)出用戶,會(huì)將創(chuàng)建用戶和授予系統(tǒng)權(quán)限的元數(shù)據(jù)也導(dǎo)出,普通用戶不能導(dǎo)出這些元數(shù)據(jù)。 |
6.3 impdp導(dǎo)入
1、expdp導(dǎo)出的文件不能使用imp導(dǎo)入,只能通過(guò)impdp導(dǎo)入數(shù)據(jù)庫(kù)。 2、導(dǎo)入時(shí)遇到已存在的對(duì)象,默認(rèn)會(huì)跳過(guò)這個(gè)對(duì)象,繼續(xù)導(dǎo)入其他對(duì)象。 3、導(dǎo)入時(shí)應(yīng)確認(rèn)dmp文件和目標(biāo)數(shù)據(jù)庫(kù)的tablespace、schema是否對(duì)應(yīng)。 4、導(dǎo)入dmp文件時(shí),應(yīng)確定dmp文件導(dǎo)出時(shí)的命令,以便順利導(dǎo)入數(shù)據(jù)。 |
6.4交互模式
進(jìn)入交互可以操作導(dǎo)入導(dǎo)出作業(yè)。 進(jìn)入交互模式的方法: 1、導(dǎo)入導(dǎo)出命令行執(zhí)行期間按Ctrl + c 2、expdp attach=jobname或impdp attach=jobnam 查看導(dǎo)入導(dǎo)出日志可以看到j(luò)obname,也可以通過(guò)查詢dba_datapump_jobs找到j(luò)obname。 |
6.5常見(jiàn)報(bào)錯(cuò)
系統(tǒng)目錄未建立,報(bào)錯(cuò): ORA-39002: invalid operation ORA-39070: Unable to open the log file. ORA-29283: invalid file operation ORA-06512: at "SYS.UTL_FILE", line 536 ORA-29283: invalid file operation impdp導(dǎo)入exp導(dǎo)出的dmp文件,報(bào)錯(cuò): ORA-39000: bad dump file specification ORA-39143: dump file "/orabak/pams_20190101.dmp" may be an original export dump file 如果導(dǎo)出的數(shù)據(jù)庫(kù)版本比導(dǎo)入的數(shù)據(jù)版本高,需要在導(dǎo)出時(shí)加上參數(shù)version=要導(dǎo)入的數(shù)據(jù)庫(kù)版本。否則報(bào)錯(cuò): ORA-39001: invalid argument value ORA-39000: bad dump file specification ORA-31640: unable to open dump file "/orabak/pams_20190101.dmp" for read ORA-27037: unable to obtain file status |
到此,關(guān)于“Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!