expdp怎么expdp 导出多个分区分区表的某些分区

expdp导出多路径
一、前言:
有的用户DBA水平不是太高,不会使用RMAN进行备份恢复,如果对现场的工程师或用户进行RMAN的这样将会导致额外的开销以及导致一些不必要的麻烦。如果在用户
对数据恢复要求不是特别高的情况下,或者做异机恢复的时候expdp/impdp 则是一个比较不错的选择。
如果在RAC环境下,用户需要多份备份的情况下,那么我们可以通过expdp 的多路径备份来实现在ASM上备份一份,同时在本地备份一份,或者还可以在NAS共享盘上备一份,
这样就可以完美的解决任意一台服务器或存储损坏都能实现数据恢复。
如下是我的测试过程,根据实际情况修改目录即可:
我这是测试环境,生产环境也类似,只需修改目录即可,(ASM路径写法: +DISKGROUP_NAME/DIRPATH)
二、创建相关目录并赋予权限
[root@source DBData]# cd /
[root@source /]# cd DBBackup/
[root@source DBBackup]# ls
[root@source DBBackup]# mkdir expdp1
[root@source DBBackup]# mkdir expdp2
[root@source DBBackup]# chown -R oracle:oinstall expdp1
[root@source DBBackup]# chown -R oracle:oinstall expdp2
[root@source DBBackup]# ll
drwxr-xr-x 2 oracle oinstall 4096 Sep 5 13:33 expdp1
drwxr-xr-x 2 oracle oinstall 4096 Sep 5 13:33 expdp2
三、进入做directory及赋予权限&
[root@source DBBackup]# su - oracle
[oracle@source ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Sep 5 13:34:12 2014
Copyright (c) , . All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL& create directory expdp1 as \
四、开始执行导出
[oracle@source expdp1]$ expdp ggs/ggs dumpfile=expdp1:ggs001.dmp,expdp2:ggs001.dmp parallel=2
Export: Release 11.2.0.4.0 - Production on Fri Sep 5 13:43:14 2014
Copyright (c) , Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
FLASHBACK automatically enabled to preserve database integrity.
Starting \2009年11月 Oracle大版内专家分月排行榜第二2009年10月 Oracle大版内专家分月排行榜第二
2009年5月 Oracle大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。Oracle 分区表 导出导入 迁移 - CSDN博客
Oracle 分区表 导出导入 迁移
在Blog&:分区表总结 里提到一种创建分区表的方法。使用导出导入。
&&&&&&&Oracle&分区表&总结
这种方法的步骤是:
(1)将普通表dump出来
(2)创建分区表
(3)将dump&文件导入数据。
分区表的迁移和这个步骤差不多。有2点要注意:
&(1)分区表导出的dump&文件比普通表导出的大。
&(2)导入分区表的时间要比普通表的时间要长。
补充一些exp/imp,expdp/impdp&与分区表有关的知识:使用exp -help&查看:
example:&imp&scott/tiger ignore=y tables=(emp,dept) full=n
&&&&&&&&&&&&&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned table
example:&exp&scott/tiger grants=y tables=(emp,dept,mgr)
&&&&&&&&&&&&&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned table
example:&expdp&scott/tiger dumpfile=scott.dmp directory=dmpdir schemas=scott&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned table
example:&impdp&scott/tiger directory=dmpdir dumpfile=scott.dmp
一些优化参考Blog:
&&&&&&&exp/imp&与&expdp/impdp&对比&及使用中的一些优化事项
迁移分区表的步骤如下:
(1)导出分区表,可以使用exp或者expdp
(2)建立新的分区表
(3)导入分区表。
&&&&&&&A)如果是imp,加ignore=y&参数,该参数会忽略创建表时的错误并继续加载数据。
&&&&&&&B)如果是impdp,加&table_exists_action=append参数.
&&&&&&&&table_exists_action:&action to take if imported object already exists.&valid keywords: (skip), append, replace and truncate.
示例1:使用exp/imp
create table pdba (id, time) partition by range (time)
(partition p1 values less than (to_date('', 'yyyy-mm-dd')),
partition p2 values less than (to_date('', 'yyyy-mm-dd')),
partition p3 values less than (to_date('', 'yyyy-mm-dd')),
partition p4 values less than (maxvalue))
as select id, time from sys.
SQL& select partition_name from user_tab_partitions where table_name='PDBA';
PARTITION_NAME
------------------------------
SQL& select count(*) from pdba partition(p1);
&&COUNT(*)
----------
&&&1718285
SQL& select count(*) from pdba partition(p2);
&&COUNT(*)
----------
&&&&183667
SQL& select count(*) from pdba partition(p3);
&&COUNT(*)
----------
&&&&188701
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&622582
1.&导出表或者某个分区
(1)导出整个表:
C:/Users/Administrator.DavidDai&exp 'sys/sys as sysdba' tables=pdba file='d:/partition.dmp' log='d:/partition.log'
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:29:42 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集
即将导出指定的表通过常规路径...
. .&正在导出表&&&&&&&&&&&&&&&&&&&&&&&&&&&&PDBA
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P1导出了&&&&&1718285&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P2导出了&&&&&&183667&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P3导出了&&&&&&188701&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P4导出了&&&&&&622582&行
成功终止导出,&没有出现警告。
(2)导出某个分区:
C:/Users/Administrator.DavidDai&exp 'sys/sys as sysdba' tables=pdba:p4 file='d:/partition_p4.dmp' log='d:/partition_p4.log'
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:30:09 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集
即将导出指定的表通过常规路径...
. .&正在导出表&&&&&&&&&&&&&&&&&&&&&&&&&&&&PDBA
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P4导出了&&&&&&622582&行
成功终止导出,&没有出现警告。
说明:开始用的分区表是11g的Interval&分区表,结果用exp导,报:
EXP-00006: internal inconsistency error
EXP-00000: Export terminated unsuccessfully
exp&不支持11g的新特性。参考:
&&&&&&&Exporting System or Composite Partitioned Table Using Classic Export Gives EXP-6 AND EXP-0 [ID ]
2.&创建分区表
2.1&可以使用一下语句获取表的DDL语句:
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES
更多参考:
ORACLE&使用DBMS_METADATA.GET_DDL获取DDL语句
2.2&使用imp&语句获取:
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba&indexfile='D:/table.sql'&file='d:/partition.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:49:47 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
. .&正在跳过分区&&PDBA&:&P1&
. .&正在跳过分区&&PDBA&:&P2&
. .&正在跳过分区&&PDBA&:&P3&
. .&正在跳过分区&&PDBA&:&P4&
成功终止导入,&没有出现警告。
这里我们在imp上加了个参数:indexfile='D:/table.sql',这条imp语句只会在对应的文件里生成分区表的ddl&语句。&然后编辑创建好就可以了。
最简单的方法就是使用第三方的工具,如Toad,直接就能查到表的定义语句了。
3.&导入分区数据
&&&&&&&我们在第一步导出里做了2种,一个是导出全表,另一个是导出一个分区。我们分别导入验证。
3.1&导入一个分区
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba:p4 file='d:/partition_p4.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:58:27 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
.&正在将&SYS&的对象导入到&SYS
.&正在将&SYS&的对象导入到&SYS
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P4&导入了&&&&&&622582&行
成功终止导入,&没有出现警告。
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&622582
SQL& select count(*) from pdba partition(p1);
&&COUNT(*)
----------
3.2&导入整个表
导入之前先把P4分区的数据truncate掉:
SQL& alter table pdba truncate partition p4;
表被截断。
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&&&&&&0
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba file='d:/partition.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:01:08 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
.&正在将&SYS&的对象导入到&SYS
.&正在将&SYS&的对象导入到&SYS
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P1&导入了&&&&&1718285&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P2&导入了&&&&&&183667&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P3&导入了&&&&&&188701&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P4&导入了&&&&&&622582&行
成功终止导入,&没有出现警告。
示例2:使用expdp/impdp
1.&导出dump文件
create directory dump as 'd:/backup';
grant read, write on dire
(1)整个表
C:/Users/Administrator.DavidDai&Expdp system/system DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=exp.
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:18:15 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动&&SYSTEM&.&SYS_EXPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=exp.
正在使用&BLOCKS&方法进行估计...
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
使用&BLOCKS&方法的总估计: 61 MB
处理对象类型&TABLE_EXPORT/TABLE/TABLE
处理对象类型&TABLE_EXPORT/TABLE/PRE_TABLE_ACTION
. .&导出了&&SYSTEM&.&PDBA&:&P1&&&&&&&&&&&&&&&&&&&&&&&&&31.12 MB 1718285&行
. .&导出了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
. .&导出了&&SYSTEM&.&PDBA&:&P3&&&&&&&&&&&&&&&&&&&&&&&&&3.422 MB&&188701&行
. .&导出了&&SYSTEM&.&PDBA&:&P2&&&&&&&&&&&&&&&&&&&&&&&&&3.331 MB&&183667&行
已成功加载/卸载了主表&&SYSTEM&.&SYS_EXPORT_TABLE_01&
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_01&的转储文件集为:
&&D:/BACKUP/PARTITION.DMP
作业&&SYSTEM&.&SYS_EXPORT_TABLE_01&&已于&16:18:34&成功完成
(2)一个分区
C:/Users/Administrator.DavidDai&Expdp system/system DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA:P4 logfile=exp_p4.
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:19:23 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动&&SYSTEM&.&SYS_EXPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA:P4 logfile=exp_p4.
正在使用&BLOCKS&方法进行估计...
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
使用&BLOCKS&方法的总估计: 14 MB
处理对象类型&TABLE_EXPORT/TABLE/TABLE
处理对象类型&TABLE_EXPORT/TABLE/PRE_TABLE_ACTION
. .&导出了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
已成功加载/卸载了主表&&SYSTEM&.&SYS_EXPORT_TABLE_01&
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_01&的转储文件集为:
&&D:/BACKUP/PARTITION_P4.DMP
作业&&SYSTEM&.&SYS_EXPORT_TABLE_01&&已于&16:19:32&成功完成
2.&创建分区表
用dbms_metadate.get_ddl()&直接获取就可以了,方法同示例1.
3.&导入dump文件
(1)导入一个分区
C:/Users/Administrator.DavidDai&impdp system/system DIRECTORY=dump DUMPFILE=partition_p4.dmp&TABLES=PDBA:P4&logfile=imp_p4.log&table_exists_action=append
--&注意这个参数,后面不用加分号,直接回车就执行了。
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:24:15 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表&&SYSTEM&.&SYS_IMPORT_TABLE_01&
启动&&SYSTEM&.&SYS_IMPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA logfile=imp_p4.log table_exists_action=append
处理对象类型&TABLE_EXPORT/TABLE/TABLE
ORA-39152:&表&&SYSTEM&.&PDBA&&已存在。由于附加了&table_exists_action,&数据将附加到现有表,&但是将跳过所有相关元数据。
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
. .&导入了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
作业&&SYSTEM&.&SYS_IMPORT_TABLE_01&&已经完成,&但是有&1&个错误&(于&16:24:21&完成)
(2)导入整个表
C:/Users/Administrator.DavidDai&impdp system/system DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=imp.log table_exists_action=append
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:26:51 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表&&SYSTEM&.&SYS_IMPORT_TABLE_01&
启动&&SYSTEM&.&SYS_IMPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=imp.log table_exists_action=append
处理对象类型&TABLE_EXPORT/TABLE/TABLE
ORA-39152:&表&&SYSTEM&.&PDBA&&已存在。由于附加了&table_exists_action,&数据将附加到现有表,&但是将跳过所有相关元数据。
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
. .&导入了&&SYSTEM&.&PDBA&:&P1&&&&&&&&&&&&&&&&&&&&&&&&&31.12 MB 1718285&行
. .&导入了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
. .&导入了&&SYSTEM&.&PDBA&:&P3&&&&&&&&&&&&&&&&&&&&&&&&&3.422 MB&&188701&行
. .&导入了&&SYSTEM&.&PDBA&:&P2&&&&&&&&&&&&&&&&&&&&&&&&&3.331 MB&&183667&行
作业&&SYSTEM&.&SYS_IMPORT_TABLE_01&&已经完成,&但是有&1&个错误&(于&16:27:02&完成)
------------------------------------------------------------------------------
Blog:&http://blog.csdn.net/tianlesoftware
网上资源:&http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive//4886500.aspx
DBA1&群:(满); DBA2&群:(满)
DBA3&群:&&&DBA&超级群:;&&&&
--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请
在Blog&:分区表总结 里提到一种创建分区表的方法。使用导出导入。
&&&&&&&Oracle&分区表&总结
这种方法的步骤是:
(1)将普通表dump出来
(2)创建分区表
(3)将dump&文件导入数据。
分区表的迁移和这个步骤差不多。有2点要注意:
&(1)分区表导出的dump&文件比普通表导出的大。
&(2)导入分区表的时间要比普通表的时间要长。
补充一些exp/imp,expdp/impdp&与分区表有关的知识:使用exp -help&查看:
example:&imp&scott/tiger ignore=y tables=(emp,dept) full=n
&&&&&&&&&&&&&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned table
example:&exp&scott/tiger grants=y tables=(emp,dept,mgr)
&&&&&&&&&&&&&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned table
example:&expdp&scott/tiger dumpfile=scott.dmp directory=dmpdir schemas=scott&&&or&tables=(t1:p1,t1:p2), if t1 is partitioned
example:&impdp&scott/tiger directory=dmpdir dumpfile=scott.dmp
一些优化参考Blog:
&&&&&&&exp/imp&与&expdp/impdp&对比&及使用中的一些优化事项
迁移分区表的步骤如下:
(1)导出分区表,可以使用exp或者expdp
(2)建立新的分区表
(3)导入分区表。
&&&&&&&A)如果是imp,加ignore=y&参数,该参数会忽略创建表时的错误并继续加载数据。
&&&&&&&B)如果是impdp,加&table_exists_action=append参数.
&&&&&&&&table_exists_action:&action to take if imported object already exists.&valid keywords: (skip), append, replace and truncate.
示例1:使用exp/imp
create table pdba (id, time) partition by range (time)
(partition p1 values less than (to_date('', 'yyyy-mm-dd')),
partition p2 values less than (to_date('', 'yyyy-mm-dd')),
partition p3 values less than (to_date('', 'yyyy-mm-dd')),
partition p4 values less than (maxvalue))
as select id, time from sys.
SQL& select partition_name from user_tab_partitions where table_name='PDBA';
PARTITION_NAME
------------------------------
SQL& select count(*) from pdba partition(p1);
&&COUNT(*)
----------
&&&1718285
SQL& select count(*) from pdba partition(p2);
&&COUNT(*)
----------
&&&&183667
SQL& select count(*) from pdba partition(p3);
&&COUNT(*)
----------
&&&&188701
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&622582
1.&导出表或者某个分区
(1)导出整个表:
C:/Users/Administrator.DavidDai&exp 'sys/sys as sysdba' tables=pdba file='d:/partition.dmp' log='d:/partition.log'
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:29:42 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集
即将导出指定的表通过常规路径...
. .&正在导出表&&&&&&&&&&&&&&&&&&&&&&&&&&&&PDBA
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P1导出了&&&&&1718285&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P2导出了&&&&&&183667&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P3导出了&&&&&&188701&行
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P4导出了&&&&&&622582&行
成功终止导出,&没有出现警告。
(2)导出某个分区:
C:/Users/Administrator.DavidDai&exp 'sys/sys as sysdba' tables=pdba:p4 file='d:/partition_p4.dmp' log='d:/partition_p4.log'
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:30:09 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已导出&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集
即将导出指定的表通过常规路径...
. .&正在导出表&&&&&&&&&&&&&&&&&&&&&&&&&&&&PDBA
. .&正在导出分区&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&P4导出了&&&&&&622582&行
成功终止导出,&没有出现警告。
说明:开始用的分区表是11g的Interval&分区表,结果用exp导,报:
EXP-00006: internal inconsistency error
EXP-00000: Export terminated unsuccessfully
exp&不支持11g的新特性。参考:
&&&&&&&Exporting System or Composite Partitioned Table Using Classic Export Gives EXP-6 AND EXP-0 [ID ]
2.&创建分区表
2.1&可以使用一下语句获取表的DDL语句:
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES
更多参考:
ORACLE&使用DBMS_METADATA.GET_DDL获取DDL语句
2.2&使用imp&语句获取:
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba&indexfile='D:/table.sql'&file='d:/partition.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:49:47 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
. .&正在跳过分区&&PDBA&:&P1&
. .&正在跳过分区&&PDBA&:&P2&
. .&正在跳过分区&&PDBA&:&P3&
. .&正在跳过分区&&PDBA&:&P4&
成功终止导入,&没有出现警告。
这里我们在imp上加了个参数:indexfile='D:/table.sql',这条imp语句只会在对应的文件里生成分区表的ddl&语句。&然后编辑创建好就可以了。
最简单的方法就是使用第三方的工具,如Toad,直接就能查到表的定义语句了。
3.&导入分区数据
&&&&&&&我们在第一步导出里做了2种,一个是导出全表,另一个是导出一个分区。我们分别导入验证。
3.1&导入一个分区
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba:p4 file='d:/partition_p4.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 15:58:27 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
.&正在将&SYS&的对象导入到&SYS
.&正在将&SYS&的对象导入到&SYS
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P4&导入了&&&&&&622582&行
成功终止导入,&没有出现警告。
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&622582
SQL& select count(*) from pdba partition(p1);
&&COUNT(*)
----------
3.2&导入整个表
导入之前先把P4分区的数据truncate掉:
SQL& alter table pdba truncate partition p4;
表被截断。
SQL& select count(*) from pdba partition(p4);
&&COUNT(*)
----------
&&&&&&&&&0
C:/Users/Administrator.DavidDai&imp 'sys/sys as sysdba' tables=pdba file='d:/partition.dmp' ignore=y
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:01:08 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
经由常规路径由&EXPORT:V11.02.00&创建的导出文件
已经完成&ZHS16GBK&字符集和&AL16UTF16 NCHAR&字符集中的导入
.&正在将&SYS&的对象导入到&SYS
.&正在将&SYS&的对象导入到&SYS
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P1&导入了&&&&&1718285&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P2&导入了&&&&&&183667&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P3&导入了&&&&&&188701&行
. .&正在导入分区&&&&&&&&&&&&&&&&&&&&&&PDBA&:&P4&导入了&&&&&&622582&行
成功终止导入,&没有出现警告。
示例2:使用expdp/impdp
1.&导出dump文件
create directory dump as 'd:/backup';
grant read, write on dire
(1)整个表
C:/Users/Administrator.DavidDai&Expdp system/system DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=exp.
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:18:15 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动&&SYSTEM&.&SYS_EXPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=exp.
正在使用&BLOCKS&方法进行估计...
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
使用&BLOCKS&方法的总估计: 61 MB
处理对象类型&TABLE_EXPORT/TABLE/TABLE
处理对象类型&TABLE_EXPORT/TABLE/PRE_TABLE_ACTION
. .&导出了&&SYSTEM&.&PDBA&:&P1&&&&&&&&&&&&&&&&&&&&&&&&&31.12 MB 1718285&行
. .&导出了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
. .&导出了&&SYSTEM&.&PDBA&:&P3&&&&&&&&&&&&&&&&&&&&&&&&&3.422 MB&&188701&行
. .&导出了&&SYSTEM&.&PDBA&:&P2&&&&&&&&&&&&&&&&&&&&&&&&&3.331 MB&&183667&行
已成功加载/卸载了主表&&SYSTEM&.&SYS_EXPORT_TABLE_01&
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_01&的转储文件集为:
&&D:/BACKUP/PARTITION.DMP
作业&&SYSTEM&.&SYS_EXPORT_TABLE_01&&已于&16:18:34&成功完成
(2)一个分区
C:/Users/Administrator.DavidDai&Expdp system/system DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA:P4 logfile=exp_p4.
Export: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:19:23 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
启动&&SYSTEM&.&SYS_EXPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA:P4 logfile=exp_p4.
正在使用&BLOCKS&方法进行估计...
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
使用&BLOCKS&方法的总估计: 14 MB
处理对象类型&TABLE_EXPORT/TABLE/TABLE
处理对象类型&TABLE_EXPORT/TABLE/PRE_TABLE_ACTION
. .&导出了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
已成功加载/卸载了主表&&SYSTEM&.&SYS_EXPORT_TABLE_01&
******************************************************************************
SYSTEM.SYS_EXPORT_TABLE_01&的转储文件集为:
&&D:/BACKUP/PARTITION_P4.DMP
作业&&SYSTEM&.&SYS_EXPORT_TABLE_01&&已于&16:19:32&成功完成
2.&创建分区表
用dbms_metadate.get_ddl()&直接获取就可以了,方法同示例1.
3.&导入dump文件
(1)导入一个分区
C:/Users/Administrator.DavidDai&impdp system/system DIRECTORY=dump DUMPFILE=partition_p4.dmp&TABLES=PDBA:P4&logfile=imp_p4.log&table_exists_action=append
--&注意这个参数,后面不用加分号,直接回车就执行了。
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:24:15 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表&&SYSTEM&.&SYS_IMPORT_TABLE_01&
启动&&SYSTEM&.&SYS_IMPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition_p4.dmp TABLES=PDBA logfile=imp_p4.log table_exists_action=append
处理对象类型&TABLE_EXPORT/TABLE/TABLE
ORA-39152:&表&&SYSTEM&.&PDBA&&已存在。由于附加了&table_exists_action,&数据将附加到现有表,&但是将跳过所有相关元数据。
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
. .&导入了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
作业&&SYSTEM&.&SYS_IMPORT_TABLE_01&&已经完成,&但是有&1&个错误&(于&16:24:21&完成)
(2)导入整个表
C:/Users/Administrator.DavidDai&impdp system/system DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=imp.log table_exists_action=append
Import: Release 11.2.0.1.0 - Production on&星期四&3月&3 16:26:51 2011
Copyright (c) , Oracle and/or its affiliates.&&All rights reserved.
连接到: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
已成功加载/卸载了主表&&SYSTEM&.&SYS_IMPORT_TABLE_01&
启动&&SYSTEM&.&SYS_IMPORT_TABLE_01&:&&system/******** DIRECTORY=dump DUMPFILE=partition.dmp TABLES=PDBA logfile=imp.log table_exists_action=append
处理对象类型&TABLE_EXPORT/TABLE/TABLE
ORA-39152:&表&&SYSTEM&.&PDBA&&已存在。由于附加了&table_exists_action,&数据将附加到现有表,&但是将跳过所有相关元数据。
处理对象类型&TABLE_EXPORT/TABLE/TABLE_DATA
. .&导入了&&SYSTEM&.&PDBA&:&P1&&&&&&&&&&&&&&&&&&&&&&&&&31.12 MB 1718285&行
. .&导入了&&SYSTEM&.&PDBA&:&P4&&&&&&&&&&&&&&&&&&&&&&&&&11.28 MB&&622582&行
. .&导入了&&SYSTEM&.&PDBA&:&P3&&&&&&&&&&&&&&&&&&&&&&&&&3.422 MB&&188701&行
. .&导入了&&SYSTEM&.&PDBA&:&P2&&&&&&&&&&&&&&&&&&&&&&&&&3.331 MB&&183667&行
作业&&SYSTEM&.&SYS_IMPORT_TABLE_01&&已经完成,&但是有&1&个错误&(于&16:27:02&完成)
------------------------------------------------------------------------------
Blog:&http://blog.csdn.net/tianlesoftware
网上资源:&http://tianlesoftware.download.csdn.net
相关视频:http://blog.csdn.net/tianlesoftware/archive//4886500.aspx
DBA1&群:(满); DBA2&群:(满)
DBA3&群:&&&DBA&超级群:;&&&&
--加群需要在备注说明Oracle表空间和数据文件的关系,否则拒绝申请
本文已收录于以下专栏:
相关文章推荐
在Blog :分区表总结 里提到一种创建分区表的方法。使用导出导入。
       Oracle 分区表 总结
       ...
在Blog :分区表总结 里提到一种创建分区表的方法。使用导出导入。       Oracle 分区表总结       http://blog.csdn.net/tianlesof...
--****************************-- 导入导出 Oracle 分区表数据--****************************        导入导入Oracle 分...
今天接到一个需求,需要对一张普通的大表(数据量3000W)进行优化,目标按时间保留2000W左右的数据量,建成分区表。
--导出表的部分数据
expdp system/**** dir...
http://www.itpub.net/thread--1.html
http://tomszrp.itpub.net/post/
从11.2.0...
相关链接:
Hive基础一(数据库,表,分区表,视图,导入导出数据)
Hive基础二(join原理和机制,join的几种类型,数据倾斜简单处理)
Hive基础三(查询中常用的语法)注意Hive版...
一、分区级别的导入导出
    可以导出一个或多个分区,也可以导出所有分区(即整个表)。
    可以导入所有分区(即整个表),一个或多个分区以及子分区。
    对于已经存...
SQL& l  1  create table y_p (part_id number,id number,name varchar2(10))  2  partition by range (par...
随着数据库数据量的不断增长,有些表需要由普通的堆表转换为分区表的模式。有几种不同的方法来对此进行操作,诸如导出表数据,然后创建分区表再导入数据到分区表;使用EXCHANGE PARTITION方式来转...
他的最新文章
讲师:宋宝华
讲师:何宇健
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)

我要回帖

更多关于 mysql导出分区表数据 的文章

 

随机推荐