|
【赛迪网-it技术报道】使用impdp复制oracle的schema数据迁移
style="text-indent:2em">测试环境如下:
源: windows 2003, oracle 10202
目标:windows 2000,oracle 10203
注:文中的schema和user是一个概念。
impdp 的数据源既可以是expdp 导出来的dmp文件,也可以是一数据库,通过network_link 参数来指定数据源,schemas 参数说明要复制的用户,remap_schemas 参数说明源用户与目标用户的匹配关系,remap_tablepace 来调整原 schemas 使用的表空间与目标数据库用户要表空间的对应关系。这样,基本上可以把源schema的数据导入到目标数据库。格式如下:
impdp user/password parfile=parfile.log
**********parfile.log 的内容***************
network_link=目标数据库上的数据库链。
schema=源数据库上导出数据的用户。
remap_schema=源用户:目标用户。
remap_tablespace=源用户使用的表空间:目标用户将使用的表空间(包括临时表空间)。
**********parfile.log 的内容***************
过程举例:
在目标数据库上创建数据库链,指向源数据库,数据库链中连接的用户必须具备exp_full_database角色的权限。 例:
a、新建数据库链里的用户,授予create session 和使用users 空间的权限,
sql> create user link identified by "1";
用户已创建。
sql> grant create session to link;
授权成功。
sql> alter user link quota unlimited on users;
用户已更改。
b、为该用户创建一表,用于测试复制用户过程。
sql> create table link.doc_type as select * from info.doc_type;
表已创建。
sql> select table_name from dba_tables where owner='link';
table_name
------------------------------
doc_type
c、使用该用户来创建数据库链。
sql> create public database link tolink connect to link identified by "1" using '37zhs';
数据库链接已创建。
d、使用该链来复制link用户,报 ora-39149: cannot link privileged user to non-privileged user
错误。
d:\oracle\product\10.2.0\db_1\bin>impdp network_link=tolink schemas=link remap_schema=link:link2
import: release 10.2.0.2.0 - production on wednesday, 07 march, 2007 16:51:37
copyright (c) 2003, 2005, oracle. all rights reserved.
username: / as sysdba
connected to: oracle database 10g enterprise edition release 10.2.0.2.0 - production
with the partitioning, olap and data mining options
ora-31631: privileges are required
ora-39149: cannot link privileged user to non-privileged user
f、授予 exp_ful_database 权限后,复制成功。
sql> grant exp_full_database to link;
授权成功。
d:\oracle\product\10.2.0\db_1\bin>impdp network_link=tolink schemas=link remap_schema=link:link2
import: release 10.2.0.2.0 - production on wednesday, 07 march, 2007 16:54:30
copyright (c) 2003, 2005, oracle. all rights reserved.
username: / as sysdba
connected to: oracle database 10g enterprise edition release 10.2.0.2.0 - production
with the partitioning, olap and data mining options
flashback automatically enabled to preserve database integrity.
starting "sys"."sys_import_schema_01": /******** as sysdba network_link=tolink schemas=link remap
_schema=link:link2
estimate in progress using blocks method...
processing object type schema_export/table/table_data
total estimation using blocks method: 64 kb
processing object type schema_export/user
processing object type schema_export/system_grant
processing object type schema_export/role_grant
processing object type schema_export/default_role
processing object type schema_export/tablespace_quota
processing object type schema_export/pre_schema/procact_schema
processing object type schema_export/table/table
. . imported "link2"."doc_type" 8 rows
job "sys"."sys_import_schema_01" successfully completed at 16:54:52
又如,在两数据库间复制用户:
a、源数据库是上面例子中的link,
b、目标数据库是10203版本,要将源中的link复制到目标中的link2中。
sys@btb>create public database link tolink connect to link identified by "1" using '37zhs';
数据库链接已创建。
sys@btb>select * from tab@tolink;
tname tabtype clusterid
------------------------------ ------- ----------
doc_type table
f:\oracle\product\10.2.0\db_1\bin>impdp network_link=tolink schemas=link remap_schema=link:link2
import: release 10.2.0.3.0 - production on 星期三, 07 3月, 2007 17:36:32
copyright (c) 2003, 2005, oracle. all rights reserved.
用户名: / as sysdba
连接到: oracle database 10g enterprise edition release 10.2.0.3.0 - production
with the partitioning, olap and data mining options
自动启用 flashback 以保持数据库完整性。
启动 "sys"."sys_import_schema_03": /******** as sysdba network_link=tolink schemas=link remap_sch
ema=link:link2
正在使用 blocks 方法进行估计...
处理对象类型 schema_export/table/table_data
使用 blocks 方法的总估计: 64 kb
处理对象类型 schema_export/user
处理对象类型 schema_export/system_grant
处理对象类型 schema_export/role_grant
处理对象类型 schema_export/default_role
处理对象类型 schema_export/tablespace_quota
处理对象类型 schema_export/pre_schema/procact_schema
处理对象类型 schema_export/table/table
. . 导入了 "link2"."doc_type" 8 行
作业 "sys"."sys_import_schema_03" 已于 17:40:14 成功完成
f:\oracle\product\10.2.0\db_1\bin>
sys@btb>select * from all_users order by 3;
username user_id created
------------------------------ ---------- -------------------
system 5 2006-11-19 10:27:12
sys 0 2006-11-19 10:27:12
outln 11 2006-11-19 10:27:18
dip 19 2006-11-19 10:34:16
tsmsys 21 2006-11-19 10:44:48
dbsnmp 24 2006-11-19 10:48:58
wmsys 25 2006-11-19 10:51:52
mgmt_view 53 2006-11-19 11:41:09
scott 54 2006-11-19 11:43:42
scott2 62 2007-03-01 14:50:06
link2 63 2007-03-07 17:39:34
从link2的创建时间可以知道,该用户是刚创建的。
从以上两个例子中大家可以看出,不论是在两数据库间,还是在同一数据库里复制schemas,都必须
使用network_link,才能说明是在复制数据。
2."remap_schema=源用户:目标用户" 中的目标用户可以事先创建。
|