數據泵整理

目錄
一、數據泵的操作準備
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{<value>}"
由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 <LOGIN>/<PASSWORD> DIRECTORY=<DIRECOTY_NAME> DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.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 "<LOGIN_SCHEMA>"."SYS_EXPORT_FULL_01": <LOGIN>/**** DIRECTORY=my_dir DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.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 <LOGIN>/<PASSWORD> 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: <LOGIN_SCHEMA>
Operation: EXPORT
Creator Privs: FALSE
GUID: F4E6BF997DFA46378D543F998E82653E
Start Time: Thursday, 18 October, 2007 17:23:49
Mode: FULL
Instance: <INSTANCE_NAME>
Max Parallelism: 1
EXPORT Job Parameters:
Parameter Name Parameter Value:
CLIENT_COMMAND <LOGIN>/**** DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME>.dmp
LOGFILE=<LOG_NAME>.log FULL=y
State: IDLING
Bytes Processed: 0
Current Parallelism: 1
Job Error Count: 0
Dump File: <DIRECTORY_PATH>/<DUMP_NAME>.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 "<LOGIN_SCHEMA>"."SYS_EXPORT_FULL_01": <LOGIN>/**** DIRECTORY=<DIRECTORY_NAME>
DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.log FULL=y
Processing object type DATABASE_EXPORT/TABLESPACE
Processing object type DATABASE_EXPORT/PROFILE

方式2
% expdp <LOGIN>/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.log TABLES=<TABLE_NAME> 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 : <SID>dm<number><process_id>.trc
Example: ORCL_dm00_2896.trc or: ORCL_dm01_3422.trc (for second active Master Control Process)
Location: BACKGROUND_DUMP_DEST or <ADR_HOME>/trace

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

  2. Data Pump Shadow Process trace file.
    Format : <SID>ora<process_id>.trc
    Example: ORCL_ora_3020.trc
    Location: USER_DUMP_DEST or <ADR_HOME>/trace

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

SHOW PARAMETER dump

NAME TYPE VALUE


background_dump_dest string <background_dump_dest_location>
user_dump_dest string <user_dump_dest_location>
...

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

SHOW PARAMETER diag

NAME TYPE VALUE


diagnostic_dest string <diagnostic_dest_location>

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 <ADR_HOME>/trace
where <ADR_HOME> is: <ADR_BASE>/diag/<product_type>/<prod_id>/<instance_id>
where <ADR_BASE> 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 <LOGIN>/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME>.dmp \
LOGFILE=expdp_s.log SCHEMAS=<SCHEMA_NAME> 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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章