Oracle 数据泵(expdp和impdp)排除某个表
Tags: EXCLUDEexpdpimpdpOracle排除表数据泵数据泵逻辑导出导入
实验
环境:LHR和LHR1用户下都有T3表,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [oracle@lhrora11204 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Export: Release 11.2.0.4.0 - Production on Sat Dec 3 03:08:27 2022 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=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 40 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE . . exported "LHR1"."T2" 950.1 KB 86961 rows . . exported "LHR"."T3" 950.1 KB 86962 rows . . exported "LHR"."T1" 950.1 KB 86960 rows Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA . . exported "LHR1"."T3" 950.2 KB 86964 rows Processing object type SCHEMA_EXPORT/TABLE/TABLE Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /home/oracle/lhr_01.dmp /home/oracle/lhr_02.dmp /home/oracle/lhr_03.dmp /home/oracle/lhr_04.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sat Dec 3 03:08:34 2022 elapsed 0 00:00:07 |
如下,排除T3表,会排除LHR和LHR1这2个用户下的T3表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | [oracle@lhrora11204 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS,TABLE:"in('T3')" LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Export: Release 11.2.0.4.0 - Production on Sat Dec 3 03:10:41 2022 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=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS,TABLE:in('T3') LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 20 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE . . exported "LHR"."T1" 950.1 KB 86960 rows . . exported "LHR1"."T2" 950.1 KB 86961 rows Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /home/oracle/lhr_01.dmp /home/oracle/lhr_02.dmp /home/oracle/lhr_03.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sat Dec 3 03:10:48 2022 elapsed 0 00:00:07 |
如下写法并不能排除T3表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [oracle@lhrora11204 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS,TABLE:"in('LHR.T3')" LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Export: Release 11.2.0.4.0 - Production on Sat Dec 3 03:09:55 2022 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=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS,TABLE:in('LHR.T3') LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 40 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE . . exported "LHR1"."T2" 950.1 KB 86961 rows . . exported "LHR"."T3" 950.1 KB 86962 rows . . exported "LHR"."T1" 950.1 KB 86960 rows Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA . . exported "LHR1"."T3" 950.2 KB 86964 rows Processing object type SCHEMA_EXPORT/TABLE/TABLE Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /home/oracle/lhr_01.dmp /home/oracle/lhr_02.dmp /home/oracle/lhr_03.dmp /home/oracle/lhr_04.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sat Dec 3 03:10:03 2022 elapsed 0 00:00:07 |
解决:只导出元数据,不导出具体数据:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | [oracle@lhrora11204 ~]$ more parfile.par QUERY=LHR.T3:"where 1 <> 1" [oracle@lhrora11204 ~]$ [oracle@lhrora11204 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y parfile=parfile.par Export: Release 11.2.0.4.0 - Production on Sat Dec 3 03:35:28 2022 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=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y parfile=parfile.par Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 40 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE . . exported "LHR"."T1" 950.1 KB 86960 rows . . exported "LHR1"."T2" 950.1 KB 86961 rows . . exported "LHR1"."T3" 950.2 KB 86964 rows Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA . . exported "LHR"."T3" 5.585 KB 0 rows Processing object type SCHEMA_EXPORT/TABLE/TABLE Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /home/oracle/lhr_01.dmp /home/oracle/lhr_02.dmp /home/oracle/lhr_03.dmp /home/oracle/lhr_04.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sat Dec 3 03:35:35 2022 elapsed 0 00:00:07 |
使用查询,也会排除所有用户下的T3表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | vi parfile.par EXCLUDE=STATISTICS,TABLE:"IN (select TABLE_NAME from DBA_TABLES where owner='LHR' AND table_name='T3')" expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp parfile=parfile.par LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y [oracle@lhrora11204 ~]$ expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp parfile=parfile.par LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Export: Release 11.2.0.4.0 - Production on Sat Dec 3 03:43:09 2022 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=D1 dumpfile=lhr_%U.dmp parfile=parfile.par LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 20 MB Processing object type SCHEMA_EXPORT/USER Processing object type SCHEMA_EXPORT/SYSTEM_GRANT Processing object type SCHEMA_EXPORT/ROLE_GRANT Processing object type SCHEMA_EXPORT/DEFAULT_ROLE . . exported "LHR"."T1" 950.1 KB 86960 rows . . exported "LHR1"."T2" 950.1 KB 86961 rows Processing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHEMA Processing object type SCHEMA_EXPORT/TABLE/TABLE Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is: /home/oracle/lhr_01.dmp /home/oracle/lhr_02.dmp /home/oracle/lhr_03.dmp Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Sat Dec 3 03:43:19 2022 elapsed 0 00:00:09 |
How to Exclude Multiple Schemas and Tables in Export or Import (Doc ID 2087052.1)
APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.1 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Backup Service - Version N/A and later
Information in this document applies to any platform.
NOTE: In the document content below, the user information and data used represents fictitious data. Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.
GOAL
Include or Exclude multiple tables from multiple schemas in full Export or Import.
SOLUTION
Following example will show to exclude or include multiple tables or schemas.
It can be used either on the command line or in a parameter file.
- Example to use include on the command line to include all tables for owner AJ or BJ:
1 2 | expdp system/<PASSWORD> full=Y directory=<DIRECTORY_NAME> dumpfile=<DUMP_NAME>.dmp logfile=<LOG_NAME>.log include=table:\"in \(select table_name from dba_tables where owner like \'AJ%\' or owner like \'BJ%\' \)\" |
- Example to use exclude in a par file to exclude table A1_TAB owned by user AJ and B1_TAB owned by user BJ.
Syntax:
1 2 | EXCLUDE=TABLE:"IN (select table_name from dba_tables where (owner,table_name) in (('<user1>','<table1>'), ('<user2>','<table2>')) )" |
Example:
1 2 | EXCLUDE=TABLE:"IN (select TABLE_NAME from DBA_TABLES where (owner,table_name) in (('AJ','A1_TAB'), ('BJ','B1_TAB')) )" |
There is another workaround mentioned in following document by using the QUERY parameter to make sure no rows for these tables are exported (only metadata is exported). Please refer to:
Note 1474932.1 - How to Exclude Duplicate Tables From Some Schemas During a Full DataPump Export
REFERENCES
BUG:6860716 - EXPORT&FILTER TABLES FROM MULTIPLE SCHEMAS IN DATA PUMP
NOTE:341733.1 - Export/Import DataPump Parameters INCLUDE and EXCLUDE - How to Load and Unload Specific Objects
How to Exclude Duplicate Tables From Some Schemas During a Full DataPump Export (Doc ID 1474932.1)
APPLIES TO:
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Exadata Express Cloud Service - Version N/A and later
Oracle Database Cloud Exadata Service - Version N/A and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Backup Service - Version N/A and later
Information in this document applies to any platform.
SYMPTOMS
You need to do a full database export but the same table is present in several schemas and you want to exclude this table for one schemas only.
CHANGES
NONE
CAUSE
Duplicate table names.
SOLUTION
Unfortunately, you cannot exclude the tables. From Note 277905.1:
\1. Note that all specified tables in the selected schemas are exported, together with their dependent objects.
It is not possible to include or exclude tables owned by a specific schema with a full database export DataPump job, or schema level export DataPump job with multiple schema's.
\2. As a workaround, you can use the query parameter to make sure no rows for these tables are exported (only metadata is exported):
1 2 3 | QUERY=<owner1>.<table_name>:"where 1 <> 1" QUERY=<owner2>.<table_name>:"where 1 <> 1" |
REFERENCES
NOTE:277905.1 - Export/Import DataPump Parameter TABLES - How to Export and Import Tables Residing in Different Schemas
Export/Import DataPump Parameter TABLES - How to Export and Import Tables Residing in Different Schemas (Doc ID 277905.1)
APPLIES TO:
Oracle Database - Personal Edition - Version 10.1.0.2 to 11.1.0.7 [Release 10.1 to 11.1]
Oracle Database - Standard Edition - Version 10.1.0.2 to 11.1.0.7 [Release 10.1 to 11.1]
Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.1.0.7 [Release 10.1 to 11.1]
Information in this document applies to any platform.
NOTE: In the images and/or the document content below, the user information and data used represents fictitious data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product.
Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.
GOAL
With the classic export client you were able to export with one single export session, tables that were owned by different users.
For example to export the following tables:
- table EMP owned by user SCOTT
- table EMPLOYEES owned by user HR
- table CATEGORIES_TAB owned by user OE
% exp system/
TABLES=scott.emp,hr.employees,oe.categories_tab
Export: Release 11.1.0.6.0 - Production on Wed Nov 28 10:04:10 2007
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in WE8ISO8859P15 character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
Current user changed to SCOTT
. . exporting table EMP 14 rows exported
Current user changed to HR
. . exporting table EMPLOYEES 107 rows exported
Current user changed to OE
. . exporting table CATEGORIES_TAB 22 rows exported
. . exporting table PRODUCT_REF_LIST_NESTEDTAB 288 rows exported
. . exporting table SUBCATEGORY_REF_LIST_NESTEDTAB 21 rows exported
Export terminated successfully without warnings.
However, with Export Data Pump you get the following error:
% expdp system/
DUMPFILE=
TABLES=scott.emp,hr.employees,oe.categories_tab
Export: Release 11.1.0.6.0 - Production on Wednesday, 28 November, 2007 10:07:13
Copyright (c) 2003, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
UDE-00012: table mode exports only allow objects from one schema
This is caused by a restriction for the TABLES parameter of Data Pump:
"The table name that you specify can be preceded by a qualifying schema name. All table names specified must reside in the same schema."
An enhancement request has been filed to make the syntax similar to that of the original export client:
Bug 6860716 - EXPORT&FILTER TABLES FROM MULTIPLE SCHEMAS IN DATA PUMP
This is implemented in version 11.2.
How to achieve the same kind of export with Oracle Data Pump ?
SOLUTION
Solution 1: Use combination of SCHEMAS and INCLUDE parameters.
When using Data Pump you can use the combination of the SCHEMAS and INCLUDE parameters.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | File: expdp_tabs.par -------------------- DIRECTORY = <DIRECTORY_NAME> DUMPFILE = expdp_tabs.dmp LOGFILE = expdp_tabs.log SCHEMAS = scott,hr,oe INCLUDE = TABLE:"IN ('EMP', 'EMPLOYEES', 'CATEGORIES_TAB')" % expdp system/<PASSWORD> PARFILE=<PARFILE_NAME>.par Export: Release 11.1.0.6.0 - Production on Wednesday, 28 November, 2007 10:25:56 Copyright (c) 2003, 2007, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options FLASHBACK automatically enabled to preserve database integrity. Starting "SYSTEM"."SYS_EXPORT_SCHEMA_01": system/******** parfile=<PARFILE_NAME>.par Estimate in progress using BLOCKS method... Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA Total estimation using BLOCKS method: 320 KB Processing object type SCHEMA_EXPORT/TABLE/TABLE Processing object type SCHEMA_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT Processing object type SCHEMA_EXPORT/TABLE/INDEX/INDEX Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS Processing object type SCHEMA_EXPORT/TABLE/COMMENT Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT Processing object type SCHEMA_EXPORT/TABLE/TRIGGER Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS . . exported "HR"."EMPLOYEES" 16.80 KB 107 rows . . exported "OE"."CATEGORIES_TAB" 14.15 KB 22 rows . . exported "OE"."PRODUCT_REF_LIST_NESTEDTAB" 12.51 KB 288 rows . . exported "OE"."SUBCATEGORY_REF_LIST_NESTEDTAB" 6.593 KB 21 rows . . exported "SCOTT"."EMP" 8.570 KB 14 rows Master table "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded ****************************************************************************** Dump file set for SYSTEM.SYS_EXPORT_SCHEMA_01 is: <PATH>\<DUMP_NAME>.DMP Job "SYSTEM"."SYS_EXPORT_SCHEMA_01" successfully completed at 10:26:57 |
Remarks:
\1. Note that all specified tables in the selected schemas are exported, together with their dependent objects. It is not possible to include or exclude tables owned by a specific schema with a full database export Data Pump job, or schema level export Data Pump job with multiple schema's.
\2. Note that if you want to specify these parameters on the command line, you have to use the escape character for special characters:
Example for Windows (place all parameters on a single line):
1 2 3 | % expdp system/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.log SCHEMAS=scott,hr,oe INCLUDE=TABLE:\"IN ('EMP', 'EMPLOYEES', 'CATEGORIES_TAB')\" |
Example for Unix/Linux (escape all special characters):
1 2 3 | expdp system/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> \ DUMPFILE=<DUMP_NAME>.dmp LOGFILE=<LOG_NAME>.log SCHEMAS=scott,hr,oe \ INCLUDE=TABLE:\"IN \(\'EMP\', \'EMPLOYEES\', \'CATEGORIES_TAB\'\)\" |
\3. For additional details, see also:
Note 341733.1 - Export/Import DataPump Parameters INCLUDE and EXCLUDE - How to Load and Unload Specific Objects
Solution 2: Use multiple Data Pump jobs.
Alternatively, you can also run multiple jobs, e.g.:
-- Export table: scott.emp
1 2 | % expdp system/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME1>.dmp \ LOGFILE=expdp_tab1.log TABLES=scott.emp |
-- Export table: hr.employees
1 2 | % expdp system/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME2>.dmp \ LOGFILE=expdp_tab2.log TABLES=hr.employees |
-- Export table: oe.categories_tab
1 2 | % expdp system/<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=<DUMP_NAME3>.dmp \ LOGFILE=expdp_tab3.log TABLES=oe.categories_tab |
Remarks:
\1. Oracle Data Pump restrictions for the TABLES parameter:
- All table names specified must reside in the same schema.
- To specify a schema other than your own, you must have the EXP_FULL_DATABASE role.
- The use of wildcards is supported for one table name per export operation.
\2. For additional details, see also:
Note 277899.1 - Export/Import DataPump: UDE-00014 When Using Wildcard in the TABLES Parameter
\3. Another example if you want to exclude two specific tables (SCOTT.EMP and HR.EMPLOYEES) from a full database export Data Pump job:
-- Run a full database export, excluding all EMP and EMPLOYEES tables:
1 2 3 | % expdp system//<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=expdp_f.dmp \ LOGFILE=expdp_f.log FULL=Y \ EXCLUDE=TABLE:\"IN \(\'EMP\', \'EMPLOYEES\'\)\" |
-- Export tables EMP owned by users other than SCOTT:
1 2 | % expdp system//<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=expdp_tab1.dmp \ LOGFILE=expdp_tab1.log SCHEMAS=oe,hr INCLUDE=TABLE:\"=\'EMP\'\" |
-- To export tables EMPLOYEES owned by users other than HR:
1 2 | % expdp system//<PASSWORD> DIRECTORY=<DIRECTORY_NAME> DUMPFILE=expdp_tab2.dmp \ LOGFILE=expdp_tab2.log SCHEMAS=scott,oe INCLUDE=TABLE:\"=\'EMPLOYEES\'\" |
REFERENCES
NOTE:341733.1 - Export/Import DataPump Parameters INCLUDE and EXCLUDE - How to Load and Unload Specific Objects
NOTE:351598.1 - Export/Import DataPump: The Minimum Requirements to Use Export DataPump and Import DataPump (System Privileges)
NOTE:277899.1 - Export/Import DataPump: UDE-00014 When Using Wildcard in the TABLES Parameter
总结
数据泵要排除某个表,表前不能加用户名,尽管命令不报错,但是会导致EXCLUDE的TABLE选项排除失效,正确写法,如下
1 2 3 4 5 | expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp \ EXCLUDE=STATISTICS,TABLE:"in('T3')" \ LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y |
如下,不能排除LHR.T3表,虽然不报错,但是会导致EXCLUDE的TABLE选项排除失效:
1 | EXCLUDE=STATISTICS,TABLE:"in('LHR'.'T3')" SCHEMAS=LHR1,LHR |
如下,会排除T3表,但是会排除掉LHR和LHR1中的所有T3表,
1 | EXCLUDE=STATISTICS,TABLE:"in('T3')" SCHEMAS=LHR1,LHR |
解决办法:
1、使用parfile和QUERY只导出元数据,而不导出某个具体表:
1 2 3 4 5 6 | vi parfile.par QUERY=LHR.T3:"where 1 <> 1" expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp EXCLUDE=STATISTICS LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y parfile=parfile.par |
2、若LHR1和LHR用户下,只有LHR用户含T3表,则也可以使用如下的SQL
1 2 3 4 5 | expdp \'/ AS SYSDBA\' directory=D1 dumpfile=lhr_%U.dmp \ EXCLUDE=STATISTICS,TABLE:"in('T3')" \ LOGFILE=expdp_1.log SCHEMAS=LHR1,LHR CLUSTER=N COMPRESSION=ALL parallel=4 FILESIZE=2g REUSE_DUMPFILES=y |
对于某个表,可以单独进行导出和导入:
1 2 | expdp \'/ AS SYSDBA\' directory=D1 dumpfile=T3.dmp EXCLUDE=STATISTICS tables="LHR"."T3" CLUSTER=N COMPRESSION=ALL |
其它
数据泵常用写法参考:https://www.xmmup.com/oracleshujubengdaochudaoruchangyongxiefa.html