[Z] 【IMPDP】同一數(shù)據(jù)庫實(shí)例不同用戶間數(shù)據(jù)遷移復(fù)制——NETWORK_LINK參數(shù)
@URL > http://space.itpub.net/519536/viewspace-631571
如何快速的復(fù)制一個(gè)用戶的數(shù)據(jù)到另外一個(gè)用戶(這個(gè)用戶可能在不同的數(shù)據(jù)庫中)?
一般答案:使用EXP(EXPDP)與IMP(IMPDP)相結(jié)合完成用戶數(shù)據(jù)的導(dǎo)入和導(dǎo)出
高級方法:IMPDP工具提供的NETWORK_LINK參數(shù)可以一步到位的完成此項(xiàng)艱巨的任務(wù)。
這種方法非常類似于使用CTAS方法在表復(fù)制中的應(yīng)用,只不過這里我們實(shí)現(xiàn)的是用戶間的數(shù)據(jù)復(fù)制。
使用這種方法的一般步驟如下:
a.創(chuàng)建database link;
b.使用IMPDP的network_link、schemas和remap_schema相結(jié)合完成用戶的數(shù)據(jù)的遷移;
真實(shí)的感受一下此項(xiàng)技術(shù)帶給我們的快樂。
實(shí)現(xiàn)案例:同一個(gè)實(shí)例中不同用戶間的遷移復(fù)制。
1.創(chuàng)建指向自身的DATABASE LINK
1)確認(rèn)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)在數(shù)據(jù)庫系統(tǒng)中創(chuàng)建一個(gè)指向自身的DATABASE LINK
sys@secooler> create public database link dblink_to_myself connect to system identified by sys using 'SECOOLER';
Database link created.
2.復(fù)制sec用戶的數(shù)據(jù)到secooler用戶
1)確認(rèn)sec用戶下的T表及其數(shù)據(jù)量
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
此時(shí)secooler用戶中不包含任何T表信息。
3)使用IMPDP工具實(shí)現(xiàn)數(shù)據(jù)從sec用戶向secooler用戶復(fù)制的功能
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用戶數(shù)據(jù),驗(yàn)收遷移成果
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
令人激動地時(shí)刻到了,sec用戶下的T表及其數(shù)據(jù)已經(jīng)成功的“復(fù)制”到了secooler用戶中。
4.小結(jié)
使用IMPDP工具完成用戶數(shù)據(jù)復(fù)制的優(yōu)點(diǎn):
1)節(jié)省了大量的磁盤空間,因?yàn)椴挥蒙芍虚g的dump文件;
2)操作簡便,步驟精簡;
3)因?yàn)椴僮鳝h(huán)節(jié)的減少,整個(gè)操作過程不易出錯(cuò)。
Good luck.
secooler
10.04.07
-- The End --
posted on 2012-08-23 15:50 Dragon4s 閱讀(335) 評論(0) 編輯 收藏 所屬分類: Oracle