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

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

創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網(wǎng)站設計、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的烏什網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

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

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

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

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

exp/imp不能導出空表,而且由于從10g開始停止更新,后面版本引入的新對象都不支持導出,如自定義對象。功能更強

1.1.與exp/imp的主要區(qū)別

?  exp/imp是客戶端工具,可以在客戶端使用;數(shù)據(jù)泵是服務端工具,只能在服務端使用。

?  exp/imp不能導出空表;數(shù)據(jù)泵可以。

?  exp/imp跟數(shù)據(jù)泵導出的文件不能通用。

2.基本概念

數(shù)據(jù)泵的命令行命令是expdp/impdp,是一種數(shù)據(jù)庫之間移動數(shù)據(jù)的工具。

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

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

3.基本步驟

3.1創(chuàng)建目錄

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

dump_dir 是目錄名稱;可以根據(jù)實際情況自己定義,不重復即可,如果系統(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í)行導入導出

$ 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 是導出命令所用的用戶;

dbmanager 是system用戶的密碼;

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

full=Y 表示全庫導出;

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

4.常用方式

4.1 expdp導出

##導出一張表,例:

expdp system/dbmanager   directory=dump_dir   dumpfile=emp_20190101.dmp   logfile=emp_expdp_20190101.log tables=scott.emp

##導出多張表,例:

expdp system/dbmanager   directory=dump_dir   dumpfile=empdept_20190101.dmp   logfile=empdept_expdp_20190101.log tables=\(scott.emp,scott.dept\)

##導出一個用戶(導出這個用戶的所有對象),例:

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

##導出多個用戶,例:

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

##導出整個數(shù)據(jù)庫(sys的用戶數(shù)據(jù)不會被導出),例:

expdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_expdp_20190101.log full=y

##并行導出,例:

expdp system/dbmanager   directory=dump_dir dumpfile=scott_20190101_%U.dmp logfile=scott_expdp_20190101.log schemas=scott   parallel=8

##導出用戶元數(shù)據(jù)(包含表定義、存儲過程、函數(shù)等等),例:

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

##導出用戶存儲過程,例:

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

##導出用戶函數(shù)和視圖,例:

expdp   system/dbmanager directory=dump_dir dumpfile=scott_20190101.dmp   logfile=scott_expdp_20190101.log   schemas=scott include=\(function,view\)

##導出一個用戶,但不包括索引,例:

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

4.2 impdp導入

##導入dmp文件中的所有數(shù)據(jù),例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log full=y

##導入一張表,例:

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

##導入多張表,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log tables=\(scott.emp,scott.dept\)

##導入一個用戶,例:

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

##導入多個用戶,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log schemas=\(scott,hr\)

##并行導入,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101_%U.dmp   logfile=full_impdp_20190101.log   parallel=5

##導入元數(shù)據(jù)(包含表定義、存儲過程、函數(shù)等等),例:

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

##導入存儲過程,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log include=procedure

##導入函數(shù)和視圖,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log include=\(function,view\)

##導入數(shù)據(jù),但不包括索引,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log exclude=index

##重命名表名導入,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log   remap_table=scott.emp:emp1

##重命名schema名導入,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log remap_schema=scott:tim

##重命名表空間名導入,例:

impdp system/dbmanager   directory=dump_dir dumpfile=full_20190101.dmp   logfile=full_impdp_20190101.log remap_tablespace=users:pams

##將dmp文件的ddl語句導入到一個文件,不導入數(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è),進入交互模式。

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

full=[ Y | N]

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

schemas=schema_name[,...]

說明:導出用戶。

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

說明:導出表。

tablespaces=tablespace_name[,...]

說明:導出表空間。

transport_tablespaces=tablespace_name[,...]

說明:導出可移動表空間。

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

query=[schema.][table_name:]   query_clause

說明:按查詢條件導出。

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

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

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

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

##其他參數(shù):

directory=directory_object

說明:導出路徑。

dumpfile=file_name[,...]

說明:導出的文件名。

logfile=file_name

說明:導出的日志文件名。

content=[ all|   data_only | metadata_only]

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

parallel=integer

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

compression=[ all | data_only   | metadata_only| none ]

說明:壓縮。

parfile=[directory_path]file_name

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

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

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

5.2 impdp參數(shù)說明

attach=job_name

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

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

full=[ Y| N ]

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

schemas=schema_name[,...]

說明:導入用戶。

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

說明:導入表。

tablespaces=tablespace_name[,...]

說明:導入表空間。

transport_tablespaces=tablespace_name[,...]

說明:導入可移動表空間。

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

query=[schema.][table_name:]   query_clause

說明:按查詢條件導入。

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

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

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

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

其他參數(shù):

directory=directory_object

說明:導入路徑。

dumpfile=file_name[,...]

說明:導入的文件名。

logfile=file_name

說明:導入的日志文件名。

content=[ all| data_only | metadata_only ]

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

parallel=integer

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

parfile=[directory_path]file_name

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

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

說明:允許導入期間重命名表名。

REMAP_SCHEMA=source_schema:target_schema

說明:允許導入期間重命名schema名。

REMAP_TABLESPACE=source_tablespace:target_tablespace

說明:允許導入期間重命名表空間名。

SQLFILE=[directory_object:]file_name

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

TABLE_EXISTS_ACTION=[   SKIP| APPEND| TRUNCATE | REPLACE ]

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

6.注意事項

6.1 directory相關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導出

1、導數(shù)的數(shù)據(jù)庫用戶需要擁有對directory_object的讀寫權(quán)限。

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

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

4、system用戶導出用戶,會將創(chuàng)建用戶和授予系統(tǒng)權(quán)限的元數(shù)據(jù)也導出,普通用戶不能導出這些元數(shù)據(jù)。

6.3 impdp導入

1、expdp導出的文件不能使用imp導入,只能通過impdp導入數(shù)據(jù)庫。

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

3、導入時應確認dmp文件和目標數(shù)據(jù)庫的tablespace、schema是否對應。

4、導入dmp文件時,應確定dmp文件導出時的命令,以便順利導入數(shù)據(jù)。

6.4交互模式

進入交互可以操作導入導出作業(yè)。

進入交互模式的方法:

1、導入導出命令行執(zhí)行期間按Ctrl + c

2、expdp attach=jobname或impdp   attach=jobnam

查看導入導出日志可以看到jobname,也可以通過查詢dba_datapump_jobs找到jobname。

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導入exp導出的dmp文件,報錯:

ORA-39000: bad dump   file specification

ORA-39143: dump file   "/orabak/pams_20190101.dmp" may be an original export dump file

如果導出的數(shù)據(jù)庫版本比導入的數(shù)據(jù)版本高,需要在導出時加上參數(shù)version=要導入的數(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

到此,關于“Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

網(wǎng)頁名稱:Oracle數(shù)據(jù)泵技術(shù)常用操作有哪些
文章源于:http://bm7419.com/article22/gipcjc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信小程序、用戶體驗、企業(yè)網(wǎng)站制作、Google、網(wǎng)站策劃、營銷型網(wǎng)站建設

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化