Chinaunix首页 | 论坛 | 博客
  • 博客访问: 428846
  • 博文数量: 55
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1584
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-04 15:15
个人简介

热衷技术,热爱交流

文章分类

全部博文(55)

文章存档

2014年(7)

2013年(48)

分类: Oracle

2013-08-26 18:05:22

全库迁移、分区迁移、network_link迁移

一、全库迁移:

数据库全库迁移与imp/exp差不多,支持跨版本迁移,但是不支持windows与linux/unix跨平台迁移,因为两者路径书写方式不一致。全库迁移必须要保证源和目的数据库相关结构一致(主要是数据文件的目录)

1.首先在源库导出数据:

SQL> create directory expdir as 'd:\';

expdp '/ as sysdba'   directory=expdir logfile=full.log  full=y dumpfile=full_%U.dmp  filesize=1024M job_name=hr exclude=schema:"in('scott')" parallel=2    --过滤掉scott用户的数据

2.目的库上导入数据:

(1)建立与源库相同的数据文件目录

(2)使用dbca或者手动建立新库:

(3)建立directory:

SQL> create directory expdir as 'd:\';

(4)把dmp文件拷贝到新库上的directory目录

(5)导入数据:

impdp '/ as sysdba'   directory=expdir logfile=full.log  full=y dumpfile=full_%U.dmp  job_name=hr  parallel=2

(6)编译无效对象

以dba角色登录,执行下列脚本:

SQL> @?\RDBMS\ADMIN\utlrp.sql

二、分区迁移:

数据泵分区迁移方法基本和传统工具一致,都需要目的数据库已经建立了相应的表空间,否则迁移失败。和之前exp/imp讨论的一样:分区表hr_event以end_time字段为分区键,每天的记录作为一个分区,每个分区对应一个表空间,对应一个数据文件。现在要导出2013年8月10日到8月26日的分区数据,如果把分区名写在tables参数里,由于分区较多,将会很麻烦,可以给query参数赋值,实现导出指定分区数据。

1.分区导出:

expdp  hr/hr tables=hr_event  directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

2.分区导入:

impdp  hr/hr tables=hr_event  directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" table_exists_action=append job_name=hr

三、network_link实现网络导入导出

1.建立dblink:

C:\Users\Administrator>sqlplus / as sysdba

SQL> create database link orcljjyf2 connect to hr identified by hr using '192.168.73.208/orcljjyf2';

SQL> select sysdate from dual@orcljjyf2;

SYSDATE

--------------

26-8月 -13

2.执行导出:

在执行导出时,如果在本地数据库使用dba角色用户导出,那么dblink指向的用户在服务器端必须具备exp_full_database权限,否则会报错,例如:

C:\Users\Administrator>sqlplus / as sysdba

SQL> create user test identified by test default tablespace users quota unlimited on users temporary tablespace temp;

SQL> grant connect,resource,dba to test

SQL> grant create table,create database link to test;

SQL> grant read,write on directory  expdir to test;

C:\Users\Administrator>sqlplus TEST/test

SQL> create database link hr_208 connect to hr identified by hr using '192.168.73.208/orcljjyf2';

expdp  'test/test' tables=hr_event  network_link=hr_208 directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 query=hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

Export: Release 10.2.0.5.0 - 64bit Production on 星期一, 26 8月, 2013 12:36:30


Copyright (c) 2003, 2007, Oracle.  All rights reserved.


连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

ORA-31631: 需要权限

ORA-39149: 无法将授权用户链接到非授权用户

解决办法:可以直接登录到dblink指向的远程服务器,给hr用户授exp_full_database权限:

C:\Users\Administrator>sqlplus sys/talent@192.168.73.208/orcljjyf2 as sysdba

SQL> grant exp_full_database to hr;

接下来执行导入操作就会成功了。

expdp  'test/test'  network_link=hr_208 directory=expdir dumpfile=hr_event.dmp logfile=hr.log parallel=2 tables=hr.hr_event query=hr.hr_event:\"where end_time>=to_timestamp('2013-08-10 00:00:00','YYYY-MM-DD HH24:MI:SS') AND end_time<=to_timestamp('2013-08-27 00:00:00','YYYY-MM-DD HH24:MI:SS')\" job_name=hr

网络状况良好时,为了避免繁琐的数据复制工作,使用network_link选项是一个很不错的选择。因为 它克服了不能通过网络导出导入的缺点,而且同样支持交互操作。数据泵也可以进行表空间的导入导出操作,方法和exp/imp基本一致,本文不再讨论了。

阅读(3443) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~