oracle_11g 不同用户之间的数据迁移

众所周知,IMP工具的FROMUSER和TOUSER参数可以实现将一个用户的的数据迁移到另外一个用户。同样的功能在IMPPDP工具中如何得以体现呢?
答案就是:使用IMPPDP的REMAP_SCHEMA参数实现。

简单演示一下,供参考。

任务:将sec用户中的数据迁移到secooler用户。

1.分别确认sec和secooler用户下的表和数据情况
1)sec用户下有一张T表,含有24360行数据
[email protected]> conn sec/sec
Connected.
[email protected]> select * from tab;

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

[email protected]> select count(*) from t;

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

2)确认secooler用户不包含表T
[email protected]> conn secooler/secooler
Connected.
[email protected]> select * from tab;

no rows selected

2.创建目录对象expdp_dir
[email protected]> create or replace directory expdp_dir as ‘/expdp‘;

Directory created.

3.将目录对象expdp_dir的读写权限授权给sec和secooler用户
[email protected]> grant read,write on directory expdp_dir to sec;

Grant succeeded.

[email protected]> grant read,write on directory expdp_dir to secooler;

Grant succeeded.

4.生成sec的备份文件
[email protected] /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

生成的备份文件信息如下:
[email protected] /expdp$ ls -l *sec.dmp
-rw-r----- 1 oracle oinstall 2.5M Apr  1 10:29 20100401102917_sec.dmp

5.使用IMPDP的REMAP_SCHEMA参数实现secooler用户的数据导入
[email protected] /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,迁入任务完成。

6.确认最后的迁移迁移成果
连接到secooler用户确认T表及其中的数据是否已经完成导入。
[email protected]> conn secooler/secooler
Connected.
[email protected]> select * from tab;

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

[email protected]> 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一份在此:
REMAP_SCHEMA

Default: none

Purpose

Loadsall objects from the source schema into a target schema.

Syntax and Description

REMAP_SCHEMA=source_schema:target_schema

MultipleREMAP_SCHEMAlines 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 necessaryCREATEUSERmetadata 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 userSYSTEMhas the necessary privileges:

> expdp SYSTEM/passwordSCHEMAS=hr
> expdp SYSTEM/passwordFULL=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,SCOTTcan remap hisBLAKE‘s objects toSCOTT, butSCOTTcannot remapSCOTT‘s objects toBLAKE.

Example

Suppose that you execute the following Export and Import commands to remap thehrschema into thescottschema:

> expdp SYSTEM/passwordSCHEMAS=hr DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp

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

In this example, if userscottalready exists before the import, then the ImportREMAP_SCHEMAcommand will add objects from thehrschema into the existingscottschema. You can connect to thescottschema after the import by using the existing password (without resetting it).

If userscottdoes 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 bySYSTEM,which has the privileges necessary to create a dump file that contains the metadata needed to create a schema. However, you cannot connect toscotton completion of the import, unless you reset the password forscotton the target database after the import completes.
8.小结
在从EXP备份工具转到EXPDP工具的过程中,有很多的变动一定要注意,防止因误用导致效率低下。
无论是从功能上还是效率上讲,EXPDP都是首选(需要在服务器端使用)。

Good luck.

时间: 2024-10-13 00:23:05

oracle_11g 不同用户之间的数据迁移的相关文章

阿里云RDS实例内不同数据库之间的数据迁移

适用场景 本文适用于使用DTS实现相同实例下库名不同的数据库之间的数据迁移.本文以使用DTS将同一RDS实例下的amptest库迁移到jiangliu_amptest库为例来说明如何使用DTS实现相同实例下库名不同的数据库之间的数据迁移. 说明:当源和目标实例类型不为RDS时,配置流程相同. 环境准备 创建RDS账号,不同的数据库类型,要求的迁移账号权限不同,具体权限要求可以参考产品手册-数据迁移中的相关文档. 在同一RDS实例下创建好amptest数据库以及jiangliu_amptest数据

生产环境下,oracle不同用户间的数据迁移。第三部分

任务名称:生产环境下schema ELON数据迁移至schema TIAN########################################前期准备:1:确认ELON用户下的对象状态select owner,constraint_name,constraint_type,table_name,status,validated from dba_constraints where owner='ELON'owner constraint_name constraint_type ta

