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
- 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.
- 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
- 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;
/
- 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.
- 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
- 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
- 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>