oracle同库复制schema,使用impdp复制oracle的schema数据迁移 | 学步园
測(cè)試環(huán)境:
源: windows 2003, oracle 10202
目標(biāo):windows 2000, oracle 10203
注:本文中所說(shuō)的 schema 和 user 是一個(gè)意思。
impdp 的數(shù)據(jù)源既可以是expdp 導(dǎo)出來(lái)的DMP文件,也可以是一數(shù)據(jù)庫(kù),通過(guò)network_link 參數(shù)來(lái)指定數(shù)據(jù)源,schemas
參數(shù)說(shuō)明要復(fù)制的用戶,remap_schemas 參數(shù)說(shuō)明源用戶與目標(biāo)用戶的匹配關(guān)系,remap_tablepace 來(lái)調(diào)整原 schemas
使用的表空間與目標(biāo)數(shù)據(jù)庫(kù)用戶要表空間的對(duì)應(yīng)關(guān)系。這樣,基本上可以把源schema的數(shù)據(jù)導(dǎo)入到目標(biāo)數(shù)據(jù)庫(kù)。格式如下:
2、impdp user/password parfile=parfile.log
**********parfile.log 的內(nèi)容***************
network_link=目標(biāo)數(shù)據(jù)庫(kù)上的數(shù)據(jù)庫(kù)鏈。
schema=源數(shù)據(jù)庫(kù)上導(dǎo)出數(shù)據(jù)的用戶。
remap_schema=源用戶:目標(biāo)用戶。
remap_tablespace=源用戶使用的表空間:目標(biāo)用戶將使用的表空間(包括臨時(shí)表空間)。
**********parfile.log 的內(nèi)容***************
過(guò)程舉例:
1、在目標(biāo)數(shù)據(jù)庫(kù)上創(chuàng)建數(shù)據(jù)庫(kù)鏈,指向源數(shù)據(jù)庫(kù),數(shù)據(jù)庫(kù)鏈中連接的用戶必須具備EXP_FULL_DATABASE
角色的權(quán)限。 例:
A、新建數(shù)據(jù)庫(kù)鏈里的用戶,授予create session 和使用users 空間的權(quán)限,
SQL> create user link identified by "1";
用戶已創(chuàng)建。
SQL> grant create session to link;
授權(quán)成功。
SQL> ALTER USER LINK QUOTA UNLIMITED ON USERS;
用戶已更改。
B、為該用戶創(chuàng)建一表,用于測(cè)試復(fù)制用戶過(guò)程。
SQL> CREATE TABLE LINK.DOC_TYPE AS SELECT * FROM INFO.DOC_TYPE;
表已創(chuàng)建。
SQL> SELECT TABLE_NAME FROM DBA_TABLES WHERE OWNER='LINK';
TABLE_NAME
------------------------------
DOC_TYPE
C、使用該用戶來(lái)創(chuàng)建數(shù)據(jù)庫(kù)鏈。
SQL> create public database link tolink connect to link identified by "1" using '37ZHS';
數(shù)據(jù)庫(kù)鏈接已創(chuàng)建。
D、使用該鏈來(lái)復(fù)制link用戶,報(bào) ORA-39149: cannot link privileged user to non-privileged user
錯(cuò)誤。
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 權(quán)限后,復(fù)制成功。
SQL> grant exp_full_database to link;
授權(quán)成功。
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
又如,在兩數(shù)據(jù)庫(kù)間復(fù)制用戶:
A、源數(shù)據(jù)庫(kù)是上面例子中的LINK,
B、目標(biāo)數(shù)據(jù)庫(kù)是10203版本,要將源中的LINK復(fù)制到目標(biāo)中的LINK2中。
SYS@BTB>create public database link tolink connect to link identified by "1" using '37zhs';
數(shù)據(jù)庫(kù)鏈接已創(chuàng)建。
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
自動(dòng)啟用 FLASHBACK 以保持?jǐn)?shù)據(jù)庫(kù)完整性。
啟動(dòng) "SYS"."SYS_IMPORT_SCHEMA_03": /******** AS SYSDBA network_link=tolink schemas=link remap_sch
ema=link:link2
正在使用 BLOCKS 方法進(jìn)行估計(jì)...
處理對(duì)象類型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的總估計(jì): 64 KB
處理對(duì)象類型 SCHEMA_EXPORT/USER
處理對(duì)象類型 SCHEMA_EXPORT/SYSTEM_GRANT
處理對(duì)象類型 SCHEMA_EXPORT/ROLE_GRANT
處理對(duì)象類型 SCHEMA_EXPORT/DEFAULT_ROLE
處理對(duì)象類型 SCHEMA_EXPORT/TABLESPACE_QUOTA
處理對(duì)象類型 SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
處理對(duì)象類型 SCHEMA_EXPORT/TABLE/TABLE
. . 導(dǎo)入了 "LINK2"."DOC_TYPE" 8 行
作業(yè) "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的創(chuàng)建時(shí)間可以知道,該用戶是剛創(chuàng)建的。
注:
1,從上面兩例子看出,不論是在兩數(shù)據(jù)庫(kù)間,還是在同一數(shù)據(jù)庫(kù)里復(fù)制SCHEMAS,都必須
使用network_link,才能說(shuō)明是在復(fù)制數(shù)據(jù)。
2,"remap_schema=源用戶:目標(biāo)用戶" 中的目標(biāo)用戶可以事先創(chuàng)建。
總結(jié)
以上是生活随笔為你收集整理的oracle同库复制schema,使用impdp复制oracle的schema数据迁移 | 学步园的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: expected:instruction
- 下一篇: mysql --max_allowed_