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>

相关推荐
Yushan Bai2 小时前
ORACLE数据库从WINDOWS环境迁移到LINUX环境并升级的方案步骤
数据库·oracle
秋917 小时前
数据库对比同步工具,快速比较开发库与生产库直接的差别,并自动生成存在差异的sql语句
数据库·oracle
Whitemeen太白17 小时前
查询子级分类、父级分类、叶子节点分类(MySQL / Oracle )
数据库·mysql·oracle
王仲肖1 天前
PostgreSQL 关系级锁 — 总结与优化指南
数据库·postgresql·oracle
云边有个稻草人1 天前
运营每次改数据都要等排期?我用飞牛NAS搭了个在线表格数据库,非技术也能自己管了
数据库·oracle
苏瞳儿1 天前
java对数据库的增删改查
java·数据库·oracle
程序边界2 天前
KingbaseES 表空间目录自动创建特性深度解析(下篇)
数据库·oracle
山峰哥2 天前
解锁SQL优化新境界:从索引策略到高效查询实战
数据库·sql·oracle
l1t2 天前
DeepSeek总结的Open DUMP Viewer for Oracle发版说明
数据库·oracle
oradh2 天前
Oracle数据库索引组织表概述
数据库·oracle·oracle基础·oracle索引组织表·索引组织表·iot表