example:利用impdp通过dblink导入数据库

来源:互联网 发布:mac 火鹤色 编辑:程序博客网 时间:2024/06/05 00:18

说明

本地数据库需要10g 以上版本

本地数据库没有新建账户,直接导入到scott 用户;

 

impdp 特色

只需要一个dblink ,就能实现将数据库从一台机器导入到另外一台机器

 

以下是测试全过程, 每个小格子,代表了一次尝试

准备工作

在scott schemas 下创建到TESTDB 的DBlink

create database link TESTDB_aix

connect to TESTDB identified by "TESTDB123!" using 'aix_TESTDB_172';

 

测试DBlink

select * from dual@TESTDB_aix

 

 

C:/>impdp scott/scott schemas=TESTDB  NETWORK_LINK=TESTDB_aix EXCLUDE=CONSTRAINT logfile=d:/impdp.log

 

Import: Release 10.2.0.1.0 - Production on 星期二, 24 5 月, 2011 10:49:03

 

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

 

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORA-31631: 需要权限

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

Google 后,将scott 用户权限调整到TESTDB 一致

 

 

 

 

C:/>impdp scott/scott schemas=TESTDB  NETWORK_LINK=TESTDB_aix  EXCLUD

E=CONSTRAINT logfile=d:/impdp.log

 

Import: Release 10.2.0.1.0 - Production on 星期二, 24 5 月, 2011 10:49:23

 

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

 

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORA-31626: 作业不存在

ORA-31633: 无法创建主表 "SCOTT.SYS_IMPORT_SCHEMA_05"

ORA-06512: 在 "SYS.DBMS_SYS_ERROR", line 95

ORA-06512: 在 "SYS.KUPV$FT", line 863

ORA-01536: 超出表空间 'USERS' 的空间限额

 

增加TESTDB 表空间

alter tablespace users add datafile 'D:/ORACLEAPP/PRODUCT/10.2.0/ORADATA/SDHTEST/USERS02.DBF' size 8G;

 

alter tablespace users add datafile 'D:/ORACLEAPP/PRODUCT/10.2.0/ORADATA/SDHTEST/USERS03.DBF' size 8G;

 

alter tablespace users add datafile 'D:/ORACLEAPP/PRODUCT/10.2.0/ORADATA/SDHTEST/USERS04.DBF' size 4G;

 

grant unlimited tablespace to scott

 

 

C:/Users/Administrator>impdp scott/scott schemas=TESTDB NETWORK_LINK=TESTDB_aix  EXCLUDE=CONSTRAINT logfile=d:/impdp.log

 

Import: Release 10.2.0.1.0 - Production on 星期二, 24 5 月, 2011 11:10:42

 

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

 

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORA-39002: 操作无效

ORA-39070: 无法打开日志文件。

ORA-39088: 文件名不能包含路径说明

命令行中未指定directory,

新建 CREATE DIRECTORY dmpdir AS 'D:/OracleApp/product/10.2.0/datapump';

给scott 赋予在dmpdir 目录的读写权限GRANT read, write ON DIRECTORY dmpdir TO scott;

Ps: 也可以使用oracle 默认的dir DATA_PUMP_DIR:

SELECT * FROM dba_directories WHERE directory_name = 'DATA_PUMP_DIR'

 

 

C:/>impdp scott/scott schemas=TESTDB  NETWORK_LINK=TESTDB_aix  EXCLUD

E=CONSTRAINT logfile=impdp.log directory=dmpdir

 

Import: Release 10.2.0.1.0 - Production on 星期二, 24 5 月, 2011 11:19:18

 

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

 

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

ORA-31631: 需要权限

ORA-39109: 未授权用户不能对其他用户的方案进行操作

在导入语句中添加schema 的映射

impdp scott/scott remap_schema=TESTDB:scott   NETWORK_LINK=TESTDB_

aix  EXCLUDE=CONSTRAINT logfile=impdp.log directory=dmpdir

 

 

 

C:/>impdp scott/scott remap_schema=TESTDB:scott  NETWORK_LINK=TESTDB_

aix  EXCLUDE=CONSTRAINT logfile=impdp.log directory=dmpdir

 

 

失败的 sql 为:

CREATE TABLE "SCOTT"."NGN" ("NETLEVEL" VARCHAR2(255), "GWCATEGORY" VARCHAR2(255)

, "HARDWAREVERSION" VARCHAR2(255), "SOFEWAREVERSION" VARCHAR2(255), "TELENETIPAD

DR" VARCHAR2(255), "BEGINTIME" DATE, "ANALOGCAPACITY" NUMBER(10,0), "ANALOGACTUA

LCAPCITY" NUMBER(10,0), "PSTN2BDACTUALCAPACITY" NUMBER(10,0), "PSTN2BDCAPACITY"

NUMBER(10,0), "TOTALCAPACITY" NUMBER(10,0), "ACTUALTOTALCAPACITY" NUMBER(10,0),

"NUMOF2MSIGNA

ORA-39083: 对象类型 TABLE 创建失败, 出现错误:

ORA-00959: 表空间 'SDH_DATA' 不存在

 

添加从sdh_data 、sdh_index 到users 的映射

impdp scott/scott remap_schema=TESTDB:scott  NETWORK_LINK=TESTDB_

aix  EXCLUDE=CONSTRAINT logfile=impdp.log directory=dmpdirremap_tablespace=sdh_data:users,sdh_index:users

 


 

 

C:/>impdp scott/scott remap_schema=TESTDB:scott  NETWORK_LINK=TESTDB_

aix  EXCLUDE=CONSTRAINT logfile=impdp.log directory=dmpdirremap_tablespace=sdh_data:users,sdh_index:users

 

 

Import: Release 10.2.0.1.0 - Production on 星期二, 24 5 月, 2011 11:27:05

 

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

;;;

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

启动 "SCOTT"."SYS_IMPORT_SCHEMA_01":  scott/******** remap_schema=TESTDB:scott NETWORK_LINK=TESTDB_aix EXCLUDE=CONSTRAINT logfile=impdp.log directory=dmpdir remap_tablespace=sdh_data:users,sdh_index:users

正在使用 BLOCKS 方法进行估计...

处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA

使用 BLOCKS 方法的总估计: 21.57 GB

处理对象类型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA

处理对象类型 SCHEMA_EXPORT/DB_LINK

处理对象类型 SCHEMA_EXPORT/SEQUENCE/SEQUENCE

处理对象类型 SCHEMA_EXPORT/TABLE/TABLE

. . 导入了 "SCOTT"."CONNECTOR"                        31396764 行

. . 导入了 "SCOTT"."DNPORTAUDITS"                     12922037 行

. . 导入了 "SCOTT"."LOG_LIHQ"                         2142840 行

 

 

 

使用总结:

l  创建 dblink

l  复制源用户 ( 本例源用户为 TESTDB) 的权限,如果源用户和本地用户一直可以省略 schema 映射

l  扩展或者新建表空间,当然够大就不需要了,上面犯错是因为事先忘记查看两边数据库表空间大小

l  创建或者使用已用的 directory ,并给本地用户读写权限

原创粉丝点击