oracle实验记录 (expdp/impdp使用)

10G新加
只能在server端使用,client端不能使用


expdp命令的使用时候有很多参数~可以满足不同需求,可以用HELP查看 参数及其使用说明
C:\>expdp system/a831115 help=y  使用help查看可使用的参数


Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 16:13:51

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


数据泵导出实用程序提供了一种用于在 Oracle 数据库之间传输
数据对象的机制。该实用程序可以使用以下命令进行调用:

   示例: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

您可以控制导出的运行方式。具体方法是: 在 'expdp' 命令后输入
各种参数。要指定各参数, 请使用关键字:

   格式:  expdp KEYWORD=value 或 KEYWORD=(value1,value2,...,valueN)
   示例: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott
               或 TABLES=(T1:P1,T1:P2), 如果 T1 是分区表

USERID 必须是命令行中的第一个参数。

关键字               说明 (默认)
------------------------------------------------------------------------------
ATTACH                连接到现有作业, 例如 ATTACH [=作业名]。
COMPRESSION           减小有效的转储文件内容的大小
                      关键字值为: (METADATA_ONLY) 和 NONE。
CONTENT               指定要卸载的数据, 其中有效关键字为:~~ (DATA_ONLY只导出数

据,metadata_only只导出对象定义)
                      (ALL), DATA_ONLY 和 METADATA_ONLY。
DIRECTORY             供转储文件和日志文件使用的目录对象。
DUMPFILE              目标转储文件 (expdat.dmp) 的列表,
                      例如 DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp。
ENCRYPTION_PASSWORD   用于创建加密列数据的口令关键字。
ESTIMATE              计算作业估计值, 其中有效关键字为:(当使用BLOCKS时oracle用导出对象

blocks*块尺寸算估计占用导出空间,statistics时用统计信息估算)
                      (BLOCKS) 和 STATISTICS。
ESTIMATE_ONLY         在不执行导出的情况下计算作业估计值。(N|Y 默认N ,Y时候是估导出作业占

用空间而不实际导出)
EXCLUDE               排除特定的对象类型, 例如 EXCLUDE=TABLE:EMP。
FILESIZE              以字节为单位指定每个转储文件的大小。(DEFAULT O 表示无限制)
FLASHBACK_SCN         用于将会话快照设置回以前状态的 SCN。
FLASHBACK_TIME        用于获取最接近指定时间的 SCN 的时间。
FULL                  导出整个数据库 (N)。
HELP                  显示帮助消息 (N)。
INCLUDE               包括特定的对象类型, 例如 INCLUDE=TABLE_DATA。
JOB_NAME              要创建的导出作业的名称。
LOGFILE               日志文件名 (export.log)。
NETWORK_LINK          链接到源系统的远程数据库的名称。
NOLOGFILE             不写入日志文件 (N)。
PARALLEL              更改当前作业的活动 worker 的数目。
PARFILE               指定参数文件。
QUERY                 用于导出表的子集的谓词子句。
SAMPLE                要导出的数据的百分比;
SCHEMAS               要导出的方案的列表 (登录方案)。
STATUS                在默认值 (0) 将显示可用时的新状态的情况下,
                      要监视的频率 (以秒计) 作业状态。
TABLES                标识要导出的表的列表 - 只有一个方案。
TABLESPACES           标识要导出的表空间的列表。
TRANSPORT_FULL_CHECK  验证所有表的存储段 (N)。
TRANSPORT_TABLESPACES 要从中卸载元数据的表空间的列表。
VERSION               要导出的对象的版本, 其中有效关键字为:
                      (COMPATIBLE), LATEST 或任何有效的数据库版本。
下列命令在交互模式下有效。
注: 允许使用缩写

命令               说明
------------------------------------------------------------------------------
ADD_FILE              向转储文件集中添加转储文件。
CONTINUE_CLIENT       返回到记录模式。如果处于空闲状态, 将重新启动作业。
EXIT_CLIENT           退出客户机会话并使作业处于运行状态。
FILESIZE              后续 ADD_FILE 命令的默认文件大小 (字节)。
HELP                  总结交互命令。
KILL_JOB              分离和删除作业。
PARALLEL              更改当前作业的活动 worker 的数目。
                      PARALLEL=。
START_JOB             启动/恢复当前作业。
STATUS                在默认值 (0) 将显示可用时的新状态的情况下,
                      要监视的频率 (以秒计) 作业状态。
                      STATUS[=interval]
STOP_JOB              顺序关闭执行的作业并退出客户机。
                      STOP_JOB=IMMEDIATE 将立即关闭


                      数据泵作业。

 

简单使用下几个参数


C:\>expdp system/a831115@xh  estimate_only=y (评估导出SYSTEM SCHEMA)


使用 BLOCKS 方法的总估计: 1.687 MB
作业 "SYSTEM"."SYS_EXPORT_SCHEMA_02" 已于 17:44:17 成功完成

 

C:\>expdp system/a831115@xh  tables=xh.t1 estimate_only=y

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:47:09

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TABLE_02":  system/********@xh tables=xh.t1 estimate_only
=y
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
.  预计为 "XH"."T1"                                      64 KB
使用 BLOCKS 方法的总估计: 64 KB
作业 "SYSTEM"."SYS_EXPORT_TABLE_02" 已于 17:47:20 成功完成

 

 

C:\>expdp system/a831115@xh directory=expdpt dumpfile=test.dmp tables=xh.t1 estimat
e_only=y

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:43:20

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORA-39002: 操作无效
ORA-39201: 仅用于评估的作业不支持转储文件。
不能写上DUMPFILE

 

C:\>expdp xh/a123@xh directory=expdpt dumpfile=D.dbf full=y job_name=test
JOB_NAME DEFAULT SYS_XXX 例如 作业 "XH"."SYS_EXPORT_TABLE_01"

 

USER_DATAPUMP_JOBS
DBA_DATAPUMP_JOBS
SQL> DESC DBA_DATAPUMP_JOBS;
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 OWNER_NAME                                         VARCHAR2(30)
 JOB_NAME                                           VARCHAR2(30)
 OPERATION                                          VARCHAR2(30)
 JOB_MODE                                           VARCHAR2(30)
 STATE                                              VARCHAR2(30)
 DEGREE                                             NUMBER
 ATTACHED_SESSIONS                                  NUMBER
 DATAPUMP_SESSIONS                                  NUMBER

SQL> select owner_name,operation,job_mode,degree from dba_datapump_jobs where job_n
ame='TEST';

OWNER_NAME
------------------------------
OPERATION
------------------------------------------------------------
JOB_MODE                                                         DEGREE
------------------------------------------------------------ ----------
XH
EXPORT
FULL                                                                  1

 

 

SQL> select count(*) from t1;

  COUNT(*)
----------
         1

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
     797675

SQL> insert into t1 values(2);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select count(*) from t1;

  COUNT(*)
----------
         2

C:\>expdp xh/a123@xh directory=expdpt dumpfile=a1.dbf tables=t1 flashback_scn=79767
5

Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 9:34:55

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "XH"."SYS_EXPORT_TABLE_01":  xh/********@xh directory=expdpt dumpfile=a1.dbf t
ables=t1 flashback_scn=797675
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA

. . 导出了 "XH"."T1"                                   4.921 KB       1 行~~~~~~~~~~可以看

到只导出了1行

 

 

 

 

 


C:\>expdp xh/a123@xh directory=expdpt dumpfile=a4.dbf full=y  parallel=2 job_name=t
est
并行执行
Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 10:19:23

SQL> select program,sid from v$session where username='XH';

PROGRAM                                                                 SID
---------------------------------------------------------------- ----------
expdp.exe                                                               125
ORACLE.EXE (DW02)                                                       131
ORACLE.EXE (DM00)                                                       132
ORACLE.EXE (DW01)                                                       138

SQL> col owner_name format a10
SQL> col operation format a10
SQL> col job_mode format a10
SQL> select owner_name,operation,job_mode,degree,attached_sessions,datapump_session
s from dba_datapump_jobs where job_name='TEST';

OWNER_NAME OPERATION  JOB_MODE       DEGREE ATTACHED_SESSIONS DATAPUMP_SESSIONS
---------- ---------- ---------- ---------- ----------------- -----------------
XH         EXPORT     FULL                2                 1                 4

 

ATTACHED_SESSIONS NUMBER   Number of sessions attached to the job
DATAPUMP_SESSIONS NUMBER   Number of Data Pump sessions participating in the job

 

 

SQL> conn xh/a123
已连接。
SQL> select * from t1;

         A
----------
         2
         1


C:\>expdp xh/a123@xh directory=expdpt dumpfile=a.dbf tables=t1 query='where a=2'

Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 10:40:43

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "XH"."SYS_EXPORT_TABLE_01":  xh/********@xh directory=expdpt dumpfile=a.dbf t
bles=t1 query='where a=2'
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
. . 导出了 "XH"."T1"                                   4.921 KB       1 行~~~~~~~~~只导出了

A=这行
已成功加载/卸载了主表 "XH"."SYS_EXPORT_TABLE_01"
******************************************************************************
XH.SYS_EXPORT_TABLE_01 的转储文件集为:
  D:\EXPDP\A.DBF
作业 "XH"."SYS_EXPORT_TABLE_01" 已于 10:40:57 成功完成

 

C:\>expdp xh/a123@xh directory=expdpt dumpfile=c tablespaces=system status=10
每10S 报告下状态     default 0
Worker 1 状态:
  状态: EXECUTING
. . 导出了 "SYSTEM"."REPCAT$_USER_AUTHORIZATIONS"          0 KB       0 行

作业: SYS_EXPORT_TABLESPACE_01
  操作: EXPORT
  模式: TABLESPACE
  状态: EXECUTING
  处理的字节: 200,552
  完成的百分比: 99
  当前并行度: 1
  作业错误计数: 0
  转储文件: D:\EXPDP\C.DMP
    写入的字节: 471,040

Worker 1 状态:
  状态: EXECUTING
. . 导出了 "SYSTEM"."REPCAT$_USER_PARM_VALUES"             0 KB       0 行

作业: SYS_EXPORT_TABLESPACE_01
  操作: EXPORT
  模式: TABLESPACE
  状态: EXECUTING
  处理的字节: 200,552
  完成的百分比: 99
  当前并行度: 1
  作业错误计数: 0
  转储文件: D:\EXPDP\C.DMP
    写入的字节: 471,040

 

 

 

C:\>expdp xh/a123@xh parfile=d:\test.txt (使用参数文件)

TEXT.TXT中包含  directory=expdpt dumpfile=e tables=t1
Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 11:08:25

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "XH"."SYS_EXPORT_TABLE_01":  xh/********@xh parfile=d:\test.txt
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
. . 导出了 "XH"."T1"                                   4.929 KB       2 行
已成功加载/卸载了主表 "XH"."SYS_EXPORT_TABLE_01"
******************************************************************************
XH.SYS_EXPORT_TABLE_01 的转储文件集为:
  D:\EXPDP\E.DMP
作业 "XH"."SYS_EXPORT_TABLE_01" 已于 11:08:40 成功完成

 

TRANSPORT_FULL_CHECK会检查要移动的表空间的完成关系

If TRANSPORT_FULL_CHECK=y, then Export verifies that there are no dependencies between

those objects inside the transportable set and those outside the transportable set. The

check addresses two-way dependencies. For example, if a table is inside the transportable

set but its index is not, a failure is returned and the export operation is terminated.

Similarly, a failure is also returned if an index is in the transportable set but the table

is not.

If TRANSPORT_FULL_CHECK=n, then Export verifies only that there are no objects within the

transportable set that are dependent on objects outside the transportable set. This check

addresses a one-way dependency. For example, a table is not dependent on an index, but an

index is dependent on a table, because an index without a table has no meaning. Therefore,

if the transportable set contains a table, but not its index, then this check succeeds.

However, if the transportable set contains an index, but not the table, the export

operation is terminated.

In addition to this check, Export always verifies that all storage segments of all tables

(and their indexes) defined within the tablespace set specified by TRANSPORT_TABLESPACES

are actually contained within the tablespace set.

 

简单说就是Y时候检查表空间的完整关系,例如 T表在TABLESPACE A上T表的INDEX 在B上 为Y时
TRANSPORT_TABLESPACE A 将会报错 TRANSPORT_TABLESPACE B时也会报错,N时候 TRANSPORT_TABLESPACE

A不会报错,但 TRANSPORT_TABLESPACE B时将会报错

SQL> create table t1 (a int ,b int)
  2  ;

表已创建。

SQL> create index t1_ind on t1(a) tablespace testxh;

索引已创建。

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

TABLESPACE_NAME
------------------------------
USERS

SQL> select tablespace_name from user_indexes where index_name='T1_IND';

TABLESPACE_NAME
------------------------------
TESTXH
表已创建。
分析可以看见 T1 表与INDEX 在不同的表空间

SQL> alter tablespace users read only;

表空间已更改。
  2  ; 不使用RMAN的话 transport tablespace ,tablespace要readonly
否则报以下错误
ORA-39123: 数据泵可传输的表空间作业中止
ORA-29335: 表空间 'USERS' 不为只读

 

C:\>expdp system/a831115@xh directory=expdpt dumpfile=a.dmp  transport_tablespaces=
USERS  transport_full_check=n~~只搬移TABLE表空间

Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 12:04:59

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@xh directory=expdpt d
umpfile=a.dmp transport_tablespaces=USERS transport_full_check=n
SYSTEM.SYS_EXPORT_TRANSPORTABLE_01 的转储文件集为:
  D:\EXPDP\A.DMP
作业 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" 已经完成, 但是有 1 个错误 (于 12:05:36
完成)

SQL> alter tablespace TESTXH read only
  2  ;

表空间已更改。

C:\>expdp system/a831115@xh directory=expdpt dumpfile=a2.dmp  transport_tablespaces
=testxh  transport_full_check=n~~~~~~~~~~~~~~~~~~~~~只搬移INDEX 表空间报错

Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 12:06:10

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@xh directory=expdpt d
umpfile=a2.dmp transport_tablespaces=testxh transport_full_check=n
ORA-39123: 数据泵可传输的表空间作业中止
ORA-29341: 可传送集不是自包含的

作业 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" 因致命错误于 12:06:16 停止

 

C:\>expdp system/a831115@xh directory=expdpt dumpfile=a2.dmp  transport_tablespaces
=users  transport_full_check=y~~~~~~~~~~~~~~只搬移table表空间

Export: Release 10.2.0.1.0 - Production on 星期二, 22 9月, 2009 12:08:22

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01":  system/********@xh directory=expdpt d
umpfile=a2.dmp transport_tablespaces=users transport_full_check=y
ORA-39123: 数据泵可传输的表空间作业中止
ORA-29341: 可传送集不是自包含的

作业 "SYSTEM"."SYS_EXPORT_TRANSPORTABLE_01" 因致命错误于 12:08:30 停止

 

 

 


具体实验下
C:\>mkdir  d:\expdp

SQL> create directory expdpt as 'd:\expdp';

目录已创建。

导出表 : 可以导出执行导出USER 所拥有的表,如果要导出其它USER的表 需要exp_full_database role

or dba role,另外多表导出时只能导出同一schema中的表

C:\>expdp system/a831115@xh directory=expdpt dumpfile=t11.dmp tables=xh.t1 (导出xh方案中T1

表)

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:06:48

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TABLE_02":  system/********@xh directory=expdpt dumpfile
t11.dmp tables=xh.t1
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
. . 导出了 "XH"."T1"                                   4.921 KB       1 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLE_02"
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_02 的转储文件集为:
  D:\EXPDP\T11.DMP
作业 "SYSTEM"."SYS_EXPORT_TABLE_02" 已于 17:07:03 成功完成


C:\>expdp system/a831115@xh directory=expdpt dumpfile=t2.dmp tables=t2 (导出SYS 方案中,T2

表)

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:10:17

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TABLE_02":  system/********@xh directory=expdpt dumpfile
t2.dmp tables=t2
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
. . 导出了 "SYSTEM"."T2"                               4.921 KB       1 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLE_02"
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_02 的转储文件集为:
  D:\EXPDP\T2.DMP
作业 "SYSTEM"."SYS_EXPORT_TABLE_02" 已于 17:10:29 成功完成

C:\>expdp system/a831115@xh directory=expdpt dumpfile=test.dmp tables=xh.t1,sys.t2(来自两个

不同的SCHEMA不行 )

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:12:11

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
UDE-00012: 表模式导出仅适用于一个方案中的对象

 

导出schema:
USER 可以导出自身schema,导其它SCHEMA要EXp_FULL_DATABASE ROLE OR DBA ROLE

C:\>expdp system/a831115@xh directory=expdpt dumpfile=test.dmp schemas=xh,sys

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:19:17

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_SCHEMA_02":  system/********@xh directory=expdpt dumpfile
=test.dmp schemas=xh,sys
正在使用 BLOCKS 方法进行估计...
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE_DATA
使用 BLOCKS 方法的总估计: 64 KB
处理对象类型 SCHEMA_EXPORT/USER
处理对象类型 SCHEMA_EXPORT/SYSTEM_GRANT
处理对象类型 SCHEMA_EXPORT/ROLE_GRANT
处理对象类型 SCHEMA_EXPORT/DEFAULT_ROLE
......................................
. . 导出了 "XH"."T1"                                   4.921 KB       1 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_SCHEMA_02"
******************************************************************************
SYSTEM.SYS_EXPORT_SCHEMA_02 的转储文件集为:
  D:\EXPDP\TEST.DMP
作业 "SYSTEM"."SYS_EXPORT_SCHEMA_02" 已于 17:20:04 成功完成


导出tablespace
要求exp_full_database or dba role
C:\>expdp system/a831115@xh directory=expdpt dumpfile=test2.dmp tablespaces=users,
ysaux

Export: Release 10.2.0.1.0 - Production on 星期一, 21 9月, 2009 17:21:37

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

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
启动 "SYSTEM"."SYS_EXPORT_TABLESPACE_01":  system/********@xh directory=expdpt dum
file=test2.dmp tablespaces=users,sysaux
正在使用 BLOCKS 方法进行估计...
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
ORA-39139: 数据泵不支持 XMLSchema 对象。将跳过 TABLE_DATA:"OE"."PURCHASEORDER"。
使用 BLOCKS 方法的总估计: 17.25 MB
处理对象类型 TABLE_EXPORT/TABLE/TABLE
处理对象类型 TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX
.................
 . 导出了 "SYSMAN"."MGMT_CREDENTIAL_TYPES"            6.789 KB       4 行
 . 导出了 "SYSMAN"."MGMT_CREDENTIAL_TYPE_COLUMNS"     8.132 KB       8 行
 . 导出了 "SYSMAN"."MGMT_CREDENTIAL_TYPE_REF"         7.179 KB       1 行
..................
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLESPACE_01"
******************************************************************************
SYSTEM.SYS_EXPORT_TABLESPACE_01 的转储文件集为:
  D:\EXPDP\TEST2.DMP
作业 "SYSTEM"."SYS_EXPORT_TABLESPACE_01" 已经完成, 但是有 1 个错误 (于 17:23:45 完
成)

 

导出DB 要exp_full_database or dba role
*********************SYS方案 不会导出
C:\>expdp system/a831115@xh directory=expdpt dumpfile=test3.dmp full=y;
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_FULL_01"
******************************************************************************

 

IMPDP 导入


C:\>impdp xh/a123@xh help=y  查看帮助

Import: Release 10.2.0.1.0 - Production on 星期三, 23 9月, 2009 10:00:19

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


数据泵导入实用程序提供了一种用于在 Oracle 数据库之间传输
数据对象的机制。该实用程序可以使用以下命令进行调用:

     示例: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

您可以控制导入的运行方式。具体方法是: 在 'impdp' 命令后输入
各种参数。要指定各参数, 请使用关键字:

     格式:  impdp KEYWORD=value 或 KEYWORD=(value1,value2,...,valueN)
     示例: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

USERID 必须是命令行中的第一个参数。

关键字               说明 (默认)
------------------------------------------------------------------------------
ATTACH                连接到现有作业, 例如 ATTACH [=作业名]。
CONTENT               指定要加载的数据, 其中有效关键字为:
                      (ALL), DATA_ONLY 和 METADATA_ONLY。
DIRECTORY             供转储文件, 日志文件和 sql 文件使用的目录对象。
DUMPFILE              要从 (expdat.dmp) 中导入的转储文件的列表,
                      例如 DUMPFILE=scott1.dmp, scott2.dmp, dmpdir:scott3.dmp。
ENCRYPTION_PASSWORD   用于访问加密列数据的口令关键字。
                      此参数对网络导入作业无效。
ESTIMATE              计算作业估计值, 其中有效关键字为:
                      (BLOCKS) 和 STATISTICS。
EXCLUDE               排除特定的对象类型, 例如 EXCLUDE=TABLE:EMP。
FLASHBACK_SCN         用于将会话快照设置回以前状态的 SCN。
FLASHBACK_TIME        用于获取最接近指定时间的 SCN 的时间。
FULL                  从源导入全部对象 (Y)。
HELP                  显示帮助消息 (N)。
INCLUDE               包括特定的对象类型, 例如 INCLUDE=TABLE_DATA。
JOB_NAME              要创建的导入作业的名称。
LOGFILE               日志文件名 (import.log)。
NETWORK_LINK          链接到源系统的远程数据库的名称。
NOLOGFILE             不写入日志文件。
PARALLEL              更改当前作业的活动 worker 的数目。
PARFILE               指定参数文件。
QUERY                 用于导入表的子集的谓词子句。
REMAP_DATAFILE        在所有 DDL 语句中重新定义数据文件引用。
REMAP_SCHEMA          将一个方案中的对象加载到另一个方案。
REMAP_TABLESPACE      将表空间对象重新映射到另一个表空间。
REUSE_DATAFILES       如果表空间已存在, 则将其初始化 (N)。
SCHEMAS               要导入的方案的列表。
SKIP_UNUSABLE_INDEXES 跳过设置为无用索引状态的索引。
SQLFILE               将所有的 SQL DDL 写入指定的文件。
STATUS                在默认值 (0) 将显示可用时的新状态的情况下,
                      要监视的频率 (以秒计) 作业状态。
STREAMS_CONFIGURATION 启用流元数据的加载
TABLE_EXISTS_ACTION   导入对象已存在时执行的操作。
                      有效关键字: (SKIP), APPEND, REPLACE 和 TRUNCATE。
TABLES                标识要导入的表的列表。
TABLESPACES           标识要导入的表空间的列表。
TRANSFORM             要应用于适用对象的元数据转换。
                      有效的转换关键字: SEGMENT_ATTRIBUTES, STORAGE
                      OID 和 PCTSPACE。
TRANSPORT_DATAFILES   按可传输模式导入的数据文件的列表。
TRANSPORT_FULL_CHECK  验证所有表的存储段 (N)。
TRANSPORT_TABLESPACES 要从中加载元数据的表空间的列表。
                      仅在 NETWORK_LINK 模式导入操作中有效。
VERSION               要导出的对象的版本, 其中有效关键字为:
                      (COMPATIBLE), LATEST 或任何有效的数据库版本。
                      仅对 NETWORK_LINK 和 SQLFILE 有效。

下列命令在交互模式下有效。
注: 允许使用缩写

命令               说明 (默认)
------------------------------------------------------------------------------
CONTINUE_CLIENT       返回到记录模式。如果处于空闲状态, 将重新启动作业。
EXIT_CLIENT           退出客户机会话并使作业处于运行状态。
HELP                  总结交互命令。
KILL_JOB              分离和删除作业。
PARALLEL              更改当前作业的活动 worker 的数目。
                      PARALLEL=。
START_JOB             启动/恢复当前作业。
                      START_JOB=SKIP_CURRENT 在开始作业之前将跳过
                      作业停止时执行的任意操作。
STATUS                在默认值 (0) 将显示可用时的新状态的情况下,
                      要监视的频率 (以秒计) 作业状态。
                      STATUS[=interval]
STOP_JOB              顺序关闭执行的作业并退出客户机。
                      STOP_JOB=IMMEDIATE 将立即关闭
                      数据泵作业。


简单使用下几个参数

 

REMAP_SCHEMA          将一个方案中的对象加载到另一个方案。
SQL> conn xh/a123
已连接。
SQL> select count(*) from t1;

  COUNT(*)
----------
         1

SQL> conn zz/a123
已连接。
SQL> select count(*) from t1;
select count(*) from t1
                     *
第 1 行出现错误:
ORA-00942: 表或视图不存在


C:\>expdp system/a831115@xh directory=expdpt dumpfile=t1.dmp tables=xh.t1

. . 导出了 "XH"."T1"                                   5.242 KB       1 行
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_TABLE_02"


C:\>impdp system/a831115@xh directory=expdpt dumpfile=t1.dmp tables=xh.t1 remap_sch
ema=xh:zz


处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "ZZ"."T1"                                   5.242 KB       1 行

SQL> conn xh/a123@xh
已连接。
SQL> select count(*) from t1;

  COUNT(*)
----------
         1

SQL> conn zz/a123
已连接。
SQL> select count(*) from t1;

  COUNT(*)
----------
         1

TABLE_EXISTS_ACTION   导入对象已存在时执行的操作。
                      有效关键字: (SKIP), APPEND, REPLACE 和 TRUNCATE。


SQL> conn zz/a123
已连接。
SQL> select count(*) from t1;

  COUNT(*)
----------
         1

SQL> insert into t1 values(1,2);

已创建 1 行。

SQL> commit;

提交完成。

SQL> select count(*) from t1;

  COUNT(*)
----------
         2
C:\>impdp system/a831115@xh directory=expdpt dumpfile=t1.dmp  remap_schema=xh:zz
APPEND 追加
default skip  当发现存在时候 跳过处理下一个对象
处理对象类型 TABLE_EXPORT/TABLE/TABLE
ORA-39151: 表 "ZZ"."T1" 已存在。由于跳过了 table_exists_action, 将跳过所有相关元数
据和数据。

C:\>impdp system/a831115@xh directory=expdpt dumpfile=t1.dmp  remap_schema=xh:zz ta
ble_exists_action=append

ORA-39152: 表 "ZZ"."T1" 已存在。由于附加了 table_exists_action, 数据将附加到现有表,
 但是将跳过所有相关元数据。
处理对象类型 TABLE_EXPORT/TABLE/TABLE_DATA
. . 导入了 "ZZ"."T1"                                   5.242 KB       1 行
处理对象类型 TABLE_EXPORT/TABLE/INDEX/INDEX

SQL> select count(*) from t1;(schema zz)

  COUNT(*)
----------
         3

C:\>impdp system/a831115@xh directory=expdpt dumpfile=t1.dmp  remap_schema=xh:zz ta
ble_exists_action=truncate
truncate已存在表 然后为其追加数据
SQL> select count(*) from t1;(schema zz)

  COUNT(*)
----------
         1

 


TRANSFORM             要应用于适用对象的元数据转换。
参数使用都可以在DOC中找到使用方法

来自 ORACLE DOC

http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/dp_import.htm#sthref375
TRANSFORM. = transform_name:value[:object_type]

The transform_name specifies the name of the transform. The possible options are as

follows:

SEGMENT_ATTRIBUTES - If the value is specified as y, then segment attributes (physical

attributes, storage attributes, tablespaces, and logging) are included, with appropriate

DDL. The default is y.

STORAGE - If the value is specified as y, the storage clauses are included, with

appropriate DDL. The default is y. This parameter is ignored if SEGMENT_ATTRIBUTES=n.

OID - If the value is specified as n, the assignment of the exported OID during the

creation of object tables and types is inhibited. Instead, a new OID is assigned. This can

be useful for cloning schemas, but does not affect referenced objects. The default value is

y.

PCTSPACE - The value supplied for this transform. must be a number greater than zero. It

represents the percentage multiplier used to alter extent allocations and the size of data

files.

Note that you can use the PCTSPACE transform. in conjunction with the Data Pump Export

SAMPLE parameter so that the size of storage allocations matches the sampled data subset.


Example

For the following example, assume that you have exported the employees table in the hr

schema. The SQL CREATE TABLE statement that results when you then import the table is

similar to the following:

CREATE TABLE "HR"."EMPLOYEES"
   ( "EMPLOYEE_ID" NUMBER(6,0),
     "FIRST_NAME" VARCHAR2(20),
     "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE,
     "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE,
     "PHONE_NUMBER" VARCHAR2(20),
     "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE,
     "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE,
     "SALARY" NUMBER(8,2),
     "COMMISSION_PCT" NUMBER(2,2),
     "MANAGER_ID" NUMBER(6,0),
     "DEPARTMENT_ID" NUMBER(4,0)
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 10240 NEXT 16384 MINEXTENTS 1 MAXEXTENTS 121
  PCTINCREASE 50 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "SYSTEM" ;

If you do not want to retain the STORAGE clause or TABLESPACE clause, you can remove them

from the CREATE STATEMENT by using the Import TRANSFORM. parameter. Specify the value of

SEGMENT_ATTRIBUTES as n. This results in the exclusion of segment attributes (both storage

and tablespace) from the table.

> impdp hr/hr TABLES=hr.employees \
  DIRECTORY=dpump_dir1 DUMPFILE=hr_emp.dmp \
  TRANSFORM=SEGMENT_ATTRIBUTES:n:table

The resulting CREATE TABLE statement for the employees table would then look similar to the

following. It does not contain a STORAGE or TABLESPACE clause; the attributes for the

default tablespace for the HR schema will be used instead.

CREATE TABLE "HR"."EMPLOYEES"
   ( "EMPLOYEE_ID" NUMBER(6,0),
     "FIRST_NAME" VARCHAR2(20),
     "LAST_NAME" VARCHAR2(25) CONSTRAINT "EMP_LAST_NAME_NN" NOT NULL ENABLE,
     "EMAIL" VARCHAR2(25) CONSTRAINT "EMP_EMAIL_NN" NOT NULL ENABLE,
     "PHONE_NUMBER" VARCHAR2(20),
     "HIRE_DATE" DATE CONSTRAINT "EMP_HIRE_DATE_NN" NOT NULL ENABLE,
     "JOB_ID" VARCHAR2(10) CONSTRAINT "EMP_JOB_NN" NOT NULL ENABLE,
     "SALARY" NUMBER(8,2),
     "COMMISSION_PCT" NUMBER(2,2),
     "MANAGER_ID" NUMBER(6,0),
     "DEPARTMENT_ID" NUMBER(4,0)
   );

As shown in the previous example, the SEGMENT_ATTRIBUTES transform. applies to both storage

and tablespace attributes. To omit only the STORAGE clause and retain the TABLESPACE

clause, you can use the STORAGE transform, as follows:

> impdp hr/hr TABLES=hr.employees \
  DIRECTORY=dpump_dir1 DUMPFILE=hr_emp.dmp \
  TRANSFORM=STORAGE:n:table

The SEGMENT_ATTRIBUTES and STORAGE transforms can be applied to all applicable table and

index objects by not specifying the object type on the TRANSFORM. parameter, as shown in the

following command:

> impdp hr/hr DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp \
 SCHEMAS=hr TRANSFORM=SEGMENT_ATTRIBUTES:n

 

简单使用IMPDP

导入表
SQL> conn xh/a123
已连接。
SQL> select count(*) from t1;

  COUNT(*)
----------
         1

 

SQL> drop table t1;

表已删除。
C:\>impdp system/a831115@xh directory=expdpt dumpfile=t1.dmp  tables=t1

SQL> select count(*) from t1;

  COUNT(*)
----------
         1


导入schema
SQL> conn zz/a123
已连接。
SQL> select count(*) from user_tables;

  COUNT(*)
----------
         0

SQL> conn xh/a123
已连接。
SQL> select count(*) from user_tables;

  COUNT(*)
----------
         3

C:\>expdp  system/a831115@xh directory=expdpt dumpfile=b.dmp schemas=xh
. . 导出了 "XH"."T1"                                   5.242 KB       1 行
. . 导出了 "XH"."T2"                                       0 KB       0 行
. . 导出了 "XH"."T3"                                       0 KB       0 行

SQL> drop user xh cascade;

用户已删除。


C:\>impdp  system/a831115@xh directory=expdpt dumpfile=b.dmp schemas=xh
. . 导入了 "XH"."T1"                                   5.242 KB       1 行
. . 导入了 "XH"."T2"                                       0 KB       0 行
. . 导入了 "XH"."T3"                                       0 KB       0 行

SQL> conn xh/a123
已连接。
SQL> select count(*) from user_tables;

  COUNT(*)
----------
         3
C:\>impdp  system/a831115@xh directory=expdpt dumpfile=b.dmp schemas=xh  remap_sche
ma=xh:zz
. . 导入了 "ZZ"."T1"                                   5.242 KB       1 行
. . 导入了 "ZZ"."T2"                                       0 KB       0 行
. . 导入了 "ZZ"."T3"                                       0 KB       0 行

SQL> conn zz/a123
已连接。
SQL> select count(*) from user_tables;

  COUNT(*)
----------
         3


导入tablespace

SQL> create table t4 (a int)tablespace testxh;

表已创建。

C:\>expdp  system/a831115@xh directory=expdpt dumpfile=c.dmp tablespaces=testxh

. . 导出了 "ZZ"."T4"                                       0 KB       0 行
SQL> drop table t4
  2  ;

表已删除。

SQL> select * from t4;
select * from t4
              *
第 1 行出现错误:
ORA-00942: 表或视图不存在
C:\>impdp  system/a831115@xh directory=expdpt dumpfile=c.dmp tablespaces=testxh
. . 导入了 "ZZ"."T4"                                       0 KB       0 行

SQL> select * from t4;

未选定行


SQL> conn zz/a123
已连接。
SQL> select * from t4;

未选定行

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

TABLESPACE_NAME
------------------------------
TESTXH

SQL> drop table t4;

表已删除。

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

未选定行
C:\>impdp  system/a831115@xh directory=expdpt dumpfile=c.dmp tablespaces=testxh  re  导入其

他tablespace
map_tablespace=testxh:users

 

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

TABLESPACE_NAME
------------------------------
USERS

 

导入database

 

C:\>expdp  system/a831115@xh directory=expdpt dumpfile=d.dmp full=y


SQL> drop tablespace testxh including contents;

表空间已删除。

SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
RMAN_TS

已选择7行。
C:\>impdp  system/a831115@xh directory=expdpt dumpfile=d.dmp full=y  reuse_datafile
s=y
此时如果 datafile还存在那么执行 create tablespace testxh时候回报错误(文件已经存在)使用

reuse_datafiles=y

SQL> select tablespace_name from dba_tablespaces;

TABLESPACE_NAME
------------------------------
SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS
EXAMPLE
RMAN_TS
TESTXH

已选择8行。

 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12020513/viewspace-615383/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/12020513/viewspace-615383/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值