使用expdp、impdp遷移數據庫

source:http://space.itpub.net/12778571/viewspace-662116

expdp、impdp在Oracle10g中才開始使用,
下面的源數據庫爲Oracle10.2,目標數據庫爲Oracle11.2
1、在源數據庫服務器A上創建expdp的導出目錄
$ pwd
/home/oraoms
$ mkdir exp_dir

SQL> create or replace directory exp_dir as '/home/oraoms/exp_dir';

Directory created.

2、在源數據庫A上查詢比較大的表,不影響系統運行的大表不導入到目標數據庫B中
select *
from (select table_name,
round((blocks * 8192 / 1024 / 1024 ), 2) "MB"
from user_tables
where blocks is not null
order by blocks desc)
where rownum < 21

下面這些表很大可以不導出來:
'MLOG_ENGI_GTB','MLOG_ENGI_MUDV','MLOG_ENGI_HYD'

3、在源數據庫A中導出
expdp A_user/A_user directory=exp_dir dumpfile=20100506.dump logfile=20100506.log schemas=A_user exclude=table:\"IN\(\'MLOG_ENGI_GTB\',\'MLOG_ENGI_MUDV\',\'MLOG_ENGI_HYD\'\)\"
在導出是想單引號,括號,需要“\”作爲轉化符。
導出的數據大概8GB多,共用了18分鐘左右。
4、在源數據庫A查看該用戶對象數量,用力驗證導入是否成功
select count(*) from user_objects

7532個對象

5、在源數據庫A中查看錶空間,在目標庫B中也建立相應的表空間
select tablespace_name, count(*)
from user_tables
group by tablespace_name
order by 2;

MLOG_NORM_SPACE


在目標數據庫B創建相關的表空間:
查看目標數據庫的數據文件位置
select name from v$datafile;
如:
create tablespace MLOG_NORM_SPACE
datafile '/oratest/app/oracle/oradata/orcl/MLOG_NORM_SPACE.dbf'
size 5M autoextend on

創建相應的用戶並授權
create user test
identified by test
default tablespace PUB_NORM_SPACE

grant dba to test;


6、在目標數據庫B建立導入目錄
>mkdir /oratest/imp_dir
把該目錄授權給oracle用戶
>chown -R oracle:dba /oratest/imp_dir

7、把導出的數據ftp到目標數據庫B中
ftp 目標數據庫ip
put 20100506.dump

8、在目標數據庫B創建導入目錄
SQL>create or replace directory imp_dir as '/oratest/imp_dir';

9、在目標數據庫B中導入數據
>su - oracle
impdp test/test DIRECTORY=imp_dir DUMPFILE=20100506.dump logfile=20100506imp.log REMAP_SCHEMA=A_user:test


10、在目標數據庫B中創建 沒有導出源數據庫A的大表的結構。
可以把表結構拷貝到目標數據庫B中。
或者在目標數據庫B中創建db_link,然後再創建相應的表結構


11、在目標數據庫B查看該用戶對象數量,用來驗證對象是否齊全
select count(*) from user_objects


注:
如果有些表中的字段用到了Oracle的關鍵字,需要用雙引號括起來。如time date,換成"time" date

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章