1. EXPDP/IMPDP方式





SQL> create user zlm identified by zlm;





User created.





SQL> grant connect,resource to zlm;





Grant succeeded.





SQL> create tablespace ts_zlm datafile '/u01/app/oracle/oradata/ora10g/zlm01.dbf' size 100M reuse;





Tablespace created.





SQL> alter user zlm default tablespace ts_zlm;





User altered.





SQL> select username,default_tablespace from dba_users where username='ZLM';





USERNAME                       DEFAULT_TABLESPACE

------------------------------ ------------------------------

ZLM                            TS_ZLM





SQL> col name for a50

SQL> select name,bytes/1024/1024 from v$datafile where name like '%users01.dbf';





NAME                                               BYTES/1024/1024

-------------------------------------------------- ---------------

/u01/app/oracle/oradata/ora10g/users01.dbf                      





SQL> set lin 120 pages 120

SQL> col username for a8

SQL> col name for a45

SQL> select a.username,a.default_tablespace,b.name from dba_users a,v$datafile b,v$tablespace c where a.default_tablespace=c.name and b.ts#=c.ts# and a.username='SCOTT'; 





USERNAME DEFAULT_TABLESPACE             NAME

-------- ------------------------------ ---------------------------------------------

SCOTT    USERS                          /u01/app/oracle/oradata/ora10g/users01.dbf





SQL> alter database datafile '/u01/app/oracle/oradata/ora10g/users01.dbf' resize 100M;





Database altered.





SQL> select name,bytes/1024/1024 from v$datafile where name like '%users01.dbf';





NAME                                          BYTES/1024/1024

--------------------------------------------- ---------------

/u01/app/oracle/oradata/ora10g/users01.dbf                









SQL> select owner,directory_name from dba_directories;









OWNER                          DIRECTORY_NAME

------------------------------ ------------------------------

SYS                            DATA_PUMP_DIR

SYS                            SUBDIR

SYS                            XMLDIR

SYS                            MEDIA_DIR

SYS                            LOG_FILE_DIR

SYS                            DATA_FILE_DIR

SYS                            WORK_DIR

SYS                            ADMIN_DIR





SQL> create directory zlm_pump as '/u01/expdp';





Directory created.





SQL> !mkdir /u01/expdp





SQL> alter user scott identified by tiger account unlock;





User altered.





SQL> grant connect,resource to scott;





Grant succeeded.





SQL> grant read,write on directory zlm_pump to scott;





Grant succeeded.





SQL> conn scott/tiger

Connected.

SQL> create table zlm1 as select * from dba_objects;





Table created.





SQL> insert into zlm1 select * from dba_objects;





50318 rows created.





SQL> /





50318 rows created.





SQL> select count(*) from zlm1;





  COUNT(*)

----------

   





SQL> select table_name from user_tables where tablespace_name='USERS';





TABLE_NAME

------------------------------

ZLM1

SALGRADE

BONUS

EMP

DEPT





[oracle@ora10g ~]$ expdp scott/tiger parallel=2 directory=zlm_pump dumpfile=scott01.dmp,scott02.dmp tablespaces=users





Export: Release 10.2.0.1.0 - Production on Sunday, 31 August, 2014 14:35:29





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





Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Starting "SCOTT"."SYS_EXPORT_TABLESPACE_01":  scott/******** parallel=2 directory=zlm_pump dumpfile=scott01.dmp,scott02.dmp tablespaces=users 

Estimate in progress using BLOCKS method...--能够通过estimate=block(默认值)指定。另一个是statistic

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 17.18 MB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported "SCOTT"."ZLM1"                              14.06 MB  150954 rows

. . exported "SCOTT"."DEPT"                              5.656 KB       4 rows

. . exported "SCOTT"."EMP"                               7.820 KB      14 rows

. . exported "SCOTT"."SALGRADE"                          5.585 KB       5 rows

. . exported "SCOTT"."BONUS"                                 0 KB       0 rows

Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

Processing object type TABLE_EXPORT/TABLE/COMMENT

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

Master table "SCOTT"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded

******************************************************************************

Dump file set for SCOTT.SYS_EXPORT_TABLESPACE_01 is:

  /u01/expdp/scott01.dmp

  /u01/expdp/scott02.dmp

Job "SCOTT"."SYS_EXPORT_TABLESPACE_01" successfully completed at 14:36:10





[oracle@ora10g ~]$ impdp zlm/zlm parallel=2 remap_schema=scott:zlm remap_tablespace=users:ts_zlm directory=zlm_pump dumpfile=scott01.dmp,scott02.dmp

 

Import: Release 10.2.0.1.0 - Production on Sunday, 31 August, 2014 14:41:30





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





Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Master table "ZLM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded

Starting "ZLM"."SYS_IMPORT_FULL_01":  zlm/******** parallel=2 remap_schema=scott:zlm remap_tablespace=users:ts_zlm directory=zlm_pump dumpfile=scott01.dmp,scott02.dmp 

Processing object type TABLE_EXPORT/TABLE/TABLE

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

. . imported "ZLM"."DEPT"                                5.656 KB       4 rows

. . imported "ZLM"."EMP"                                 7.820 KB      14 rows

. . imported "ZLM"."SALGRADE"                            5.585 KB       5 rows

. . imported "ZLM"."BONUS"                                   0 KB       0 rows

. . imported "ZLM"."ZLM1"                                14.06 MB  150954 rows

Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS

Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT

Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS

Job "ZLM"."SYS_IMPORT_FULL_01" successfully completed at 14:41:43

[oracle@ora10g ~]$ sqlplus /nolog





SQL*Plus: Release 10.2.0.1.0 - Production on Sun Aug 31 14:43:12 2014





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





SQL> conn zlm/zlm

Connected.

SQL> select table_name from user_tables where tablespace_name='TS_ZLM';





TABLE_NAME

------------------------------

ZLM1

SALGRADE

BONUS

EMP

DEPT





SQL> select object_name from user_objects;





OBJECT_NAME

--------------------------------------------------------------------------------

DEPT

EMP

BONUS

SALGRADE

ZLM1

PK_DEPT

PK_EMP





SCHEMA SCOTT的表空间USERS中的所有对象已经被导入到SCHEMA ZLM的表空间,包含表和索引





2. EXP/IMP方式





SQL> conn / as sysdba

Connected.

SQL> drop user zlm cascade;





User dropped.





SQL> create user zlm identified by zlm;





User created.





SQL> grant connect,resource to zlm;





Grant succeeded.





SQL> alter user zlm default tablespace ts_zlm;





User altered.





SQL> conn zlm/zlm

Connected.

SQL> select * from cat;





no rows selected





SQL> !

[oracle@ora10g ~]$ exp scott/tiger owner=scott file=/u01/scott01.dmp                                                       





Export: Release 10.2.0.1.0 - Production on Sun Aug 31 15:42:00 2014





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









Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

Export done in US7ASCII character set and AL16UTF16 NCHAR character set

server uses ZHS16GBK character set (possible charset conversion)

. exporting pre-schema procedural objects and actions

. exporting foreign function library names for user SCOTT 

. exporting PUBLIC type synonyms

. exporting private type synonyms

. exporting object type definitions for user SCOTT 

About to export SCOTT's objects ...

. exporting database links

. exporting sequence numbers

. exporting cluster definitions

. about to export SCOTT's tables via Conventional Path ...

. . exporting table                          BONUS          0 rows exported

EXP-00091: Exporting questionable statistics.

. . exporting table                           DEPT          4 rows exported

EXP-00091: Exporting questionable statistics.

EXP-00091: Exporting questionable statistics.

. . exporting table                            EMP         14 rows exported

EXP-00091: Exporting questionable statistics.

EXP-00091: Exporting questionable statistics.

. . exporting table                       SALGRADE          5 rows exported

EXP-00091: Exporting questionable statistics.

. . exporting table                           ZLM1     150954 rows exported

. exporting synonyms

. exporting views

. exporting stored procedures

. exporting operators

. exporting referential integrity constraints

. exporting triggers

. exporting indextypes

. exporting bitmap, functional and extensible indexes

. exporting posttables actions

. exporting materialized views

. exporting snapshot logs

. exporting job queues

. exporting refresh groups and children

. exporting dimensions

. exporting post-schema procedural objects and actions

. exporting statistics

Export terminated successfully with warnings.

[oracle@ora10g ~]$ imp zlm/zlm fromuser=scott touser=zlm file=/u01/exp/scott01.dmp





Import: Release 10.2.0.1.0 - Production on Sun Aug 31 15:43:01 2014





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









Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options





IMP-00002: failed to open /u01/exp/scott01.dmp for read   --路径指定错了

Import file: expdat.dmp > /u01/scott01.dmp





Export file created by EXPORT:V10.02.01 via conventional path





Warning: the objects were exported by SCOTT, not by you





import done in US7ASCII character set and AL16UTF16 NCHAR character set

import server uses ZHS16GBK character set (possible charset conversion)

. . importing table                        "BONUS"          0 rows imported

. . importing table                         "DEPT"          4 rows imported

. . importing table                          "EMP"         14 rows imported

. . importing table                     "SALGRADE"          5 rows imported

. . importing table                         "ZLM1"     150954 rows imported

About to enable constraints...

Import terminated successfully with warnings.

[oracle@ora10g ~]$ exit

SQL> col object_name for a15

SQL> select object_name,object_type from user_objects;





OBJECT_NAME     OBJECT_TYPE

--------------- -------------------

BONUS           TABLE

DEPT            TABLE

PK_DEPT         INDEX

EMP             TABLE

PK_EMP          INDEX

SALGRADE        TABLE

ZLM1            TABLE





SQL> select table_name,tablespace_name from user_tables;





TABLE_NAME                     TABLESPACE_NAME

------------------------------ ------------------------------

BONUS                          USERS

DEPT                           USERS

EMP                            USERS

SALGRADE                       USERS

ZLM1                           USERS



注意。用imp导入后的对象,都是存放在exp导出时的表空间的,假设要迁移到别的表空间,就要使用alter table move tablespace来实现,先通过以下的SQL拼接语句来获得批量move的语句:

SQL> select 'alter table '||table_name||' MOVE TABLESPACE ts_zlm;' from user_tables; 





'ALTERTABLE'||TABLE_NAME||'MOVETABLESPACETS_ZLM;'

------------------------------------------------------------------

alter table BONUS MOVE TABLESPACE ts_zlm;

alter table DEPT MOVE TABLESPACE ts_zlm;

alter table EMP MOVE TABLESPACE ts_zlm;

alter table SALGRADE MOVE TABLESPACE ts_zlm;

alter table ZLM1 MOVE TABLESPACE ts_zlm;





SQL> select 'ALTER INDEX ' ||index_name || ' REBUILD TABLESPACE ts_zlm;' from user_indexes;





'ALTERINDEX'||INDEX_NAME||'REBUILDTABLESPACETS_ZLM;'

---------------------------------------------------------------------

ALTER INDEX PK_EMP REBUILD TABLESPACE ts_zlm;

ALTER INDEX PK_DEPT REBUILD TABLESPACE ts_zlm;





SQL> select table_name,tablespace_name from user_tables;





TABLE_NAME                     TABLESPACE_NAME

------------------------------ ------------------------------

SALGRADE                       TS_ZLM

EMP                            TS_ZLM

ZLM1                           TS_ZLM

DEPT                           TS_ZLM

BONUS                          TS_ZLM





SQL> select index_name,tablespace_name from user_indexes;





INDEX_NAME                     TABLESPACE_NAME

------------------------------ ------------------------------

PK_EMP                         TS_ZLM

PK_DEPT                        TS_ZLM

能够看到,zlm用户imp导入的数据库对象已经所有迁移到TS_ZLM表空间去了

总结:

EXPDP/IPMDP仅仅能在server上执行,其执行效率全然取决于磁盘I/O,而EXP/IMP不仅能够执行在server上。也能够执行在client上。所以除了磁盘I/O的制约因素,还有网络方面的因素。

EXPDP/IMPDP比EXP/IMP性能有非常大的提高,当中影响最大的就是paralle。通常设置为CPU的个数。通过该參数能够并行导出,大大提高导出速度。而EXP/IMP是没有这个功能的,最多也就仅仅有一个DIRECT=Y,使导出不用经过SELECT到SGA的BUFFER中。提高的速度是有限的,注意他们之间的语法也有不小的差别,參数不可互相替代。

EXPDP/IMPDP能够通过remap_schema和remap_tablespace直接实现不同用户和表空间之间的数据迁移;而EXP/IMP则略微麻烦一点,须要ALTER TABLE xxx MOVE TABLESPACE xxx/ALTER INDEX xxx REBUILD TABLESPACE xxx方式来实现。move相当于把表再重建一次,能够改动storage參数(如initial、pctfree、pctincrease等)。还能够move到另外的表空间,假设不指定表空间。则在原来的表空间中move,因此做move操作时,目标表空间须要保证有这个表相同大小的剩余空间,整个操作相当于exp/imp(从表空间A导出到表空间B)。move完表后要重建索引。

基于以上几种原因。如今做数据逻辑迁移都是用EXPDP/IMPDP而非常少再使用EXP/IMP了。

EXPDP/IMPDP与EXP/IMP在不同用户和表空间之间迁移数据的实现方法的更多相关文章

  1. Oracle创建删除用户,角色,表空间,导入导出数据库命令总结(转载)

    无意间看到一篇文章,觉得对于ORACLE的新手很实用,特转载,原文出处这里 说明:在创建数据库时输入的密码,是修改系统默认的密码,以system和sysman等系统默认身份登录时要输入的密码就是修改后 ...

  2. oracle数据库_实例_用户_表空间之间的关系(转)

    数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的概念和其它数据库不一样,这里的数据库是一个操作系统只有一个库.可 ...

  3. oracle数据库_实例_用户_表空间之间的关系

    基础概念:Oracle数据库.实例.用户.表空间.表之间的关系 数据库:Oracle数据库是数据的物理存储.这就包括(数据文件ORA或者DBF.控制文件.联机日志.参数文件).其实Oracle数据库的 ...

  4. expdp\impdp及exp\imp

    数据泵文件 expdp介绍 EXPDP命令行选项1. ATTACH该选项用于在客户会话与已存在导出作用之间建立关联.语法如下ATTACH=[schema_name.]job_nameSchema_na ...

  5. oracle数据库 expdp/impdp 和 exp/imp

    --EXPDP导出,需要系统用户权限,一般不使用--sqlplus--1.创建dmp导出逻辑目录 create directory 目录名 as '目录路径' create directory exp ...

  6. ORACLE创建表空间、创建用户、更改用户默认表空间以及授权、查看权限

    Oracle创建用户.表空间.导入导出....命令 //创建临时表空间 create temporary tablespace ext_temptempfile 'D:\oracle\product\ ...

  7. linux环境:创建数据库用户,表空间,启动数据库

    1.启动数据库 首先使用oracle用户登录Linux,然后在shell命令行中执行下面的命令:第一步:打开Oracle监听(先查看状态:oracle监听是否启动:lsnrctl status)$ l ...

  8. ORACLE创建用户,表空间,并且导出数据,导出表

    1.创建用户: create user toptea2 identified by "用户名" 2.给用户授权 grant create session to 用户名; grant ...

  9. Oracle 删除用户和表空间////Oracle创建删除用户、角色、表空间、导入导出、...命令总结/////Oracle数据库创建表空间及为用户指定表空间

    Oracle 使用时间长了, 新增了许多user 和tablespace. 需要清理一下 对于单个user和tablespace 来说, 可以使用如下命令来完成. 步骤一:  删除user drop ...

随机推荐

  1. 后台开发常用mysql语句_v1.0

    目录 一.基本信息查看 1. 表描述 二.表操作 1. 查看建表语句 2.查看表 3. 创建表 4. 更新表 5. 删除表 6. 重命名表 三.索引操作 1. 查看索引 2. 创建索引 3. 修改索引 ...

  2. 转载:tar命令批量解压方法总结

    由于linux的tar命令不支持批量解压,所以很多网友编写了好多支持批量解压的shell命令,收集了一下,供大家分享: 第一:for tar in *.tar.gz;  do tar xvf $tar ...

  3. 缩略图信息提取工具vinetto

    缩略图信息提取工具vinetto   在Windows操作系统中,为了方便用户快速浏览图片,系统会自动为每个图片生成预览图.预览图默认保存在同目录的Thumbs.db文件中.当图片文件删除后,Thum ...

  4. 连接LilyPad之Linux平台的驱动

    连接LilyPad之Linux平台的驱动 常用的Linux发行版都自带了FTDI驱动,因此在绝大多数Linux发行版中不需要用户进行额外的操作. 在LilyPad编程器被正确驱动后,就可以将LilyP ...

  5. 在 HTTP Request 中加入特定的 Header

    转:http://www.findspace.name/easycoding/1137 要加入 header,需要使用 Request 对象: #code1 import urllib2 reques ...

  6. 解决关于stack溢出的问题

    开发中经常遇到: 前端遇到Uncaught RangeError: Maximum call stack size exceeded错误 后台遇到java.lang.OutOfMemoryError: ...

  7. ARC 058

    所以为啥要写来着........... 链接 T1 直接枚举大于等于$n$的所有数,暴力分解判断即可 复杂度$O(10n \log n)$ #include <cstdio> #inclu ...

  8. luoguP3750 [六省联考2017]分手是祝愿 概率期望DP + 贪心

    ...........真的神状态了,没办法去想的状态................... 考试的时候选择$50$分贪心+$15$分状压吧,别的点就放弃算了........ 令$f[i]$表示从最小步 ...

  9. noip模拟 五子棋

    递推+模拟.在读取数据时,我们建4个图,分别代表这个图中横.纵.左斜右斜的连续长度.例如heng[i][j]代表ij这个点所在的横着一条线的长度. 然后搜索,对于一个空点,如果他的上下都>=4那 ...

  10. PAT甲级1103. Integer Factorization

    PAT甲级1103. Integer Factorization 题意: 正整数N的K-P分解是将N写入K个正整数的P次幂的和.你应该写一个程序来找到任何正整数N,K和P的N的K-P分解. 输入规格: ...