数据泵(Data Pump)是Oracle从10g开始推出,并且不断强化以期替代原有exp/imp工具的数据迁移工具。在11g中,数据泵产品不断地强化功能和弥补缺陷,在原有的exp/imp功能基础上提供了更多的灵活空间。
分区表Partition Table是我们经常遇到的数据对象类型。在11g中,Data Pump提供了针对分区表的操作选项参数PARTITION_OPTION。借助这个新引入的参数,可以实现在导入过程中对数据表结构进行变化。
本篇主要集中介绍PARTITION_OPTION参数的选项值和使用方法。
1、参数介绍和环境介绍
从取值上看,PARTITION_OPTIONS参数包括三个可选值,Departition、Merge和None,用于指定导入分区表的转换方式。
PARTITION_OPTIONS
Specify how partitions should be transformed.
Valid keywords are: DEPARTITION, MERGE and [NONE].
默认情况下,该参数取值为NONE,表示不进行任何转换。如果是分区数据表,导入之后依然为分区数据表。Departition为分表操作,也就是将每个分区作为一个独立的数据表进行导入,导入之后可见与原数据表分区对应的数据表集合。
Merge参数是取消分区设置,将数据导入到一个非分区表的转换动作。
下面笔者使用11.2.0.4版本进行测试。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for 64-bit Windows: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 – Production
创建实验用户test,以及对应的权限信息。
SQL> create user test identified by test;
User created
SQL> grant select any dictionary to test;
Grant succeeded
SQL> grant resource, connect to test;
Grant succeeded
SQL> grant select_catalog_role to test;
Grant succeeded
在test用户下创建分区数据表t_part。
SQL> conn test/test@sicsdb
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0
Connected as test
SQL> create table t_part
2 (owner varchar2(100),
3 object_id number,
4 object_name varchar2(100))
5 partition by list (owner)
6 (
7 partition p1 values (‘SYS‘),
8 partition p2 values (‘PUBLIC‘),
9 partition p3 values (default)
10 );
Table created
SQL> insert into t_part select owner, object_id, object_name from dba_objects;
99695 rows inserted
SQL> commit;
Commit complete
分区表结构显示。
SQL> select table_name, partition_name, num_rows from user_tab_partitions;
TABLE_NAME PARTITION_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
T_PART P1
T_PART P2
T_PART P3
SQL> exec dbms_stats.gather_table_stats(user,‘T_PART‘,cascade => true);
PL/SQL procedure successfully completed
SQL> select table_name, partition_name, num_rows from user_tab_partitions;
TABLE_NAME PARTITION_NAME NUM_ROWS
------------------------------ ------------------------------ ----------
T_PART P1 37693
T_PART P2 33889
T_PART P3 28113
使用expdp导出数据。
C:\Users\Administrator.SICSENVIRONMENT>expdp \"/ as sysdba\" dumpfile=test.dmp schemas=test
Export: Release 11.2.0.4.0 - Production on Mon Dec 15 14:17:48 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
(篇幅原因,有省略……)
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."T_PART":"P1" 1.358 MB 37693 rows
. . exported "TEST"."T_PART":"P2" 1.356 MB 33889 rows
. . exported "TEST"."T_PART":"P3" 1012. KB 28113 rows
Master table "SYS"."SYS_EXPORT_SCHEMA_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_SCHEMA_01 is:
C:\APP\ADMINISTRATOR\ADMIN\SICSDB\DPDUMP\TEST.DMP
Job "SYS"."SYS_EXPORT_SCHEMA_01" successfully completed at Mon Dec 15 14:18:00 2
014 elapsed 0 00:00:10
2、Merge参数使用
Merge参数使用之后,会将原有分区表合并为一般数据表。
C:\Users\Administrator.SICSENVIRONMENT>impdp \"/ as sysdba\" dumpfile=test.dmp remap_table=test.t_part:t_merge partition_options=merge
Import: Release 11.2.0.4.0 - Production on Mon Dec 15 14:28:01 2014
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
(篇幅原因,有省略……)
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."T_MERGE":"P1" 1.358 MB 37693 rows
. . imported "TEST"."T_MERGE":"P2" 1.356 MB 33889 rows
. . imported "TEST"."T_MERGE":"P3" 1012. KB 28113 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYS"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Mon Dec 15 14:28:03
2014 elapsed 0 00:00:02
导入之后,数据schema段结构列表。
SQL> select segment_name, partition_name, segment_type, tablespace_name from user_segments;
SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME
--------------- --------------- -------------------- ------------------------------
T_MERGE TABLE USERS
T_PART P1 TABLE PARTITION USERS
T_PART P2 TABLE PARTITION USERS
T_PART P3 TABLE PARTITION USERS
新数据表t_merge被导入,而且作为普通数据表出现。
3、Departition参数
Departition参数作用是将分区表依据分区拆分为多个独立的数据表。
C:\Users\Administrator.SICSENVIRONMENT>impdp \"/ as sysdba\" dumpfile=test.dmp remap_table=test.t_part:t_depa partition_options=departition
Import: Release 11.2.0.4.0 - Production on Mon Dec 15 14:34:07 2014
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
(篇幅原因,有省略……)
Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATA
. . imported "TEST"."T_PART_P1" 1.358 MB 37693 rows
. . imported "TEST"."T_PART_P2" 1.356 MB 33889 rows
. . imported "TEST"."T_PART_P3" 1012. KB 28113 rows
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYS"."SYS_IMPORT_FULL_01" completed with 1 error(s) at Mon Dec 15 14:34:12
2014 elapsed 0 00:00:04
新数据表被建立。
SQL> select segment_name, partition_name, segment_type, tablespace_name from user_segments;
SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME
--------------- --------------- -------------------- ------------------------------
T_MERGE TABLE USERS
T_PART_P1 TABLE USERS
T_PART_P2 TABLE USERS
T_PART_P3 TABLE USERS
T_PART P1 TABLE PARTITION USERS
T_PART P2 TABLE PARTITION USERS
T_PART P3 TABLE PARTITION USERS
7 rows selected
4、结论
PARTITION_OPTIONS是11g数据泵提出的新功能选项,在一些特殊场景下,可以方便的帮助我们解决实际问题。从本质上看,这部分转换应该是在元数据导入过程中进行的转换转化。这样的功能提供了一定程度的灵活性。
使用PARTITION_OPTIONS参数控制数据泵分区表导入
原文:http://blog.itpub.net/17203031/viewspace-1368496/