使用impdp复制oracle的schema数据迁移


  测试环境:
    源: windows 2003, oracle 10202
    目标:windows 2000, oracle 10203

    注:本文中所说的 schema 和 user 是一个意思。

    impdp 的数据源既可以是expdp 导出来的DMP文件,也可以是一数据库,通过network_link 参数来指定数据源,schemas 参数说明要复制的用户,remap_schemas 参数说明源用户与目标用户的匹配关系,remap_tablepace 来调整原 schemas 使用的表空间与目标数据库用户要表空间的对应关系。这样,基本上可以把源schema的数据导入到目标数据库。格式如下:

    2、impdp user/password parfile=parfile.log

    **********parfile.log 的内容***************

    network_link=目标数据库上的数据库链。
    schema=源数据库上导出数据的用户。
    remap_schema=源用户:目标用户。
    remap_tablespace=源用户使用的表空间:目标用户将使用的表空间(包括临时表空间)。

    **********parfile.log 的内容***************

    过程举例:

    1、在目标数据库上创建数据库链,指向源数据库,数据库链中连接的用户必须具备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的创建时间可以知道,该用户是刚创建的。
    注:
    1,从上面两例子看出,不论是在两数据库间,哈市是在同一数据库里复制SCHEMAS,都必须
    使用network_link,才能说明是在复制数据。
    2,"remap_schema=源用户:目标用户" 中的目标用户可以事先创建

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3