生产环境下,oracle不同用户间的数据迁移。第二部分

任务名称:生产环境下schema ELON数据迁移至schema TIAN######################################## 测试二:测试参数remap_tablespace 导出schema ELON的全部数据:[[email protected] ~]$expdp system/xxxxxx SCHEMAS=ELON directory=EXPDP_DIR dumpfile =ELON_`date +"%Y%m%d%H%M%S"`.dmp logfil

利用Kettle进行SQLServer与Oracle之间的数据迁移实践

Kettle简介 Kettle(网地址为http://kettle.pentaho.org/)是一款国外开源的ETL工具,纯java编写,可以在Windows.Linux.Unix上运行,数据抽取高效稳定. Kettle 中文名称叫水壶,该项目的主程序员MATT 希望把各种数据放到一个壶里,然后以一种指定的格式流出.Kettle中有两种脚本文件,transformation和job,transformation完成针对数据的基础转换,job则完成整个工作流的控制. Windows环境下的安装与配

jsp在不同页面或者用户之间共享数据

1.同一用户回话不同页面之间数据共享方法 (1)通过Cookie. (2)通过隐含的表单把数据提交到下一个页面. (3)通过ServletContext对象. (4)通过application对象. (5)通过文件系统或者数据库. 2.不同用户回话不同页面之间数据共享方法 (1)通过ServletContext对象. (2)通过application对象. (3)通过文件系统或者数据库. 具体实现方法见

ORACLE与MS SQL之间的数据迁移

就职百度期间,王劲分别创立了百度移动云事业部.百度大数据部.百度基础架构(云计算)部.百度美国研发中心.百度深圳研发中心:并以百度深度学习实验室(IDL)为基础,联合创立了百度研究院.在2010年4月到2015年4月的5年间,王劲同时还负责百度商业变现的技术与产品(凤巢). 2013年百度启动无人车项目,2015年12月14日,百度成立了自动驾驶事业部,王劲出任事业部总经理. 王劲一度成为百度无人车业务的代言人,直到2017年3月份,王劲离开百度,据腾讯<一线>报道,王劲与百度的分手并不愉快.

mysql数据迁移

一. 数据迁移简介所谓的数据迁移,就是指将原有的数据库系统迁移到另外一个业务系统上数据迁移的原因是多种多样的,有可能是业务变更.硬件升级.平台切换或升级mysql数据库 迁移的注意事项:(1).相同版本可以迁移(2).注意版本可以使用的引擎(3).低版本可以向高版本进行数据迁移,高版本一般兼容低版本的特性(4).高版本的数据不能向低版本进行数据迁移,会出现数据不兼容的情况(5).迁移是请注意导出数据和备份数据,出现迁移失败时,立即启动备份方案,保证公司业务的正常运行(6).在数据迁移时,要选择用

SQL SERVER几种数据迁移/导出导入的实践

SQLServer提供了多种数据导出导入的工具和方法,在此,分享我实践的经验(只涉及数据库与Excel.数据库与文本文件.数据库与数据库之间的导出导入). (一)数据库与Excel 方法1: 使用数据库客户端(SSMS)的界面工具.右键选择要导出数据的数据库,选择“任务”——“导出数据”,下图1,按照向导一步一步操作即可.而导入则相反,导入时,SQLServer会默认创建一张新表,字段名也默认跟导入的Excel标题一样,并且会默认字段数据类型等.当然在可以在向导进行修改.需要注意的是如果标题不是

Office365 Groups and OD4B 不同tenant之间数据迁移_经验分享

目前国内很多企业都逐渐借助Microsoft 365的 解决方案为内部员工提供现代化办公环境,不限于可以提高企业分支机构之间的协作办公效率,满足跨平台移动办公需求,同时对企业来说也降低了IT基础架构投入和管理成本.但随着企业业务模型扩增,陆续有很多企业需要更高标准的Office 365 来满足其业务需求,那么就会衍生很多企业有Office 365 Tenant to Tenant的 数据转移的项目发生,但数据迁移并非是件容易的事情,需要考量点的地方比较多,同时利用对来源端的数据结构合理的分析并制