Home >Database >Mysql Tutorial >Oracle教程:使用expdp、impdp迁移数据库

Oracle教程:使用expdp、impdp迁移数据库

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:03:46920browse

expdp、impdp在Oracle10g中才开始使用,下面的源数据库为Oracle10.2,目标数据库为Oracle11.21、在源数据库服务器A上创建expdp的

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

下面这些表很大可以不导出来:
'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.

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn