溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些

發(fā)布時間:2021-11-05 11:22:24 來源:億速云 閱讀:255 作者:iii 欄目:關(guān)系型數(shù)據(jù)庫

這篇文章主要介紹“Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些”,在日常操作中,相信很多人在Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”O(jiān)racle數(shù)據(jù)泵技術(shù)常用操作有哪些”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

1. 為什么選擇數(shù)據(jù)泵

數(shù)據(jù)泵是Oracle 10g開始引入的新技術(shù),對現(xiàn)在來說已經(jīng)不是新技術(shù)了,11g都已經(jīng)結(jié)束標(biāo)準(zhǔn)支持期了。技術(shù)更新

從10g版本開始,數(shù)據(jù)泵技術(shù)跟隨新版本進(jìn)行不斷的完善,對新版本的Oracle數(shù)據(jù)庫具有更強(qiáng)的適應(yīng)性。BUG更少

數(shù)據(jù)泵可以使用直接路徑、并行等特性,對大數(shù)據(jù)量的遷移來說,具有更好的性能,可以減少大量導(dǎo)入導(dǎo)出時間。性能更好

exp/imp不能導(dǎo)出空表,而且由于從10g開始停止更新,后面版本引入的新對象都不支持導(dǎo)出,如自定義對象。功能更強(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ù)庫之間移動數(shù)據(jù)的工具。

目錄(directory)是Oracle的一種對象類型,可以認(rèn)為是一個指向物理存儲路徑的指針,用來指定數(shù)據(jù)泵導(dǎo)出導(dǎo)入文件使用的路徑。

模式(schema)是一組數(shù)據(jù)庫對象的集合,一般一個用戶對應(yīng)一個schema。

3. 基本步驟

3.1 創(chuàng)建目錄

SQL> create directory dump_dir   as '/home/oracle/dump';

dump_dir 是目錄名稱;可以根據(jù)實際情況自己定義,不重復(fù)即可,如果系統(tǒng)中已經(jīng)存在,可以直接使用;

/home/oracle/dump 是操作系統(tǒng)物理路徑;必須保證該路徑真實存在,并具有足夠空間存放備份文件;

3.2 授權(quán)

SQL> grant read,write on   directory dump_dir to public;

dump_dir 是上面創(chuàng)建得目錄名稱;

public 表示這個目錄是公開的;也可以針對某個用戶授權(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)建得目錄名稱;

full=Y 表示全庫導(dǎo)出;

dumpfile/logfile 根據(jù)實際情況命名即可;該命名需要能夠描述備份的內(nèi)容及時間等基本信息;該命名重復(fù)的話會覆蓋

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)出一個用戶(導(dǎo)出這個用戶的所有對象),例:

expdp system/dbmanager   directory=dump_dir dumpfile=scott_20190101.dmp   logfile=scott_expdp_20190101.log   schemas=scott

##導(dǎo)出多個用戶,例:

expdp system/dbmanager   directory=dump_dir dumpfile=scotthr_20190101.dmp   logfile=scotthr_expdp_20190101.log schemas=\(scott,hr\)

##導(dǎo)出整個數(shù)據(jù)庫(sys的用戶數(shù)據(jù)不會被導(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ù)(包含表定義、存儲過程、函數(shù)等等),例:

expdp system/dbmanager   directory=dump_dir dumpfile=scott_20190101.dmp   logfile=scott_expdp_20190101.log   schemas=scott content=metadata_only

##導(dǎo)出用戶存儲過程,例:

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)出一個用戶,但不包括索引,例:

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)入一個用戶,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log schemas=scott

##導(dǎo)入多個用戶,例:

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ù)(包含表定義、存儲過程、函數(shù)等等),例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log content=metadata_only

##導(dǎo)入存儲過程,例:

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語句導(dǎo)入到一個文件,不導(dǎo)入數(shù)據(jù)庫,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log sqlfile=import.sql

5. 常用參數(shù)

5.1 expdp參數(shù)說明

attach=[schema_name.]job_name

說明:nodefault。連接到作業(yè),進(jìn)入交互模式。

##導(dǎo)出模式,以下五個參數(shù)互斥:

full=[ Y | N ]

說明:導(dǎo)出所有數(shù)據(jù)和元數(shù)據(jù)。要執(zhí)行完全導(dǎo)出,需要具有datapump_exp_full_database角色。

schemas=schema_name[,...]

說明:導(dǎo)出用戶。

tables=[schema_name.]table_name[:partition_name][,...]

說明:導(dǎo)出表。

tablespaces=tablespace_name[,...]

說明:導(dǎo)出表空間。

transport_tablespaces=tablespace_name[,...]

說明:導(dǎo)出可移動表空間。

