expdp 指定的表分区 其实指定where 条件也可以

Applies To

All Users

Summary

This document describes and explains with examples how to exclude partitions through a Data Pump export (EXPDP) backup using the API package: DBMS_DATAPUMP.DATA_FILTER.

Solution

  1. Create the environment.

SQL> connect / as sysdba

Connected.

SQL> drop user test cascade;

User dropped.

SQL> purge dba_recyclebin;

DBA Recyclebin purged.

SQL> create user test identified by <Password> default tablespace users temporary tablespace temp;

User created.

SQL> grant connect, resource to test;

Grant succeeded.

SQL> create or replace directory dpudir as '/tmp';

Directory created.

SQL> grant read, write on directory dpudir to test;

Grant succeeded.

  1. Create a partitioned table (with 5 partitions).

SQL> connect test/<Password>

Connected.

SQL> create table systemlog

(

id number not null,

createdate integer not null,

application varchar2(30) not null,

objectname varchar2(20) not null,

operation varchar2(30) not null

)

partition by range (createdate)

(

partition oct2007_07 values less than (20071007),

partition oct2007_14 values less than (20071014),

partition oct2007_21 values less than (20071021),

partition oct2007_28 values less than (20071027),

partition hightime values less than (maxvalue)

);

Table created.

SQL> connect / as sysdba

SQL> select partition_name, table_name

from dba_tab_partitions

where table_owner = 'TEST' and

table_name = 'SYSTEMLOG'

order by partition_position;

PARTITION_NAME TABLE_NAME


OCT2007_07 SYSTEMLOG

OCT2007_14 SYSTEMLOG

OCT2007_21 SYSTEMLOG

OCT2007_28 SYSTEMLOG

HIGHTIME SYSTEMLOG

  1. Using the DBMS_DATAPUMP package, specify only the desired partitions (e.g. OCT2007_21, OCT2007_28) you want to backup.

declare

h1 number;

begin

h1 := dbms_datapump.open (operation => 'EXPORT',

job_mode => 'TABLE');

dbms_datapump.add_file (handle => h1,

filename => 'EXPDAT.DMP',

directory => 'DPUDIR',

filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_DUMP_FILE);

dbms_datapump.add_file (handle => h1,

filename => 'EXPDAT.LOG',

directory => 'DPUDIR',

filetype => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);

dbms_datapump.metadata_filter (handle => h1,

name => 'SCHEMA_EXPR',

value => 'IN (''TEST'')');

dbms_datapump.metadata_filter (handle => h1,

name => 'NAME_EXPR',

value => 'IN (''SYSTEMLOG'')');

dbms_datapump.data_filter (handle => h1,

name => 'PARTITION_LIST',

value => '''OCT2007_21'', ''OCT2007_28''',

table_name => 'SYSTEMLOG',

schema_name => 'TEST');

dbms_datapump.start_job (handle => h1);

dbms_datapump.detach (handle => h1);

end;

/

  1. Verify the expdp log file EXPDAT.LOG.

#> ls -l EXP*

-rw-r----- 1 oracle dba 86016 Sep 10 12:19 EXPDAT.DMP

-rw-r--r-- 1 oracle dba 666 Sep 10 12:19 EXPDAT.LOG

#> more EXPDAT.LOG

Starting "SYS"."SYS_EXPORT_TABLE_01":

Estimate in progress using BLOCKS method...

Processing object type TABLE_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 0 KB

Processing object type TABLE_EXPORT/TABLE/TABLE

. . exported "TEST"."SYSTEMLOG":"OCT2007_21" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_28" 0 KB 0 rows

Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded

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

Dump file set for SYS.SYS_EXPORT_TABLE_01 is:

/tmp/EXPDAT.DMP

Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 12:19:42

Under that scenario, the partitions SYSTEMLOG:OCT2007_07, SYSTEMLOG:OCT2007_14, SYSTEMLOG:HIGHTIME were excluded.

  1. If you try to exclude a partition during Data Pump Export (EXPDP) and use EXCLUDE parameter, then expdp ignores the specified partition (for example, SYSTEMLOG:OCT2007_07).

#> expdp test/<Password> directory=dpudir dumpfile=exclude.dmp logfile=exclude.log schemas=test exclude=table:\"IN \(\'SYSTEMLOG\:OCT2007_07\'\)\"

Export: Release 11.1.0.6.0 - 64bit Production on Wednesday, 10 September, 2008 12:21:27

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining,

Oracle Database Vault and Real Application Testing options

Starting "TEST"."SYS_EXPORT_SCHEMA_01": test/******** directory=dpudir dumpfile=exclude.dmp logfile=exclude.log schemas=test exclude=table:"IN ('SYSTEMLOG:OCT2007_07')"

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 0 KB

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/COMMENT

Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA

. . exported "TEST"."SYSTEMLOG":"HIGHTIME" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_07" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_14" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_21" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_28" 0 KB 0 rows

Master table "TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

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

Dump file set for TEST.SYS_EXPORT_SCHEMA_01 is:

/tmp/exclude.dmp

Job "TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 12:21:51

  1. Using the LIKE operator (instead of IN) does not work either.

#> expdp test/<password> directory=dpudir dumpfile=exclude1.dmp logfile=exclude1.log schemas=test exclude=table:\"LIKE \(\'%SYSTEMLOG\:OCT2007_07%\'\)\"

Export: Release 11.1.0.6.0 - 64bit Production on Wednesday, 10 September, 2008 12:21:53

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

Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP, Data Mining,

Oracle Database Vault and Real Application Testing options

Starting "TEST"."SYS_EXPORT_SCHEMA_01": test/******** directory=dpudir dumpfile=exclude1.dmp logfile=exclude1.log schemas=test exclude=table:"LIKE ('%SYSTEMLOG:OCT2007_07%')"

Estimate in progress using BLOCKS method...

Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA

Total estimation using BLOCKS method: 0 KB

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/COMMENT

Processing object type SCHEMA_EXPORT/POST_SCHEMA/PROCACT_SCHEMA

. . exported "TEST"."SYSTEMLOG":"HIGHTIME" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_07" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_14" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_21" 0 KB 0 rows

. . exported "TEST"."SYSTEMLOG":"OCT2007_28" 0 KB 0 rows

Master table "TEST"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded

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

Dump file set for TEST.SYS_EXPORT_SCHEMA_01 is:

/tmp/exclude1.dmp

Job "TEST"."SYS_EXPORT_SCHEMA_01" successfully completed at 12:22:17

  1. Therefore, please use the package DBMS_DATAPUMP.DATA_FILTER and specify the desired partitions you want to backup.

...

dbms_datapump.data_filter (handle => h1,

name => 'PARTITION_LIST',

value => '''OCT2007_21'', ''OCT2007_28''',

table_name => 'SYSTEMLOG',

schema_name => 'TEST');

...

Note: An alternative to using the DBMS_DATAPUMP API is to list the partitions to be exported using syntax like:

...
tables=<TableOwner>.<TableName>:<PartitionName1>
tables=<TableOwner>.<TableName>:<PartitionName2>
tables=<TableOwner>.<TableName>:<PartitionName3>

相关推荐
todoitbo7 小时前
把发票台账接进 Codex:KingbaseES MCP 的一次只读风险排查实践
数据库·oracle·codex·kingbasees·mcp
暗暗别做白日梦8 小时前
CompletableFuture 并发统计
网络·数据库·oracle
TDengine (老段)8 小时前
TDengine 认证与权限 — 用户、角色、RBAC
大数据·数据库·物联网·oracle·时序数据库·tdengine·涛思数据
晴天¥8 小时前
记一次Oracle集群归档日志爆满之后如何处理(涉及ASM磁盘的增添。有坑必踩)
数据库·oracle
Hoxy.R8 小时前
记录一次Oracle 19c RAC iSCSI会话反复重连:comm error (1020) 原因定位与解决
数据库·oracle
sky_8106131 天前
Oracle ERP 各模块业务管理功能及底层表说明
数据库·oracle
ClouGence1 天前
加一张临时表,OceanBase Oracle 写入居然快了 30 倍!
数据库·sql·oracle
oradh1 天前
Oracle参数文件(PFILE与SPFILE)维护操作总结
数据库·oracle·oracle参数·spfile·pfile
鸽芷咕1 天前
【金仓数据库征文】从 Oracle 到金仓:一次零误差的数据库国产化迁移实录
数据库·oracle
0566461 天前
RAG 向量检索:从“查字“到“查意“
数据库·人工智能·学习·oracle