天天看點

使用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

繼續閱讀