##過濾條件,以下三個參數(shù)互斥:

query=[schema.][table_name:]   query_clause

說明:按查詢條件導(dǎo)出。

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

說明:排除特定的對象類型。

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

說明:包括特定的對象類型。

##其他參數(shù):

directory=directory_object

說明:導(dǎo)出路徑。

dumpfile=file_name[,...]

說明:導(dǎo)出的文件名。

logfile=file_name

說明:導(dǎo)出的日志文件名。

content=[ all |   data_only | metadata_only]

說明:指定要導(dǎo)出的數(shù)據(jù)。

parallel=integer

說明:并行度,該值應(yīng)小于等于dmp文件數(shù)量,或可以為'dumpfile='使用替換變量'%U'。RAC環(huán)境中,并行度大于1時,注意目錄應(yīng)該為共享目錄。

compression=[ all | data_only   | metadata_only | none ]

說明:壓縮。

parfile=[directory_path]file_name

說明:指定導(dǎo)出參數(shù)文件名稱。

filesize=integer[b|kb|mb|gb|tb]

說明:指定每個dmp文件的最大大小。如果此參數(shù)小于將要導(dǎo)出的數(shù)據(jù)大小,將報錯ORA-39095。

5.2 impdp參數(shù)說明

attach=job_name

說明:連接到作業(yè),進(jìn)入交互模式。

導(dǎo)入模式,以下五個參數(shù)互斥。

full=[ Y | N ]

說明:導(dǎo)入dmp文件的所有數(shù)據(jù)和元數(shù)據(jù)。

schemas=schema_name[,...]

說明:導(dǎo)入用戶。

tables=[schema_name.]table_name[:partition_name][,...]

說明:導(dǎo)入表。

tablespaces=tablespace_name[,...]

說明:導(dǎo)入表空間。

transport_tablespaces=tablespace_name[,...]

說明:導(dǎo)入可移動表空間。

過濾條件,以下三個參數(shù)互斥:

query=[schema.][table_name:]   query_clause

說明:按查詢條件導(dǎo)入。

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

說明:排除特定的對象類型。

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

說明:包括特定的對象類型。

其他參數(shù):

directory=directory_object

說明:導(dǎo)入路徑。

dumpfile=file_name[,...]

說明:導(dǎo)入的文件名。

logfile=file_name

說明:導(dǎo)入的日志文件名。

content=[ all | data_only | metadata_only ]

說明:指定要導(dǎo)入的數(shù)據(jù)。

parallel=integer

說明:并行度,該值應(yīng)小于等于dmp文件數(shù)量,或可以為'dumpfile='使用替換變量'%U'。

parfile=[directory_path]file_name

說明:指定導(dǎo)入?yún)?shù)文件名稱。

REMAP_TABLE=[schema.]old_tablename[.partition]:new_tablename

說明:允許導(dǎo)入期間重命名表名。

REMAP_SCHEMA=source_schema:target_schema

說明:允許導(dǎo)入期間重命名schema名。

REMAP_TABLESPACE=source_tablespace:target_tablespace

說明:允許導(dǎo)入期間重命名表空間名。

SQLFILE=[directory_object:]file_name

說明:根據(jù)其他參數(shù),將所有的 SQL DDL   寫入指定的文件。

TABLE_EXISTS_ACTION=[   SKIP | APPEND | TRUNCATE | REPLACE ]

說明:default:skip(if   content=data_only is specified,then the default is append)

6. 注意事項

6.1 directory相關(guān)SQL語句:

##查看目錄

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ù)庫用戶需要擁有對directory_object的讀寫權(quán)限。

2、操作系統(tǒng)中需要已經(jīng)存在directory_object指定的路徑。

3、oracle用戶擁有對directory_object指定路徑的讀寫權(quán)限。

4、system用戶導(dǎo)出用戶,會將創(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)入,只能通過impdp導(dǎo)入數(shù)據(jù)庫。

2、導(dǎo)入時遇到已存在的對象,默認(rèn)會跳過這個對象,繼續(xù)導(dǎo)入其他對象。

3、導(dǎo)入時應(yīng)確認(rèn)dmp文件和目標(biāo)數(shù)據(jù)庫的tablespace、schema是否對應(yīng)。

4、導(dǎo)入dmp文件時,應(yīng)確定dmp文件導(dǎo)出時的命令,以便順利導(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,也可以通過查詢dba_datapump_jobs找到j(luò)obname。

6.5 常見報錯

系統(tǒng)目錄未建立,報錯:

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文件,報錯:

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ù)庫版本比導(dǎo)入的數(shù)據(jù)版本高,需要在導(dǎo)出時加上參數(shù)version=要導(dǎo)入的數(shù)據(jù)庫版本。否則報錯:

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é)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI