目录
一、数据泵的操作准备
1.1、创建数据泵目录
1.2、给该目录赋权
1.3、查看创建的目录细节
1.4、简单例子
二、数据泵的基本使用
2.1、使用参数文件
2.2、全数据库导出
2.3、schema级别导出
2.4、表空间级别
2.5、表级别
2.6、直接通过网络执行导出或导入操作

三、数据泵得其它用法
3.1、估算导出的作业
3.2、列出数据泵文件备份中的内容
3.3、克隆用户
3.4、创建一致性导出文件
3.5、在对象已经存在的情况下执行导入操作
3.6、重命名表
3.7、重用导出的文件名
3.8、数据库得并行操作

四、数据泵交互模式
4.1、说明
4.2、进入交互模式
4.3、交互状态操作
4.4、监控数据库作业

五、数据泵过滤
5.1、过滤说明
5.2、设置query参数
5.3、按百分比导出数据
5.4、从导出文件中排除对象
5.5、在导出文件中包含指定对象
5.6、从导入文件中排除对象
5.7、在导入中仅包含对象
5.8、导出表、索引、约束和触发器的ddl

六、数据泵跟踪
6.1、跟踪说明
6.2、跟踪方式
6.3、找到跟踪文件

一、数据泵的操作准备
1、创建数据泵目录
sql>create directory dump as '/backup';

1.2、给该目录赋权
sql>grant read,write on directory dump to system;

1.3、查看创建的目录细节
sql>select owner,directory_name,directory_path from dba_directory;

1.4、例子
导出schema所有对象
expdp system/[email protected]:1521/ERP dumpfile=1.dump directory=dump schemas=BFAPP10

二、数据泵的基本使用
2.1、使用参数文件
1、创建参数文件
vi exp.par
userid=system/DHHZDHHZ
directory=dump
dumpfile=exp.dump
reuse_dumpfiles=y
2、调用参数文件
expdp parfile=exp.par

2.2、全数据库导出
1、全库导出说明
全库导出时需加full=y
导出整个数据库称为全库导出,生成的导出文件含有重建数据库的所有必须信息。
全库导出信息由下列部分组成,用于重建表空间、用户、表、索引、约束、触发器、序列、已存储pl/sql脚本等元素的所有ddl代码
全库导出不会导出数据库中的所有元素、sys方案中的对象不会导出
2、全库导入操作需要注意以下几点
全库导入时需加full=y
导入作业会首先重建所有表空间、如果表空间已经存在,或表空间依存的目录路径不存在,那么创建表空间操作就会失败。
导入作业会更改sys和system用户账户,使它们包含导出的密码
导入作业会创建导出文件中的所有用户,如果某个用户已经存在,会又错误提示,并运行下一个任务
重建表,如果表中已经存在并含有数据,则必须设置TABLE_EXSITS_ACTION,CONTENT
创建相关索引
处理统计数据
3、全库导出操作:

     expdp system/DHHZDHHZ directory=dump dumpfile=full.dump full=y

4、全库导入操作:

      impdp system/DHHZDHHZ directory=dump dumpfile=full.dump full=y

2.3、schema级别导出
1、说明
方案级别导出文件中不包含表空间
创建表并加载数据,如果表已经存在,需要使用table_exists_action处理
2、语法
schemas=BFCRM8,BFAPP8.....

3、语句如下:
    expdp system/DHHZDHHZ directory=dump dumpfile=today.dump schemas=BFCRM,BFAPP8

2.4、表空间级别
1、说明
表空间级别的导出和导入作业可以操作特定表空间中的对象
表空间导入会创建表空间中的所有表和索引
该导入操作不会自动创建表空间
2、导出语句
expdp system/DHHZDHHZ directory=dump dumpfile=tbs.dump tablespaces=JXC
3、导出过程
[oracle@destogg ~]$ export ORACLE_SID=erp
[oracle@destogg ~]$ expdp system/DHHZDHHZ directory=dump dumpfile=tbs.dump tablespaces=JXC

Export: Release 11.2.0.4.0 - Production on Thu Nov 29 20:53:13 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLESPACE_01": system/**** directory=dump dumpfile=tbs.dump tablespaces=JXC
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 623.1 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
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/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFCRM1"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFPUB"."PUBT1" 39.74 MB 3000000 rows
. . exported "BFPUB"."PUBT2" 39.11 MB 2953000 rows
. . exported "BFCRM"."CRMT2" 6.095 MB 400000 rows
. . exported "BFCRM"."SCOTT.SCOCRMT2" 6.095 MB 400000 rows
. . exported "BFCRM1"."CRMT2" 6.095 MB 400000 rows
. . exported "SCOTT"."CRMT2" 6.095 MB 400000 rows
. . exported "BFCW"."CWT2" 4.950 MB 400000 rows
. . exported "BFBHDD"."BHDDT2" 2.056 MB 144150 rows
. . exported "ZX01"."TZX01" 873.0 KB 100000 rows
. . exported "ZX02"."TZX02" 5.421 KB 1 rows
. . exported "BFBHDD"."BHDDT1" 1.425 MB 100001 rows
. . exported "BFCW"."CWT1" 1.234 MB 100000 rows
. . exported "JJ"."T1" 873.0 KB 100000 rows
. . exported "JJ"."T2" 873.0 KB 100000 rows
. . exported "JJ"."T3" 873.0 KB 100000 rows
. . exported "ZX03"."EZX03" 697.4 KB 80000 rows
. . exported "ZX02"."EZX02" 521.8 KB 60000 rows
. . exported "ZX01"."EZX01" 82.94 KB 10001 rows
. . exported "ZX"."TEST" 12.75 KB 1004 rows
. . exported "ZX01"."T" 5.031 KB 3 rows
. . exported "ZX01"."T2" 0 KB 0 rows
. . exported "ZX01"."T3" 0 KB 0 rows
. . exported "ZX01"."T4" 0 KB 0 rows
. . exported "ZX01"."T5" 0 KB 0 rows
. . exported "ZX03"."TZX03" 0 KB 0 rows
Master table "SYSTEM"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded


4、导入语句
impdp system/DHHZDHHZ directory=dump dumpfile=tbs.dump tablespaces=JXC
5、导入过程
[oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump dumpfile=tbs.dump tablespaces=JXC

Import: Release 11.2.0.4.0 - Production on Thu Nov 29 21:09:35 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLESPACE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLESPACE_01": system/**** directory=dump dumpfile=tbs.dump tablespaces=JXC
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFCRM1"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFPUB"."PUBT1" 39.74 MB 3000000 rows
. . imported "BFPUB"."PUBT2" 39.11 MB 2953000 rows
. . imported "BFCRM"."CRMT2" 6.095 MB 400000 rows
. . imported "BFCRM"."SCOTT.SCOCRMT2" 6.095 MB 400000 rows
. . imported "BFCRM1"."CRMT2" 6.095 MB 400000 rows
. . imported "SCOTT"."CRMT2" 6.095 MB 400000 rows
. . imported "BFCW"."CWT2" 4.950 MB 400000 rows
. . imported "BFBHDD"."BHDDT2" 2.056 MB 144150 rows
. . imported "ZX01"."TZX01" 873.0 KB 100000 rows
. . imported "ZX02"."TZX02" 5.421 KB 1 rows
. . imported "BFBHDD"."BHDDT1" 1.425 MB 100001 rows
. . imported "BFCW"."CWT1" 1.234 MB 100000 rows
. . imported "JJ"."T1" 873.0 KB 100000 rows
. . imported "JJ"."T2" 873.0 KB 100000 rows
. . imported "JJ"."T3" 873.0 KB 100000 rows
. . imported "ZX03"."EZX03" 697.4 KB 80000 rows
. . imported "ZX02"."EZX02" 521.8 KB 60000 rows
. . imported "ZX01"."EZX01" 82.94 KB 10001 rows
. . imported "ZX"."TEST" 12.75 KB 1004 rows
. . imported "ZX01"."T" 5.031 KB 3 rows
. . imported "ZX01"."T2" 0 KB 0 rows
. . imported "ZX01"."T3" 0 KB 0 rows
. . imported "ZX01"."T4" 0 KB 0 rows
. . imported "ZX01"."T5" 0 KB 0 rows
. . imported "ZX03"."TZX03" 0 KB 0 rows
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLESPACE_01" successfully completed at Thu Nov 29 21:10:41 2018 elapsed 0 00:01:00
2.5、表级别
1、说明
tables参数使数据泵操作特定的表
从全库备份或者方案级别的导出文件中,可以加参数tables只导入指定的表
2、操作过程如下
[oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump dumpfile=full.dump tables=BFCRM.CRMT1,BFCRM.CRMT2

Import: Release 11.2.0.4.0 - Production on Thu Nov 29 18:35:13 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01": system/**** directory=dump dumpfile=full.dump tables=BFCRM.CRMT1,BFCRM.CRMT2
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFCRM"."CRMT2" 6.095 MB 400000 rows
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/INDEX
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/CONSTRAINT/CONSTRAINT
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at Thu Nov 29 18:35:57 2018 elapsed 0 00:00:43

[oracle@destogg backup]$ impdp system/DHHZDHHZ directory=dump dumpfile=20181202.dump tables=BFCRM.CRMT1

Import: Release 11.2.0.4.0 - Production on Sun Dec 2 21:40:56 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
UDI-00010: multiple job modes requested, schema and tables.

[oracle@destogg backup]$ impdp system/DHHZDHHZ directory=dump dumpfile=20181202.dump tables=BFCRM.CRMT1

Import: Release 11.2.0.4.0 - Production on Sun Dec 2 21:46:13 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01": system/**** directory=dump dumpfile=20181202.dump tables=BFCRM.CRMT1
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at Sun Dec 2 21:46:34 2018 elapsed 0 00:00:20

2.6、直接通过网络执行导出和导入操作
1、说明
只要源数据库和目标数据库经过网络连接就可以用此方法
不受源数据库和目标数据库的os类型影响。
使用此方式可以避免通过网络拷贝数据泵导出的文件
可以在导入的过程中可以使用重命名方案

 2、远程导入

     若要重命名用户,则需在测试数据库中创建新用户
       在本地测试数据库中创建公共数据库链接并测试是否能访问对端数据
      在本地创建指向远程数据库的链接。

SQL> create public database link dk connect to system identified by DHHZDHHZ using '192.168.5.11/erp';

Database link created.

SQL> select * from BFCRM.CRMT1@dk where rownum<=2;

 M L

  1046 crm1
  1047 crm1

  在本地测试数据库中创建数据泵目录
   create directory dump as '/backup';
   grant read,write on directory dump to system;

  在本地执行导入操作
  impdp system/DHHZDHHZ directory=dump network_link=dk schemas=BFCRM
  导入过程如下:
  [oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump network_link=dk schemas=BFCRM

Import: Release 11.2.0.4.0 - Production on Thu Nov 29 22:23:48 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/**** directory=dump network_link=dk schemas=BFCRM
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 248 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
. . imported "BFCRM"."CRMT1" 12500000 rows
. . imported "BFCRM"."CRMT2" 400000 rows
. . imported "BFCRM"."SCOTT.SCOCRMT2" 400000 rows
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Thu Nov 29 22:24:28 2018 elapsed 0 00:00:39
3、远程数据库导出数据泵备份到本地
在本地执行如下语句
expdp system/[email protected]/SG directory=dump dumpfile=script.DUMP schemas=BFCRM10 network_link=dk

说明
system/[email protected]/SG 为本地库
dk创建的链接指向远程

[oracle@destogg ~]$ expdp \' / as sysdba \' directory=dump network_link=dk schemas='BFCRM' dumpfile=20181129nt.dump;

Export: Release 11.2.0.4.0 - Production on Thu Nov 29 22:34:55 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_SCHEMA_01": "/**** AS SYSDBA" directory=dump network_link=dk schemas=BFCRM dumpfile=20181129nt.dump
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 248 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFCRM"."CRMT2" 6.095 MB 400000 rows
. . exported "BFCRM"."SCOTT.SCOCRMT2" 6.095 MB 400000 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
/backup/20181129nt.dump
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Thu Nov 29 22:35:13 2018 elapsed 0 00:00:18

[oracle@destogg ~]$ ls -l /backup/
total 1973900
-rw-r----- 1 oracle oinstall 672464896 Sep 6 14:03 1-20180906-0btced9a_1_1.dat
-rw-r----- 1 oracle oinstall 10059776 Sep 6 14:03 1-20180906-0ctced9p_1_1.dat
-rw-r----- 1 oracle oinstall 207368192 Nov 29 22:35 20181129nt.dump
-rw-r--r-- 1 oracle oinstall 1692 Nov 29 22:35 export.log
-rw-r----- 1 oracle oinstall 618946560 Nov 29 18:18 full.dump
-rw-r--r-- 1 oracle oinstall 1414 Nov 29 22:24 import.log
-rw-r----- 1 oracle oinstall 512425984 Nov 29 20:58 tbs.dump

三、数据泵得其它用法
3.1、估算导出的作业
1、使用参数说明
estimate_only=y

2、操作过程如下:
 expdp system/DHHZDHHZ estimate_only=y directory=dump  schemas=BFCRM
 [oracle@destogg ~]$  expdp system/DHHZDHHZ estimate_only=y schemas=BFCRM

                     Export: Release 11.2.0.4.0 - Production on Mon Nov 26 17:50:23 2018
                     Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
                     Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
                     With the Partitioning, OLAP, Data Mining and Real Application Testing options
                     Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01":  system/******** estimate_only=y schemas=BFCRM 
                     Estimate in progress using BLOCKS method...
                     Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
                          .  estimated "BFCRM"."CRMT1"                               232 MB
                          .  estimated "BFCRM"."CRMT2"                                 8 MB
                    Total estimation using BLOCKS method: 240 MB
                    Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Nov 26 17:50:25 2018 elapsed 0 00:00:01

3.2、列出数据泵文件备份中的内容
1、使用sqlfile参数时的说明
使用数据泵的SQLFILE选项,可以导入数据泵导出文件的内容列表
语法为SQLFILE=目录:sql结尾的文件 不指定目录,默认sql文件存在于directory目录
在导入操作使用SQLFILE选项时,impdp进程不会导入任何数据,它仅会创建含有导入进程运行的sql命令文件
2、语法为
impdp system/DHHZDHHZ directory=dump dumpfile=today.dump sqlfile=dump:exp.sql
3、执行过程
impdp system/DHHZDHHZ directory=dump dumpfile=2018.DUMP sqlfile=1.sql

Import: Release 11.2.0.4.0 - Production on 星期日 12月 2 22:15:58 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表 "SYSTEM"."SYS_SQL_FILE_SCHEMA_01"
启动 "SYSTEM"."SYS_SQL_FILE_SCHEMA_01": system/**** directory=dump dumpfile=2018.DUMP sqlfile=1.sql

处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
作业 "SYSTEM"."SYS_SQL_FILE_SCHEMA_01" 已于 星期日 12月 2 22:16:14 2018 elapsed 0 00:00:13 成功完成

4、生成sql的内容如下:
-- CONNECT SYSTEM
ALTER SESSION SET EVENTS '10150 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10904 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '25475 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10407 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '10851 TRACE NAME CONTEXT FOREVER, LEVEL 1';
ALTER SESSION SET EVENTS '22830 TRACE NAME CONTEXT FOREVER, LEVEL 192 ';
-- new object type path: SCHEMA_EXPORT/TABLE/TABLE
CREATE TABLE "BFPUB10"."BFBBDEFINE"
( "MSG_ID" NUMBER(10,0) NOT NULL ENABLE,
"RPTNAME" VARCHAR2(40 BYTE),
"URL" VARCHAR2(100 BYTE)
) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
TABLESPACE "JXC" ;

3.3、克隆用户
1、语法
remap_schema=schema1:schema2
2、执行语句
impdp system/DHHZDHHZ directory=dump remap_schema=BFCRM:BFCRM1 dumpfile=today.dump
3、执行过程和结果
oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump remap_schema=BFCRM:BFCRM1 dumpfile=today.dump

Import: Release 11.2.0.4.0 - Production on Wed Nov 28 17:38:02 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/**** directory=dump remap_schema=BFCRM:BFCRM1 dumpfile=today.dump
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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 "BFCRM1"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFCRM1"."CRMT2" 6.095 MB 400000 rows
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Wed Nov 28 17:39:25 2018 elapsed 0 00:01:22

SQL> select username from dba_users where default_tablespace='JXC';

USERNAME

BFPUB
BFCW
ZX01
ZX
JJ
BFCRM
BFBHDD
BFCRM1
ZX02
ZX03

10 rows selected.

3.4、创建一致性导出文件

1、语法

flashback_scn获取方式如下:

SQL> select current_scn from v$database;

CURRENT_SCN

3091099 
flashback_time 获取方式如下:
flashback_time="to_timestamp{}"
由scn转换为timestamp

SQL> select to_char(scn_to_timestamp(3091099),'yyyy-mm-dd hh24:mi:ss') timestamp from dual;

TIMESTAMP

2018-11-28 17:45:28
参数文件中输入如下:
directory=dump
dumpfile=new.dump
schemas=BFCRM
flashback_time="to_timestamp('2018-11-28 17:45:28','yyyy-mm-dd hh24:mi:ss')"
命令行中输入如下:
2、执行语句

expdp system/DHHZDHHZ directory=dump schemas=BFCRM1 flashback_scn=3091099

3、参数文件执行过程如下:
[oracle@destogg ~]$ expdp system/DHHZDHHZ parfile=1par reuse_dumpfiles=y

Export: Release 11.2.0.4.0 - Production on Wed Nov 28 22:49:00 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** parfile=1par reuse_dumpfiles=y
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 240 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFCRM"."CRMT2" 6.095 MB 400000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/new.dump
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Nov 28 22:49:32 2018 elapsed 0 00:00:31

4、命令行执行过程如下:

expdp system/DHHZDHHZ directory=dump dumpfile=today2.dump schemas=BFCRM flashback_time=\"to_timestamp(\'2018-11-28 17:45:28\',\'yyyy-mm-dd hh24:mi:ss\')\"
[oracle@destogg ~]$ expdp system/DHHZDHHZ directory=dump dumpfile=today2.dump schemas=BFCRM flashback_time=\"to_timestamp(\'2018-11-28 17:45:28\',\'yyyy-mm-dd hh24:mi:ss\')\"

Export: Release 11.2.0.4.0 - Production on Wed Nov 28 22:57:56 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** directory=dump dumpfile=today2.dump schemas=BFCRM flashback_time="to_timestamp('2018-11-28 17:45:28','yyyy-mm-dd hh24:mi:ss')"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 240 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFCRM"."CRMT2" 6.095 MB 400000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/today2.dump
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Nov 28 22:58:06 2018 elapsed 0 00:00:10

3.5、在对象已经存在的情况下执行导入操作

1、参数说明
table_exists_action
skip (不使用content=data_only参数情况下的默认值)不处理已经存在的对象,
append (使用content=data_only参数情况下的默认值) 不删除已经存在的数据向表中附加数据
replace 删除已经存在的对象并重建它们 和content=data_only冲突
truncate 截断表中的数据
content
all 默认值既加载数据泵文件中的数据,也加载数据泵文件中的元数据即创建表等对象
data_only 仅仅向已经存在的表附加数据,不创建数据库对象
metadata_only 可以使数据泵仅创建对象,不加载数据。
2、例子
没有加table_exists_action content=data_only 执行过程如下:
[oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump dumpfile=20181129.dump tables=BFCRM.CRMT2

Import: Release 11.2.0.4.0 - Production on Thu Nov 29 16:15:12 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01": system/**** directory=dump dumpfile=20181129.dump tables=BFCRM.CRMT2
Processing object type SCHEMA_EXPORT/TABLE/TABLE
ORA-39151: Table "BFCRM"."CRMT2" exists. All dependent metadata and data will be skipped due to table_exists_action of skip
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_TABLE_01" completed with 1 error(s) at Thu Nov 29 16:15:15 2018 elapsed 0 00:00:02

加了后执行过程如下:

[oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump dumpfile=20181129.dump tables=BFCRM.CRMT2 table_exists_action=truncate content=data_only;

Import: Release 11.2.0.4.0 - Production on Thu Nov 29 16:16:42 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_TABLE_01": system/**** directory=dump dumpfile=20181129.dump tables=BFCRM.CRMT2 table_exists_action=truncate content=data_only
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT2" 6.095 MB 400000 rows
Job "SYSTEM"."SYS_IMPORT_TABLE_01" successfully completed at Thu Nov 29 16:16:53 2018 elapsed 0 00:00:10

3.6、重命名表
1、语法规则
remap_table=[schema.]old_tablename[.partition]:new_tablename
remap_table如果在同一个schema下进行,虽然不要加remap_schema,但是remap_table冒号前面的表名一定要带schema信息,
冒号后面的表名一定不能带schema信息
remap_table如果在不同schema的情况下进行,如user1.A1转换成user2.B1,user1.A2转换成user2.B1,
必须加remap_schema,且remap_table冒号前面的表名一定要带schema信息,冒号后面的表名一定不能带schema信息

有如下两种方式

remap_table= user1.A1:B1 remap_table= user1.A2:B1 remap_schema=user1: user2

remap_table= user1. A1:B1, user1.A2:B1 remap_schema=user1: user2

2、例子
impdp system/DHHZDHHZ directory=dump dumpfile=today2.dump tables=BFCRM.CRMT2 remap_table=BFCRM.CRMT2:SCOCRMT2 remap_schema=BFCRM:SCOTT content=data_only
impdp system/DHHZDHHZ directory=dump dumpfile=today2.dump tables=BFCRM.CRMT2 remap_schema=BFCRM:SCOTT

3.7、重用导出的文件名

1、语法
reuse_dumpfiles=y
2、执行语句
[oracle@destogg ~]$ expdp system/DHHZDHHZ directory=dump dumpfile=new.dump reuse_dumpfiles=y

Export: Release 11.2.0.4.0 - Production on Wed Nov 28 22:49:00 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** parfile=1par reuse_dumpfiles=y
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 240 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . exported "BFCRM"."CRMT2" 6.095 MB 400000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/new.dump
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Wed Nov 28 22:49:32 2018 elapsed 0 00:00:31

3.8、数据库得并行操作

1、并行参数调整原则
parallel参数的设置不要大于服务器上cpu数量的两倍
2、替换变量%U的说明
使用替换变量%U,可以使数据泵自动创建符合并行度的数据文件,%U替换变量的起始值为01,并随数据泵文件数量的增加而增加
3、导出语法形式为
expdp system/DHHZDHHZ parallel=4 dumpfile=exp%U.dmp directory=dumpfile
4、导入语法形式为
impdp system/DHHZDHHZ parallel=4 dumpfile=exp%U.dmp directory=dumpfile

四、数据泵交互模式

4.1、说明
1、在使用expdp活impdp启动数据泵作业中、按ctrl+c组合健
2、对正在运行的作业应用attach参数
3、确定数据泵作业的名称
SQL> select owner_name,operation,job_name,state from dba_datapump_jobs;

OWNER_NAME OPERATION JOB_NAME STATE


SYSTEM IMPORT SYS_IMPORT_FULL_01 EXECUTING
4.2、进入交互模式
impdp system/DHHZDHHZ attach=SYS_IMPORT_FULL_01
4.3、交互状态操作
1、查看状态
Import> status

Job: SYS_IMPORT_FULL_01
Operation: IMPORT
Mode: FULL
State: EXECUTING
Bytes Processed: 184,135,660,280
Percent Done: 99
Current Parallelism: 4
Job Error Count: 0
Dump File: /backup/%u_erp_20181121.dmp
Dump File: /backup/01_erp_20181121.dmp
Dump File: /backup/02_erp_20181121.dmp
Dump File: /backup/03_erp_20181121.dmp
Dump File: /backup/04_erp_20181121.dmp
Dump File: /backup/05_erp_20181121.dmp
Dump File: /backup/06_erp_20181121.dmp
Dump File: /backup/07_erp_20181121.dmp
Dump File: /backup/08_erp_20181121.dmp
Dump File: /backup/09_erp_20181121.dmp
Dump File: /backup/10_erp_20181121.dmp
Dump File: /backup/11_erp_20181121.dmp

Worker 1 Status:
Process Name: DW00
State: EXECUTING
Object Schema: BFBHDD8
Object Name: PK_BB_KCCQSP
Object Type: SCHEMA_EXPORT/TABLE/INDEX/INDEX
Completed Objects: 63
Worker Parallelism: 4

Worker 2 Status:
Process Name: DW01
State: WORK WAITING

Worker 3 Status:
Process Name: DW02
State: WORK WAITING

Worker 4 Status:
Process Name: DW03
State: WORK WAITING
2、停止作业
$impdp system/DHHZDHHZ attach=SYS_IMPORT_FULL_01
import>stop_job
或者
import>stop_job=immediate

3、启动作业
$import>start_job

4、终止作业
import>kill_job

4.4、监控数据库作业
1、查询视图DBA_DATADUMP_JOBS
select job_name,operation,job_mode,state from dba_datapump_jobs;
SQL> select job_name,operation,job_mode,state from dba_datapump_jobs;

JOB_NAME OPERATION JOB_MODE STATE


SYS_IMPORT_FULL_01 IMPORT FULL EXECUTING

2.2、命令行交互模式
Import> status

Job: SYS_IMPORT_FULL_01
Operation: IMPORT
Mode: FULL
State: EXECUTING
Bytes Processed: 184,135,660,280
Percent Done: 99
Current Parallelism: 4
Job Error Count: 0
Dump File: /backup/%u_erp_20181121.dmp
Dump File: /backup/01_erp_20181121.dmp
Dump File: /backup/02_erp_20181121.dmp
Dump File: /backup/03_erp_20181121.dmp
Dump File: /backup/04_erp_20181121.dmp
Dump File: /backup/05_erp_20181121.dmp
Dump File: /backup/06_erp_20181121.dmp
Dump File: /backup/07_erp_20181121.dmp
Dump File: /backup/08_erp_20181121.dmp
Dump File: /backup/09_erp_20181121.dmp
Dump File: /backup/10_erp_20181121.dmp
Dump File: /backup/11_erp_20181121.dmp

五、数据泵过滤
5.1、过滤说明
query参数可以导出或导入数据子集
sample参数可以导出表中一定百分比的行
content参数可以设置在导出和导入中包含或不包含数据和元数据
exclude参数可以设置排除导出和导入内容之外的对象
include参数可以设置被包含到导出和导入内容中的对象
schemas参数仅操作数据库对象的某个子集

5.2、设置query参数
1、语法
query=[schema.][table_name:] query_clause
2、语法说明
查询子句必须放在双引号或单引号中。建议sql子句放入双引号中
3、命令行中的query语句格式如下:
expdp system/DHHZDHHZ directory=dump dumpfile=exp.dmp tables=BFCRM.CRMT1 query=BFCRM.CRMT1:\" where m \<=100 \" (对所有特殊字符都加转义符号\)

 4、参数文件中的query语句格式如下:
    userid=system/DHHZDHHZ
    directory=dump
    dumpfile=exp.dump
    tables=BFCRM.CRMT1
    query=BFCRM.CRMT1:"where m <=100"
 5、例子
   SQL> select count(*) from BFCRM.CRMT1 WHERE M<=100;

COUNT(*)

  5000

  命令行执行结果如下:

[oracle@destogg backup]$ expdp system/DHHZDHHZ directory=dump dumpfile=exp.dmp tables=BFCRM.CRMT1 query=BFCRM.CRMT1:\" where m \<=100 \"

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 14:27:04 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01": system/**** directory=dump dumpfile=exp.dmp tables=BFCRM.CRMT1 query=BFCRM.CRMT1:" where m <=100 "
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 232 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 68.88 KB 5000 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
/backup/exp.dmp
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at Fri Nov 30 14:27:12 2018 elapsed 0 00:00:07
参数文件执行结果如下:
[oracle@destogg backup]$ expdp parfile=1par

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 14:28:54 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01": system/**** parfile=1par
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 232 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 68.88 KB 5000 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
/backup/exp.dump
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at Fri Nov 30 14:28:57 2018 elapsed 0 00:00:03

5.3、按百分比导出数据
1、说明
在执行导出时,该方法对于有子表,表中含有外键约束时,有限制。
2、语法
sample=[[schema.]table_name:]sample_percent
3、导出语句如下:
expdp system/DHHZDHHZ directory=dump dumpfile=exp.dump tables=BFCRM.CRMT1 sample=10;
expdp system/DHHZDHHZ directory=dump dumpfile=exp.dump tables=BFCRM.CRMT1,BFCRM.CRMT2 sample=CRMT2:20
4、例子
[oracle@destogg backup]$ expdp system/DHHZDHHZ directory=dump dumpfile=exp.dump tables=BFCRM.CRMT1 sample=10;

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 14:53:18 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_TABLE_01": system/**** directory=dump dumpfile=exp.dump tables=BFCRM.CRMT1 sample=10
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 23.19 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 18.52 MB 1249068 rows
Master table "SYSTEM"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_TABLE_01 is:
/backup/exp.dump
Job "SYSTEM"."SYS_EXPORT_TABLE_01" successfully completed at Fri Nov 30 14:53:21 2018 elapsed 0 00:00:03
5.4、从导出文件中排除对象
1、说明
该参数可以使数据泵不导出指定对象
导出操作默认模式是方案级,如果要将某个方案排除导出文件,应先将导出操作设置为全库模式,再排除方案。
name_clause子句用双引号
2、语法
exclude=object_type[:name_clause][,...] object_type代表数据库对象

3、命令行语句
 expdp  system/DHHZDHHZ directory=dump dumpfile=expdp schemas=BFCRM exclude=table:\"in\(\'CRMT1\',\'CRMT2\'\)\"
4、参数文件语句:
userid=system/DHHZDHHZ
directory=dump
dumpfile=exp.dump
schemas=BFCRM
exclude=table:"in('CRMT1','CRMT2')"
-------------------------------------
exclude=table:"='CRMT1'"
-------------------------------------
exclude=table:"like'CRMT%'"
-------------------------------------
exclude=statistics
5、命令行执行过程如下:
[oracle@destogg backup]$  expdp  system/DHHZDHHZ directory=dump dumpfile=expdp schemas=BFCRM exclude=table:\"in\(\'CRMT1\',\'CRMT2\'\)\"

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 16:49:20 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** directory=dump dumpfile=expdp schemas=BFCRM exclude=table:"in('CRMT1','CRMT2')"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."SCOTT.SCOCRMT2" 6.095 MB 400000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/expdp.dmp
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri Nov 30 16:49:25 2018 elapsed 0 00:00:04
6、参数文件执行过程如下:
[oracle@destogg backup]$ expdp parfile=1par

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 17:05:21 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** parfile=1par
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 8 MB
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."SCOTT.SCOCRMT2" 6.095 MB 400000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/exp.dump
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri Nov 30 17:05:25 2018 elapsed 0 00:00:04

5.5、在导出文件中包含指定对象
1、说明
include参数可以使数据泵仅在导出文件中包含指定的数据库对象
2、语法
include=object_type[:name_clause][,...]
3、语句为
expdp system/DHHZDHHZ directory=dump dumpfile=exp.dump schemas=BFCRM include=table:\"=\'CRMT1\'\" 或者include=table:"\=\'CRMT1\'"
4、执行过程如下:
oracle@destogg backup]$ expdp system/DHHZDHHZ directory=dump dumpfile=exp.dump schemas=BFCRM include=table:\"=\'CRMT1\'\"

Export: Release 11.2.0.4.0 - Production on Fri Nov 30 17:33:41 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** directory=dump dumpfile=exp.dump schemas=BFCRM include=table:"='CRMT1'"
Estimate in progress using BLOCKS method...
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 232 MB
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded


Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is:
/backup/exp.dump
Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at Fri Nov 30 17:33:47 2018 elapsed 0 00:00:05
5.6、从导入文件中排除对象
[oracle@destogg ~]$ impdp system/DHHZDHHZ directory=dump dumpfile=today.dump exclude=table:\"=\'SCOTT.SCOCRMT2\'\"

Import: Release 11.2.0.4.0 - Production on Fri Nov 30 18:19:56 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_FULL_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_FULL_01": system/**** directory=dump dumpfile=today.dump exclude=table:"='SCOTT.SCOCRMT2'"
Processing object type SCHEMA_EXPORT/USER
Processing object type SCHEMA_EXPORT/DEFAULT_ROLE
Processing object type SCHEMA_EXPORT/TABLESPACE_QUOTA
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 "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFCRM"."CRMT2" 6.095 MB 400000 rows
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_FULL_01" successfully completed at Fri Nov 30 18:20:15 2018 elapsed 0 00:00:19

5.7、在导入中仅包含对象
1、命令行中执行过程如下:
SQL> create user BFCRM identified by DHHZDHHZ default tablespace JXC;

User created.
SQL> alter user BFCRM quota unlimited on jxc;

User altered.
[oracle@destogg backup]$ impdp system/DHHZDHHZ directory=dump dumpfile=20181202.dump SCHEMAS=BFCRM include=table:"\=\'CRMT1\'"

Import: Release 11.2.0.4.0 - Production on Sun Dec 2 21:19:05 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/**** directory=dump dumpfile=20181202.dump SCHEMAS=BFCRM include=table:\=\'CRMT1\'
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Sun Dec 2 21:19:39 2018 elapsed 0 00:00:33

2、参数文件中执行如下:
[oracle@destogg backup]$ cat 1par
userid=system/DHHZDHHZ
directory=dump
dumpfile=20181202.dump
schemas=BFCRM
include=table:"='CRMT1'"

[oracle@destogg backup]$ impdp parfile=1par

Import: Release 11.2.0.4.0 - Production on Sun Dec 2 21:25:27 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/**** parfile=1par
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Sun Dec 2 21:25:56 2018 elapsed 0 00:00:28

3、参数文件中只导入多个表
[oracle@destogg backup]$ impdp parfile=1par

Import: Release 11.2.0.4.0 - Production on Sun Dec 2 21:37:19 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully loaded/unloaded
Starting "SYSTEM"."SYS_IMPORT_SCHEMA_01": system/**** parfile=1par
Processing object type SCHEMA_EXPORT/TABLE/TABLE
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "BFCRM"."CRMT1" 185.3 MB 12500000 rows
. . imported "BFCRM"."CRMT2" 6.095 MB 400000 rows
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/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at Sun Dec 2 21:38:13 2018 elapsed 0 00:00:54

[oracle@destogg backup]$ cat 1par
userid=system/DHHZDHHZ
directory=dump
dumpfile=20181202.dump
schemas=BFCRM
include=table:"in('CRMT1','CRMT2')"

5.8、导出表、索引、约束和触发器的ddl
1、说明
使用schemas模式,并设置content=metadata_only
导出对象时,数据泵会导出所有依存对象
2、例子
C:\Users\Administrator>expdp system/DHHZDHHZ directory=dump dumpfile=2018.DUMP schemas=BFPUB10 content=metadata_only inc
lude=table

Export: Release 11.2.0.4.0 - Production on 星期日 12月 2 22:08:05 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.

连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动 "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/**** directory=dump dumpfile=2018.DUMP schemas=BFPUB10 content=metadat
a_only include=table
处理对象类型 SCHEMA_EXPORT/TABLE/TABLE
处理对象类型 SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT
处理对象类型 SCHEMA_EXPORT/TABLE/COMMENT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/INDEX
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
处理对象类型 SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
处理对象类型 SCHEMA_EXPORT/TABLE/TRIGGER
处理对象类型 SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
已成功加载/卸载了主表 "SYSTEM"."SYS_EXPORT_SCHEMA_01"


SYSTEM.SYS_EXPORT_SCHEMA_01 的转储文件集为:
E:\BACKUP\2018.DUMP
作业 "SYSTEM"."SYS_EXPORT_SCHEMA_01" 已于 星期日 12月 2 22:10:45 2018 elapsed 0 00:01:55 成功完成

六、数据泵的跟踪
6.1、说明
When value 480300 is specified, we will trace the Master Control process (MCP) and the Worker process(es).
6.2、生成跟踪的方式
方式1、expdp / DIRECTORY= DUMPFILE=.dmp LOGFILE=.log FULL=Y

Export: Release 10.2.0.3.0 - Production on Thursday, 18 October, 2007 17:11:08
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
FLASHBACK automatically enabled to preserve database integrity.
Starting ""."SYS_EXPORT_FULL_01": /**** DIRECTORY=my_dir DUMPFILE=.dmp LOGFILE=.log FULL=y
Estimate in progress using BLOCKS method...
Processing object type DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA-- press Control-C to go to the Interactive Command mode,
-- and temporary stop the job with the STOP_JOB command:

Export> stop
Are you sure you wish to stop this job ([yes]/no): yes

-- use the system generated job-name SYS_EXPORT_FULL_01 to re-attach to the job
-- and specify the TRACE parameter with a tracing level:
% expdp / ATTACH=sys_export_full_01 TRACE=480300

Export: Release 10.2.0.3.0 - Production on Thursday, 18 October, 2007 17:23:48
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

Job: SYS_EXPORT_FULL_01
Owner:
Operation: EXPORT
Creator Privs: FALSE
GUID: F4E6BF997DFA46378D543F998E82653E
Start Time: Thursday, 18 October, 2007 17:23:49
Mode: FULL
Instance:
Max Parallelism: 1
EXPORT Job Parameters:
Parameter Name Parameter Value:
CLIENT_COMMAND /**** DIRECTORY= DUMPFILE=.dmp
LOGFILE=.log FULL=y
State: IDLING
Bytes Processed: 0
Current Parallelism: 1
Job Error Count: 0
Dump File: /.dmp
bytes written: 4,096

Worker 1 Status:
State: UNDEFINED

-- restart the job and change back from Interactive Command mode to Logging mode
-- with CONTINUE_CLIENT (note that tracing with level 480300 is now active):

Export> cont
Restarting ""."SYS_EXPORT_FULL_01": /**** DIRECTORY=
DUMPFILE=.dmp LOGFILE=.log FULL=y
Processing object type DATABASE_EXPORT/TABLESPACE
Processing object type DATABASE_EXPORT/PROFILE

方式2
% expdp / DIRECTORY= DUMPFILE=.dmp LOGFILE=.log TABLES= TRACE=480300

expdp BFAPP8/DHHZDHHZ dumpfile=%U_20190612.dmp directory=dumpdir schemas=BFAPP8,BFPUB8,BFBHDD8,POS_USER8,cs_pos,bf_sys_user,csbjf job_name=pos_job2 parallel=3 logfile=1.log TRACE=480300

方式3
Use a database init.ora/spfile event to trace Data Pump.
Data Pump tracing can also be started with a line with EVENT 39089 in the initialization parameter file. This method should only be used to trace the Data Pump calls in an early state, e.g. if details are needed about the DBMS_DATAPUMP.OPEN API call. Trace level 0x300 will trace all Data Pump client processes.
Example when using init.ora initialization parameter file:

  • add the following line to init.ora parameter file:

    EVENT="39089 trace name context forever,level 0x300"

  • Restart the database.
    • Start the Export Data Pump or Import Data Pump job.

方式4
Example when using spfile initialization parameter file:

-- when using spfile parameter file:

CONNECT / as sysdba
SHOW PARAMETER event

NAME TYPE VALUE


event string

ALTER SYSTEM SET EVENTS = '39089 trace name context forever, level 0x300'
SCOPE = spfile;

SHUTDOWN immediate
STARTUP
SHOW PARAMETER event

NAME TYPE VALUE


event string 39089 trace name context forev
er, level 0x300

  • Start the Export Data Pump or Import Data Pump job.

    -- to remove the event(s) again:
    ALTER SYSTEM RESET EVENT SCOPE = spfile SID='*';
    SHUTDOWN immediate
    STARTUP

Alternatively, the event 39089 can also be enabled and disabled at system level using next commands:

-- Enable event
ALTER SYSTEM SET EVENTS = '39089 trace name context forever, level 0x300' ;

-- Disable event
ALTER SYSTEM SET EVENTS = '39089 trace name context off' ;

6.3. 找到数据泵的跟踪文件

Data Pump trace files are written to the directories specified by the init.ora/spfile initialization parameters BACKGROUND_DUMP_DEST and USER_DUMP_DEST.

1 Data Pump Master Control Process (MCP).
Format : dm.trc
Example: ORCL_dm00_2896.trc or: ORCL_dm01_3422.trc (for second active Master Control Process)
Location: BACKGROUND_DUMP_DEST or /trace

  1. Data Pump Worker Process trace file.
    Format : dw.trc
    Example: ORCL_dw01_2936.trc or: ORCL_dw01_2844.trc and ORCL_dw02_2986.trc (if PARALLEL=2)
    Location: BACKGROUND_DUMP_DEST or /trace

  2. Data Pump Shadow Process trace file.
    Format : ora.trc
    Example: ORCL_ora_3020.trc
    Location: USER_DUMP_DEST or /trace

-- determine location of the trace files on disk (Oracle10g):

SHOW PARAMETER dump

NAME TYPE VALUE


background_dump_dest string
user_dump_dest string
...

-- determine location of the trace files on disk (Oracle11g):

SHOW PARAMETER diag

NAME TYPE VALUE


diagnostic_dest string

Note that in Oracle10g the default location for the trace files is: $ORACLE_HOME/rdbms/log
This location will be used if the initialization parameters BACKGROUND_DUMP_DEST and/or USER_DUMP_DEST are not set.

For Oracle11g, the trace files are written to the /trace
where is: /diag///
where is specified by DIAGNOSTIC_DEST (defaults to: $ORACLE_HOME/log).
E.g.: /oracle/diag/rdbms/ORCL/ORCL/trace

How to get timing details on processed objects ? Parameter: METRICS
expdp / DIRECTORY= DUMPFILE=.dmp \
LOGFILE=expdp_s.log SCHEMAS= METRICS=y

-- In SQL*Plus, activate SQL tracing with ORADEBUG and the SPID:

-- Example to SQL_TRACE Worker process with level 4 (Bind values):
oradebug setospid 17294
oradebug unlimit
oradebug event 10046 trace name context forever, level 4
oradebug tracefile_name

-- Example to SQL_TRACE Master Control process with level 8 (Waits):
oradebug setospid 17292
oradebug unlimit
oradebug event 10046 trace name context forever, level 8
oradebug tracefile_name

-- To stop the tracing:
oradebug event 10046 trace name context off

event 10046, level 1 = enable standard SQL_TRACE functionality
event 10046, level 4 = as level 1, plus trace the BIND values
event 10046, level 8 = as level 1, plus trace the WAITs
event 10046, level 12 = as level 1, plus trace the BIND values and the WAITs