[Z] 【IMPDP】同一數據庫實例不同用戶間數據遷移復制——NETWORK_LINK參數

          @URL > http://space.itpub.net/519536/viewspace-631571

          如何快速的復制一個用戶的數據到另外一個用戶(這個用戶可能在不同的數據庫中)?

          一般答案:使用EXP(EXPDP)與IMP(IMPDP)相結合完成用戶數據的導入和導出

          高級方法:IMPDP工具提供的NETWORK_LINK參數可以一步到位的完成此項艱巨的任務。
          這種方法非常類似于使用CTAS方法在表復制中的應用,只不過這里我們實現的是用戶間的數據復制。

          使用這種方法的一般步驟如下:
          a.創建database link;
          b.使用IMPDP的network_link、schemas和remap_schema相結合完成用戶的數據的遷移

          真實的感受一下此項技術帶給我們的快樂。
          實現案例:同一個實例中不同用戶間的遷移復制。

          1.創建指向自身的DATABASE LINK
          1)確認tnsnames.ora文件中的連接串
          secooler@secDB /home/oracle$ cat $ORACLE_HOME/network/admin/tnsnames.ora
          # tnsnames.ora Network Configuration File: /oracle/ora11gR2/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
          # Generated by Oracle configuration tools.

          SECOOLER =
            (DESCRIPTION =
              (ADDRESS = (PROTOCOL = TCP)(HOST = secDB)(PORT = 1526))
              (CONNECT_DATA =
                (SERVER = DEDICATED)
                (SERVICE_NAME = secooler)
              )
            )

          2)在數據庫系統中創建一個指向自身的DATABASE LINK
          sys@secooler> create public database link dblink_to_myself connect to system identified by sys using 'SECOOLER';

          Database link created.

          2.復制sec用戶的數據到secooler用戶
          1)確認sec用戶下的T表及其數據量
          sys@secooler> conn sec/sec
          Connected.
          sec@secooler> select * From cat;

          TABLE_NAME                     TABLE_TYPE
          ------------------------------ -----------
          T                              TABLE

          sec@secooler> select count(*) from t;

            COUNT(*)
          ----------
               71325

          2)查看secooler用戶
          sys@secooler> conn secooler/secooler
          Connected.
          secooler@secooler> select * from cat;

          no rows selected

          此時secooler用戶中不包含任何T表信息。

          3)使用IMPDP工具實現數據從sec用戶向secooler用戶復制的功能
          secooler@secDB /home/oracle$ impdp system/sys network_link=dblink_to_myself schemas=sec remap_schema=sec:secooler

          Import: Release 11.2.0.1.0 - Production on Thu Apr 8 10:01:16 2010

          Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

          Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
          With the Partitioning, Oracle Label Security, OLAP, Data Mining,
          Oracle Database Vault and Real Application Testing options
          Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01":  system/******** network_link=dblink_to_myself schemas=sec remap_schema=sec:secooler
          Estimate in progress using BLOCKS method...
          Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
          Total estimation using BLOCKS method: 9 MB
          Processing object type SCHEMA_EXPORT/USER
          ORA-31684: Object type USER:"SECOOLER" already exists
          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/PRE_SCHEMA/PROCACT_SCHEMA
          Processing object type SCHEMA_EXPORT/TABLE/TABLE
          . . imported "SECOOLER"."T"                               71325 rows
          Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
          Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at 10:02:45

          3.查看secooler用戶數據,驗收遷移成果
          secooler@secDB /home/oracle$ sqlplus secooler/secooler

          SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 8 10:04:55 2010

          Copyright (c) 1982, 2009, Oracle.  All rights reserved.


          Connected to:
          Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
          With the Partitioning, Oracle Label Security, OLAP, Data Mining,
          Oracle Database Vault and Real Application Testing options

          secooler@secooler> select * from cat;

          TABLE_NAME                     TABLE_TYPE
          ------------------------------ -----------
          T                              TABLE

          secooler@secooler> select count(*) from t;

            COUNT(*)
          ----------
               71325

          令人激動地時刻到了,sec用戶下的T表及其數據已經成功的“復制”到了secooler用戶中。

          4.小結
          使用IMPDP工具完成用戶數據復制的優點:
          1)節省了大量的磁盤空間,因為不用生成中間的dump文件;
          2)操作簡便,步驟精簡;
          3)因為操作環節的減少,整個操作過程不易出錯。

          Good luck.

          secooler
          10.04.07

          -- The End --

          posted on 2012-08-23 15:50 Dragon4s 閱讀(334) 評論(0)  編輯  收藏 所屬分類: Oracle

          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          留言簿

          文章分類(6)

          文章檔案(6)

          最新隨筆

          搜索

          最新評論

          主站蜘蛛池模板: 胶州市| 南京市| 克拉玛依市| 乌鲁木齐县| 万盛区| 罗山县| 清徐县| 房产| 静安区| 思南县| 稷山县| 五原县| 临安市| 巴林右旗| 信阳市| 夏邑县| 苏州市| 承德市| 九寨沟县| 宁明县| 临沭县| 清流县| 离岛区| 远安县| 溧水县| 织金县| 河津市| 乐昌市| 沁水县| 宣恩县| 正镶白旗| 石渠县| 乌兰县| 新沂市| 仙桃市| 兰考县| 纳雍县| 凤山县| 连平县| 兴国县| 天门市|