溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

【IMPDP】實(shí)現(xiàn)不同用戶之間的數(shù)據(jù)遷移——REMAP_SCHEMA參數(shù)

發(fā)布時(shí)間:2020-08-10 17:04:54 來(lái)源:ITPUB博客 閱讀:272 作者:iotogo 欄目:建站服務(wù)器
眾所周知,IMP工具的FROMUSER和TOUSER參數(shù)可以實(shí)現(xiàn)將一個(gè)用戶的的數(shù)據(jù)遷移到另外一個(gè)用戶。同樣的功能在IMPPDP工具中如何得以體現(xiàn)呢?
答案就是:使用IMPPDP的REMAP_SCHEMA參數(shù)實(shí)現(xiàn)。

簡(jiǎn)單演示一下,供參考。

任務(wù):將sec用戶中的數(shù)據(jù)遷移到secooler用戶。

1.分別確認(rèn)sec和secooler用戶下的表和數(shù)據(jù)情況
1)sec用戶下有一張T表,含有24360行數(shù)據(jù)
sys@ora10g> conn sec/sec
Connected.
sec@ora10g> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
T                              TABLE

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

  COUNT(*)
----------
     24360

2)確認(rèn)secooler用戶不包含表T
secooler@ora10g> conn secooler/secooler
Connected.
secooler@ora10g> select * from tab;

no rows selected

2.創(chuàng)建目錄對(duì)象expdp_dir
sys@ora10g> create or replace directory expdp_dir as '/expdp';

Directory created.

3.將目錄對(duì)象expdp_dir的讀寫(xiě)權(quán)限授權(quán)給sec和secooler用戶
sys@ora10g> grant read,write on directory expdp_dir to sec;

Grant succeeded.

sys@ora10g> grant read,write on directory expdp_dir to secooler;

Grant succeeded.

4.生成sec的備份文件
ora10g@secDB /expdp$ expdp sec/sec directory=expdp_dir dumpfile=`date +"%Y%m%d%H%M%S"`_sec.dmp logfile=`date +"%Y%m%d%H%M%S"`_sec.log

Export: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:29:17

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Starting "SEC"."SYS_EXPORT_SCHEMA_01":  sec/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec.log
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 3 MB
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/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type SCHEMA_EXPORT/TABLE/COMMENT
. . exported "SEC"."T"                                   2.259 MB   24360 rows
Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:
  /expdp/20100401102917_sec.dmp
Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:29:20

生成的備份文件信息如下:
ora10g@secDB /expdp$ ls -l *sec.dmp
-rw-r----- 1 oracle oinstall 2.5M Apr  1 10:29 20100401102917_sec.dmp

5.使用IMPDP的REMAP_SCHEMA參數(shù)實(shí)現(xiàn)secooler用戶的數(shù)據(jù)導(dǎo)入
ora10g@secDB /expdp$ impdp secooler/secooler directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log REMAP_SCHEMA=sec:secooler

Import: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:32:10

Copyright (c) 2003, 2005, Oracle.  All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
Master table "SECOOLER"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SECOOLER"."SYS_IMPORT_FULL_01":  secooler/******** directory=expdp_dir dumpfile=20100401102917_sec.dmp logfile=20100401102917_sec_impdp.log REMAP_SCHEMA=sec:secooler
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
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "SECOOLER"."T"                              2.259 MB   24360 rows
Job "SECOOLER"."SYS_IMPORT_FULL_01" completed with 1 error(s) at 10:32:12

OK,遷入任務(wù)完成。

6.確認(rèn)最后的遷移遷移成果
連接到secooler用戶確認(rèn)T表及其中的數(shù)據(jù)是否已經(jīng)完成導(dǎo)入。
sec@ora10g> conn secooler/secooler
Connected.
secooler@ora10g> select * from tab;

TNAME                          TABTYPE  CLUSTERID
------------------------------ ------- ----------
T                              TABLE

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

  COUNT(*)
----------
     24360

OK,搞定。

7.進(jìn)一步參考資料
最好的參考資料就是Oracle的官方文檔,參考鏈接如下:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_import.htm#sthref340
便于參考,copy一份在此:

REMAP_SCHEMA

Default: none

Purpose

Loads all objects from the source schema into a target schema.

Syntax and Description

REMAP_SCHEMA=source_schema:target_schema

Multiple REMAP_SCHEMA lines can be specified, but the source schema must be different for each one. However, different source schemas can map to the same target schema. The mapping may not be 100 percent complete, because there are certain schema references that Import is not capable of finding. For example, Import will not find schema references ××ded within the body of definitions of types, views, procedures, and packages.

If the schema you are remapping to does not already exist, the import operation creates it, provided the dump file set contains the necessary CREATE USER metadata for the source schema and you are importing with enough privileges. For example, the following Export commands would create the dump file sets with the necessary metadata to create a schema, because the user SYSTEM has the necessary privileges:

> expdp SYSTEM/password SCHEMAS=hr
> expdp SYSTEM/password FULL=y

If your dump file set does not contain the metadata necessary to create a schema, or if you do not have privileges, then the target schema must be created before the import operation is performed. This is because the unprivileged dump files do not contain the necessary information for the import to create the schema automatically.

If the import operation does create the schema, then after the import is complete, you must assign it a valid password in order to connect to it. The SQL statement to do this, which requires privileges, is:

SQL> ALTER USER [schema_name] IDENTIFIED BY [new_pswd] 

Restrictions

Unprivileged users can perform. schema remaps only if their schema is the target schema of the remap. (Privileged users can perform. unrestricted schema remaps.)

For example, SCOTT can remap his BLAKE's objects to SCOTT, but SCOTT cannot remap SCOTT's objects to BLAKE.

Example

Suppose that you execute the following Export and Import commands to remap the hr schema into the scott schema:

> expdp SYSTEM/password SCHEMAS=hr DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp

> impdp SYSTEM/password DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp
REMAP_SCHEMA=hr:scott

In this example, if user scott already exists before the import, then the Import REMAP_SCHEMA command will add objects from the hr schema into the existing scott schema. You can connect to the scott schema after the import by using the existing password (without resetting it).

If user scott does not exist before you execute the import operation, Import automatically creates it with an unusable password. This is possible because the dump file, hr.dmp, was created by SYSTEM, which has the privileges necessary to create a dump file that contains the metadata needed to create a schema. However, you cannot connect to scott on completion of the import, unless you reset the password for scott on the target database after the import completes.

8.小結(jié)
在從EXP備份工具轉(zhuǎn)到EXPDP工具的過(guò)程中,有很多的變動(dòng)一定要注意,防止因誤用導(dǎo)致效率低下。
無(wú)論是從功能上還是效率上講,EXPDP都是首選(需要在服務(wù)器端使用)。

Good luck.

secooler
10.04.01

-- The End --

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI