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>

相关推荐
龙虾PRO13 小时前
高并发场景数据库调优实操:目标定位、监控方法与优化维度全解析
数据库·oracle
l12586515 小时前
# LangGraph Deep Research Agent 全流程设计:多轮研究、人机协同与真实来源管理
数据库·人工智能·python·算法·自然语言处理·oracle·langchain
辰辉创聚17 小时前
重组蛋白表达不出来怎么办?蛋白表达失败、低表达及异常原因解析
python·oracle·eclipse·重组蛋白·蛋白·western blot
Java小白笔记19 小时前
Codex CLI 使用与斜杠指令实战教程
服务器·数据库·oracle
养生技术人19 小时前
Oracle OCP认证考试题目详解082系列第16题
数据库·sql·oracle·ocp
惜分飞20 小时前
kcratr_nab_less_than_odr和system坏块故障处理
数据库·oracle
惜分飞20 小时前
obet forcecopy功能抢救硬件故障中的数据文件
数据库·oracle
Java小白笔记21 小时前
Java中PDF文件导出,生成链路与实现
服务器·网络·oracle
小江的记录本1 天前
【ORM框架】MyBatis核心原理、ORM思想、MyBatis vs JPA
java·数据库·后端·spring·spring cloud·oracle·mybatis
疯狂打码的少年2 天前
【数据库技术】数据库三级模式结构(外模式/模式/内模式)
数据库·笔记·oracle