众所周知,IMP工具的FROMUSER和TOUSER参数可以实现将一个用户的的数据迁移到另外一个用户。同样的功能在IMPPDP工具中如何得以体现呢?
答案就是:使用IMPPDP的REMAP_SCHEMA参数实现。
简单演示一下,供参考。
任务:将sec用户中的数据迁移到secooler用户。
1.分别确认sec和secooler用户下的表和数据情况
1)sec用户下有一张T表,含有24360行数据
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)确认secooler用户不包含表T
secooler@ora10g> conn secooler/secooler
Connected.
secooler@ora10g> select * from tab;
no rows selected
2.创建目录对象expdp_dir
sys@ora10g> create or replace directory expdp_dir as ‘/expdp’;
Directory created.
3.将目录对象expdp_dir的读写权限授权给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\( <span style="text-decoration: underline"><strong>expdp</strong></span> 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<br><br>Export: Release 10.2.0.3.0 - 64bit Production on Thursday, 01 April, 2010 10:29:17<br><br>Copyright (c) 2003, <span style="text-decoration: underline"><strong>2005</strong></span>, <span style="text-decoration: underline"><strong>Oracle</strong></span>. All rights reserved.<br><br>Connected to: Oracle Database <span style="text-decoration: underline"><strong>10g</strong></span> Enterprise Edition Release 10.2.0.3.0 - 64bit Production<br>With the Partitioning, Oracle Label Security, OLAP and <span style="text-decoration: underline"><strong>Data</strong></span> Mining Scoring Engine options<br>Starting "SEC"."SYS_EXPORT_SCHEMA_01": sec/ directory=expdp_dir dumpfile=917_sec.dmp logfile=917_sec.log<br>Estimate in progress using BLOCKS method...<br>Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA<br>Total estimation using BLOCKS method: 3 MB<br>Processing object type SCHEMA_EXPORT/USER<br>Processing object type SCHEMA_EXPORT/SYSTEM_GRANT<br>Processing object type SCHEMA_EXPORT/ROLE_GRANT<br>Processing object type SCHEMA_EXPORT/DEFAULT_ROLE<br>Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA<br>Processing object type SCHEMA_EXPORT/TABLE/TABLE<br>Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX<br>Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT<br>Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS<br>Processing object type SCHEMA_EXPORT/TABLE/COMMENT<br>. . exported "SEC"."T" 2.259 MB 24360 rows<br>Master table "SEC"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded<br><br>Dump file set for SEC.SYS_EXPORT_SCHEMA_01 is:<br> /expdp/917_sec.dmp<br>Job "SEC"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:29:20<br><br>生成的备份文件信息如下:<br>ora10g@secDB /expdp\) ls -l *sec.dmp
-rw-r—– 1 oracle oinstall 2.5M Apr 1 10:29 917_sec.dmp
5.使用IMPDP的REMAP_SCHEMA参数实现secooler用户的数据导入
ora10g@secDB /expdp$ impdp secooler/secooler directory=expdp_dir dumpfile=917_sec.dmp logfile=917_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 © 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=917_sec.dmp logfile=917_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,迁入任务完成。
6.确认最后的迁移迁移成果
连接到secooler用户确认T表及其中的数据是否已经完成导入。
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.进一步参考资料
最好的参考资料就是Oracle的官方文档,参考链接如下:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_import.htm#sthref340
便于参考,copy一份在此:
Default: none
Loadsall objects from the source schema into a target schema.
Multiplelines 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 necessarymetadata 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 userhas the necessary privileges:
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:
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,can remap his's objects to, butcannot remap's objects to.
Suppose that you execute the following Export and Import commands to remap theschema into theschema:
In this example, if useralready exists before the import, then the Importcommand will add objects from theschema into the existingschema. You can connect to theschema after the import by using the existing password (without resetting it).
If userdoes not exist before you execute the import operation, Import automatically creates it with an unusable password. This is possible because the dump file,., was created bywhich has the privileges necessary to create a dump file that contains the metadata needed to create a schema. However, you cannot connect toon completion of the import, unless you reset the password foron the target database after the import completes.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/139110.html