使用imp匯入表和索引至不同表空間方法

2021-10-03 08:25:43 字數 2717 閱讀 1380

在以前我的blog中,曾經記錄過使用expdp/impdp方式將表和索引匯入至不同表空間的方法,這裡再提一下:

匯出:expdp test/test directory=dump_dir dumpfile=test.dmp logfile=test_expdp.log tables=t

匯入表資料:

impdp test/test directory=dump_dir dumpfile=test.dmp logfile=impdp_data.log remap_tablespace=system:datatb exclude=index

匯入索引資料:

impdp test/test directory=dump_dir dumpfile=test.dmp logfile=impdp_index.log remap_tablespace=system:idxtb include=index

查詢語句:

select segment_name,tablespace_name from dba_segments where owner=『test』;

由於應用資料需要遷移,要將原來資料庫中應用資料通過匯入匯出的方式,遷移至目標資料庫,同時由於新的規劃需求,需要將表中資料和索引存放的表空間區分,遷移前後資料庫版本均為oracle 10g。此操作本來是可以用上述expdp/impdp方式完成的,不過由於在源端資料庫沒有足夠空間存放匯出後的dmp檔案,所以需要使用其他方式完成資料遷移。

先給出一般的exp/imp遷移資料方法:

(為方便說明,以下示例是將a使用者下的資料匯入至b使用者,同時表中資料和索引表空間需遷移至不同表空間)

exp/imp方式將資料進行遷移時,如果想改變資料存放的表空間的話,需要注意2點:

(1) 匯入使用者無dba許可權

(2) 匯入使用者無unlimited tablespace許可權

這樣的話,匯入的資料會存放在其預設表空間下,具體說明可參考eygle大師的文章

不過這樣是無法將表中資料和索引匯入至不同表空間的,如果想將索引匯入至其他表空間,方法如下:

匯出a使用者下資料

exp a/a file=exp_test.dmp log=exp_test.log

首先不匯入索引,只匯入表資料部分:

imp b/b file=exp_test.dmp log=imp_test_data.log fromuser=a touser=b indexes=n

之後,通過indexfile引數,將建立索引的sql語句儲存至文字中:

imp b/b file=exp_test.dmp log=imp_test_index.log fromuser=a touser=b indexfile=index.sql

最後,通過修改並執行索引建立的sql語句index.sql,完成實際匯入需求。

以上方式可以完成需求,不過操作起來比較麻煩,尤其需要注意:

(1) 應用使用者匯入的預設表空間及該使用者相關許可權。

(2) 修改index.sql文字的方法頗顯麻煩。

以下給出我的oracle 10g下exp/imp遷移資料方法,也是本次資料遷移實際使用的方法:

首先使用expdp/impdp方法遷移元資料(metadata):
匯出:

expdp system/oracle directory=dump_dir dumpfile=expdp_test.dmp logfile=expdp_test.log content=metadata_only schemas=a

匯入元資料(metadata),指定不同表空間。
impdp system/oracle directory=dump_dir dumpfile=expdp_test.dmp logfile=impdp_test_data.log remap_schema=a:b remap_tablespace=splex:datatb exclude=index

impdp system/oracle directory=dump_dir dumpfile=expdp_test.dmp logfile=impdp_test_index.log remap_schema=a:b remap_tablespace=splex:proftb include=index

之後,通過exp/imp方式遷移應用資料,注意源資料庫字符集、目標端資料庫字符集、客戶端字符集設定應當一致,避免字元轉換:
exp a/a file=exp_test.dmp log=exp_test.log statistics=none buffer=52428800

imp b/b file=exp_test.dmp log=imp_test.log fromuser=a touser=b ignore=y commit=y buffer=52428800 indexes=n grants=n constraints=n

通過上述方式,可完成exp/imp遷移資料的方法。

資料幫浦的其他匯出方法:

雖然本次資料遷移未使用到,不過還是記錄一下。

其實資料幫浦是可以在客戶端匯出資料的,即指定network_link引數:

expdp system/password network_link=db_link_name directory=data_pump_dir dumpfile=server.dmp tables=employees

這種方式需要涉及到2個資料庫例項,相當於是客戶端的資料庫通過使用database link訪問了伺服器端的資料庫,並通過資料幫浦方式實現伺服器端資料的匯出。

ORACLE exp匯出和imp匯入使用者表

在另一篇部落格有說到利用exp和imp匯出和匯入乙個普通使用者 不包含分割槽表的使用者 那現在這篇就來說下匯出和匯入乙個使用者的某些表。1 oracle11g企業版 2 登入scott使用者 將scott使用者下的某個表匯出,然後匯入到hr使用者下 為了不影響scott自帶的表,我們使用以下語句建立...

imp匯入到指定表空間

sql create user myhuang identified by myhuang default tablespace myhuang 先建立乙個使用者 sql grant resource,connect to myhuang sql grant dba to myhuang 賦 dba...

oracle dmp中有分割槽表 imp匯入方法

imp 匯入 dmp的時候,如果dmp中有分割槽表,會報錯。則有以下2中發放解決 1 事先建立好分割槽表的表結構。2 就是根據匯入時候錯誤提示,建立表空間。然後再匯入。imp hzjj hzjj sbtb101 file f cbd work hz2004 20141028.dmp fromuser...