实验环境:
11.1.0.6.0
对ANONYMOUSUSER_ALL表中分区进行备份
SQL> select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,PARTITION_POSITION,TABLESPACE_NAME from user_tab_partitions where TABLE_NAME='ANONYMOUSUSER_ALL';
TABLE_NAME PARTITION_NAM HIGH_VALUE PARTITION_POSITION TABLESPACE_NAME
------------------------- ------------- -------------------------------------------------------------------------------- ------------------ ------------------------------
ANONYMOUSUSER_ALL PART07_12 TO_DATE(' 2008-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 1 PART
ANONYMOUSUSER_ALL PART09_03 TO_DATE(' 2009-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 2 PART
ANONYMOUSUSER_ALL SYS_P11720 TO_DATE(' 2011-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 3 P4
ANONYMOUSUSER_ALL SYS_P11721 TO_DATE(' 2011-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 4 P5
ANONYMOUSUSER_ALL SYS_P11722 TO_DATE(' 2011-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 5 P3
ANONYMOUSUSER_ALL SYS_P11724 TO_DATE(' 2011-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 6 P5
ANONYMOUSUSER_ALL SYS_P11725 TO_DATE(' 2011-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 7 P3
ANONYMOUSUSER_ALL SYS_P11728 TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 8 P3
ANONYMOUSUSER_ALL SYS_P11729 TO_DATE(' 2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 9 P4
ANONYMOUSUSER_ALL SYS_P11731 TO_DATE(' 2012-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 10 P3
ANONYMOUSUSER_ALL SYS_P11732 TO_DATE(' 2012-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 11 P4
ANONYMOUSUSER_ALL SYS_P11733 TO_DATE(' 2012-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 12 P5
ANONYMOUSUSER_ALL SYS_P11755 TO_DATE(' 2012-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 13 P5
13 rows selected.
对SYS_P11720分区进行备份
SQL> select count(*) from ANONYMOUSUSER_ALL partition(SYS_P11720);
COUNT(*)
----------
25240
SQL> select CTIME from ANONYMOUSUSER_ALL where rownum<2;
CTIME
------------
01-JUN-11
使用exp导出SYS_P11720分区
[oracle@hou-test backup]$ exp part/part file=ANONYMOUSUSER_ALL_201106.dmp tables=ANONYMOUSUSER_ALL:SYS_P11720
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 06:56:49 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
EXP-00006: internal inconsistency error
EXP-00000: Export terminated unsuccessfully
出错,exp不支持11g分区表的新特性(ANONYMOUSUSER_ALL是11g的新特性interval分区),解决办法,采用数据泵expd
一、创建dump目录
create directory dump as '/home/oracle/backup';
grant read,write on directory dump to part;
二、备份
1.分区表全表备份
[oracle@hou-test backup]$ expdp part/part directory=dump dumpfile=ANONYMOUSUSER_ALL.dmp tables=ANONYMOUSUSER_ALL
Export: Release 11.1.0.6.0 - 64bit Production on Monday, 23 July, 2012 7:29:08
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, OLAP, Data Mining and Real Application Testing options
Starting "PART"."SYS_EXPORT_TABLE_01": part/******** directory=dump dumpfile=ANONYMOUSUSER_ALL.dmp tables=ANONYMOUSUSER_ALL
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 91.06 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11725" 13.71 MB 88534 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11724" 13.02 MB 83637 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11728" 11.18 MB 70963 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11722" 7.103 MB 45357 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11731" 6.251 MB 39730 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11732" 5.743 MB 36423 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11729" 4.575 MB 29288 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11720" 3.903 MB 25240 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11733" 3.645 MB 23010 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11721" 2.788 MB 17762 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11755" 10.68 KB 1 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"PART07_12" 0 KB 0 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"PART09_03" 0 KB 0 rows
Master table "PART"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for PART.SYS_EXPORT_TABLE_01 is:
/home/oracle/backup/ANONYMOUSUSER_ALL.dmp
Job "PART"."SYS_EXPORT_TABLE_01" successfully completed at 07:29:30
2备份一个分区
[oracle@hou-test backup]$ expdp part/part directory=dump dumpfile=ANONYMOUSUSER_ALL_201106.dmp tables=ANONYMOUSUSER_ALL:SYS_P11720
Export: Release 11.1.0.6.0 - 64bit Production on Monday, 23 July, 2012 7:34:15
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, OLAP, Data Mining and Real Application Testing options
Starting "PART"."SYS_EXPORT_TABLE_01": part/******** directory=dump dumpfile=ANONYMOUSUSER_ALL_201106.dmp tables=ANONYMOUSUSER_ALL:SYS_P11720
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 5 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11720" 3.903 MB 25240 rows
Master table "PART"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for PART.SYS_EXPORT_TABLE_01 is:
/home/oracle/backup/ANONYMOUSUSER_ALL_201106.dmp
Job "PART"."SYS_EXPORT_TABLE_01" successfully completed at 07:34:36
3.备份多个分区
SQL> select count(*) from ANONYMOUSUSER_ALL partition(SYS_P11721);
COUNT(*)
----------
17762
SQL> select ctime from ANONYMOUSUSER_ALL partition(SYS_P11721) where rownum<2;
CTIME
------------
01-JUL-11
[oracle@hou-test backup]$ expdp part/part directory=dump dumpfile=ANONYMOUSUSER_ALL_201106-201207.dmp tables=ANONYMOUSUSER_ALL:SYS_P11720,ANONYMOUSUSER_ALL:SYS_P11721
Export: Release 11.1.0.6.0 - 64bit Production on Monday, 23 July, 2012 7:39:03
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, OLAP, Data Mining and Real Application Testing options
Starting "PART"."SYS_EXPORT_TABLE_01": part/******** directory=dump dumpfile=ANONYMOUSUSER_ALL_201106-201207.dmp tables=ANONYMOUSUSER_ALL:SYS_P11720,ANONYMOUSUSER_ALL:SYS_P11721
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 9 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11720" 3.903 MB 25240 rows
. . exported "PART"."ANONYMOUSUSER_ALL":"SYS_P11721" 2.788 MB 17762 rows
Master table "PART"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for PART.SYS_EXPORT_TABLE_01 is:
/home/oracle/backup/ANONYMOUSUSER_ALL_201106-201207.dmp
Job "PART"."SYS_EXPORT_TABLE_01" successfully completed at 07:39:25
三、还原
1.分区表整表还原
[oracle@hou-test backup]$ impdp part/part directory=dump dumpfile=ANONYMOUSUSER_ALL.dmp tables=part.ANONYMOUSUSER_ALL
Import: Release 11.1.0.6.0 - 64bit Production on Monday, 23 July, 2012 11:54:54
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, OLAP, Data Mining and Real Application Testing options
Master table "PART"."SYS_IMPORT_TABLE_15" successfully loaded/unloaded
Starting "PART"."SYS_IMPORT_TABLE_15": part/******** directory=dump dumpfile=ANONYMOUSUSER_ALL.dmp tables=part.ANONYMOUSUSER_ALL
Processing object type TABLE_EXPORT/TABLE/TABLE
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.PUT_DDLS []
ORA-06502: PL/SQL: numeric or value error
LPX-00225: end-element tag "INSERT_TS_LIST_ITEM" does not match start-element tag "INTERVAL_STR"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.KUPW$WORKER", line 7704
----- PL/SQL Call Stack -----
object line object
handle number name
0x117526e10 18051 package body SYS.KUPW$WORKER
0x117526e10 7736 package body SYS.KUPW$WORKER
0x117526e10 15263 package body SYS.KUPW$WORKER
0x117526e10 3766 package body SYS.KUPW$WORKER
0x117526e10 8370 package body SYS.KUPW$WORKER
0x11725f6a8 1 anonymous block
0x1179235f8 1501 package body SYS.DBMS_SQL
0x117526e10 8201 package body SYS.KUPW$WORKER
0x117526e10 1477 package body SYS.KUPW$WORKER
0x10cd8ef10 2 anonymous block
ORA-39126: Worker unexpected fatal error in KUPW$WORKER.PUT_DDLS []
ORA-06502: PL/SQL: numeric or value error
LPX-00225: end-element tag "INSERT_TS_LIST_ITEM" does not match start-element tag "INTERVAL_STR"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 86
ORA-06512: at "SYS.KUPW$WORKER", line 7704
----- PL/SQL Call Stack -----
object line object
handle number name
0x117526e10 18051 package body SYS.KUPW$WORKER
0x117526e10 7736 package body SYS.KUPW$WORKER
0x117526e10 15263 package body SYS.KUPW$WORKER
0x117526e10 3766 package body SYS.KUPW$WORKER
0x117526e10 8370 package body SYS.KUPW$WORKER
0x117506638 1 anonymous block
0x1179235f8 1501 package body SYS.DBMS_SQL
0x117526e10 8201 package body SYS.KUPW$WORKER
0x117526e10 1477 package body SYS.KUPW$WORKER
0x10cd8ef10 2 anonymous block
Job "PART"."SYS_IMPORT_TABLE_15" stopped due to fatal error at 11:54:55
还原出错,通过metalink查到原因,这是11.1.0.6.0版本bug,升级到11.1.0.7.0能解决这个问题,但是生产库就是这个版本,不允许升级。
看来只有放弃interval partition方案了。
使用普通range分区,每个月一个分区,每个分区在一个表空间上
一、准备普通range分区表
创建表空间
2011-05
2011-06
2011-07
2011-08
2011-09
2011-10
2011-11
2011-12
2012-01
2012-02
2012-03
2012-04
2012-05
2012-06
2012-07
创建表空间
create tablespace p6 datafile '/u01/app/oradata/hou/p6.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p7 datafile '/u01/app/oradata/hou/p7.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p8 datafile '/u01/app/oradata/hou/p8.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p9 datafile '/u01/app/oradata/hou/p9.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p10 datafile '/u01/app/oradata/hou/p10.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p11 datafile '/u01/app/oradata/hou/p11.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p12 datafile '/u01/app/oradata/hou/p12.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p13 datafile '/u01/app/oradata/hou/p13.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p14 datafile '/u01/app/oradata/hou/p14.dbf' size 10M autoextend on next 10M maxsize 31G;
create tablespace p15 datafile '/u01/app/oradata/hou/p15.dbf' size 10M autoextend on next 10M maxsize 31G;
授予part用户使用表空间权限
SQL> select 'alter user part quota unlimited on '|| TABLESPACE_NAME||';' from dba_tablespaces where TABLESPACE_NAME like 'P%';
'ALTERUSERPARTQUOTAUNLIMITEDON'||TABLESPACE_NAME||';'
------------------------------------------------------------------
alter user part quota unlimited on P1;
alter user part quota unlimited on P10;
alter user part quota unlimited on P11;
alter user part quota unlimited on P12;
alter user part quota unlimited on P13;
alter user part quota unlimited on P14;
alter user part quota unlimited on P15;
alter user part quota unlimited on P2;
alter user part quota unlimited on P3;
alter user part quota unlimited on P4;
alter user part quota unlimited on P5;
alter user part quota unlimited on P6;
alter user part quota unlimited on P7;
alter user part quota unlimited on P8;
alter user part quota unlimited on P9;
建分区表
CREATE TABLE "ANONYMOUSUSER_ALL"
(
"ID" NUMBER,
"MD5ID" NVARCHAR2(32),
"CTIME" DATE,
"UTIME" DATE,
"CLIENT_TYPE" NVARCHAR2(10),
"CHANNEL" NVARCHAR2(20),
"SUB_CHANNEL" NVARCHAR2(20),
"TYPE" NVARCHAR2(10),
"PHONENUM" NVARCHAR2(20),
"PRODUCT_ID" NUMBER,
"CLIENT_ID" NUMBER,
"IP" NUMBER,
"IMEI" NVARCHAR2(20),
"UA" NVARCHAR2(100),
"SCREEN_SIZE" NUMBER,
CONSTRAINT "ANONYMOUSUSER_ADPLAN_PK" PRIMARY KEY ("ID")
)
partition by range(ctime)
(partition anony_all_2011_05 values less than (to_date('2011-06-01','yyyy-mm-dd')) tablespace p1,
partition anony_all_2011_06 values less than (to_date('2011-07-01','yyyy-mm-dd')) tablespace p2,
partition anony_all_2011_07 values less than (to_date('2011-08-01','yyyy-mm-dd')) tablespace p3,
partition anony_all_2011_08 values less than (to_date('2011-09-01','yyyy-mm-dd')) tablespace p4,
partition anony_all_2011_09 values less than (to_date('2011-10-01','yyyy-mm-dd')) tablespace p5,
partition anony_all_2011_10 values less than (to_date('2011-11-01','yyyy-mm-dd')) tablespace p6,
partition anony_all_2011_11 values less than (to_date('2011-12-01','yyyy-mm-dd')) tablespace p7,
partition anony_all_2011_12 values less than (to_date('2012-01-01','yyyy-mm-dd')) tablespace p8,
partition anony_all_2012_01 values less than (to_date('2012-02-01','yyyy-mm-dd')) tablespace p9,
partition anony_all_2012_02 values less than (to_date('2012-03-01','yyyy-mm-dd')) tablespace p10,
partition anony_all_2012_03 values less than (to_date('2012-04-01','yyyy-mm-dd')) tablespace p11,
partition anony_all_2012_04 values less than (to_date('2012-05-01','yyyy-mm-dd')) tablespace p12,
partition anony_all_2012_05 values less than (to_date('2012-06-01','yyyy-mm-dd')) tablespace p13,
partition anony_all_2012_06 values less than (to_date('2012-07-01','yyyy-mm-dd')) tablespace p14,
partition anony_all_2012_07 values less than (to_date('2012-08-01','yyyy-mm-dd')) tablespace p15
);
SQL> select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,PARTITION_POSITION,TABLESPACE_NAME from user_tab_partitions where TABLE_NAME='ANONYMOUSUSER_ALL';
TABLE_NAME PARTITION_NAME HIGH_VALUE PARTITION_POSITION TABLESPACE_NAME
-------------------- ------------------------------ -------------------------------------------------------------------------------- ------------------ ------------------------------
ANONYMOUSUSER_ALL ANONY_ALL_2011_05 TO_DATE(' 2011-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 1 P1
ANONYMOUSUSER_ALL ANONY_ALL_2011_06 TO_DATE(' 2011-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 2 P2
ANONYMOUSUSER_ALL ANONY_ALL_2011_07 TO_DATE(' 2011-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 3 P3
ANONYMOUSUSER_ALL ANONY_ALL_2011_08 TO_DATE(' 2011-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 4 P4
ANONYMOUSUSER_ALL ANONY_ALL_2011_09 TO_DATE(' 2011-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 5 P5
ANONYMOUSUSER_ALL ANONY_ALL_2011_10 TO_DATE(' 2011-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 6 P6
ANONYMOUSUSER_ALL ANONY_ALL_2011_11 TO_DATE(' 2011-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 7 P7
ANONYMOUSUSER_ALL ANONY_ALL_2011_12 TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 8 P8
ANONYMOUSUSER_ALL ANONY_ALL_2012_01 TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 9 P9
ANONYMOUSUSER_ALL ANONY_ALL_2012_02 TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 10 P10
ANONYMOUSUSER_ALL ANONY_ALL_2012_03 TO_DATE(' 2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 11 P11
ANONYMOUSUSER_ALL ANONY_ALL_2012_04 TO_DATE(' 2012-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 12 P12
ANONYMOUSUSER_ALL ANONY_ALL_2012_05 TO_DATE(' 2012-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 13 P13
ANONYMOUSUSER_ALL ANONY_ALL_2012_06 TO_DATE(' 2012-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 14 P14
ANONYMOUSUSER_ALL ANONY_ALL_2012_07 TO_DATE(' 2012-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA 15 P15
15 rows selected.
插入数据
declare
i number:=1;
begin
for rec in (select * from ANONYMOUSUSER_ANDROID ) loop
insert into ANONYMOUSUSER_ALL values rec;
if mod(i,10000) =0 then
commit;
end if;
i:=i+1;
end loop;
commit;
end;
/
SQL> exec DBMS_STATS.GATHER_TABLE_STATS(user,'ANONYMOUSUSER_ALL');
PL/SQL procedure successfully completed.
分区中都有数据了
SQL> select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,TABLESPACE_NAME,NUM_ROWS from user_tab_partitions where table_name='ANONYMOUSUSER_ALL';
TABLE_NAME PARTITION_NAME HIGH_VALUE TABLESPACE_NAME NUM_ROWS
-------------------- ------------------------------ -------------------------------------------------------------------------------- ------------------------------ ----------
ANONYMOUSUSER_ALL ANONY_ALL_2011_05 TO_DATE(' 2011-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P1 18465
ANONYMOUSUSER_ALL ANONY_ALL_2011_06 TO_DATE(' 2011-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P2 25240
ANONYMOUSUSER_ALL ANONY_ALL_2011_07 TO_DATE(' 2011-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P3 17762
ANONYMOUSUSER_ALL ANONY_ALL_2011_08 TO_DATE(' 2011-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P4 45357
ANONYMOUSUSER_ALL ANONY_ALL_2011_09 TO_DATE(' 2011-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P5 55854
ANONYMOUSUSER_ALL ANONY_ALL_2011_10 TO_DATE(' 2011-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P6 83637
ANONYMOUSUSER_ALL ANONY_ALL_2011_11 TO_DATE(' 2011-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P7 88534
ANONYMOUSUSER_ALL ANONY_ALL_2011_12 TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P8 56809
ANONYMOUSUSER_ALL ANONY_ALL_2012_01 TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P9 108626
ANONYMOUSUSER_ALL ANONY_ALL_2012_02 TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P10 70963
ANONYMOUSUSER_ALL ANONY_ALL_2012_03 TO_DATE(' 2012-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P11 29288
ANONYMOUSUSER_ALL ANONY_ALL_2012_04 TO_DATE(' 2012-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P12 44022
ANONYMOUSUSER_ALL ANONY_ALL_2012_05 TO_DATE(' 2012-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P13 39730
ANONYMOUSUSER_ALL ANONY_ALL_2012_06 TO_DATE(' 2012-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P14 36423
ANONYMOUSUSER_ALL ANONY_ALL_2012_07 TO_DATE(' 2012-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA P15 23010
二、备份
1.分区表整表备份还原
1.1 分区表全表备份
[oracle@hou-test backup]$ exp part/part file= ANONYMOUSUSER_ALL.dmp tables=ANONYMOUSUSER_ALL
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 13:03:15 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table ANONYMOUSUSER_ALL
. . exporting partition ANONY_ALL_2011_05 18465 rows exported
. . exporting partition ANONY_ALL_2011_06 25240 rows exported
. . exporting partition ANONY_ALL_2011_07 17762 rows exported
. . exporting partition ANONY_ALL_2011_08 45357 rows exported
. . exporting partition ANONY_ALL_2011_09 55854 rows exported
. . exporting partition ANONY_ALL_2011_10 83637 rows exported
. . exporting partition ANONY_ALL_2011_11 88534 rows exported
. . exporting partition ANONY_ALL_2011_12 56809 rows exported
. . exporting partition ANONY_ALL_2012_01 108626 rows exported
. . exporting partition ANONY_ALL_2012_02 70963 rows exported
. . exporting partition ANONY_ALL_2012_03 29288 rows exported
. . exporting partition ANONY_ALL_2012_04 44022 rows exported
. . exporting partition ANONY_ALL_2012_05 39730 rows exported
. . exporting partition ANONY_ALL_2012_06 36423 rows exported
. . exporting partition ANONY_ALL_2012_07 23010 rows exported
Export terminated successfully without warnings.
1.2 分区表全表还原
SQL> drop table ANONYMOUSUSER_ALL;
imp导入
[oracle@hou-test backup]$ imp part/part file=ANONYMOUSUSER_ALL.dmp tables=ANONYMOUSUSER_ALL
Import: Release 11.1.0.6.0 - Production on Mon Jul 23 13:06:13 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing PART's objects into PART
. importing PART's objects into PART
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_05" 18465 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_06" 25240 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_07" 17762 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_08" 45357 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_09" 55854 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_10" 83637 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_11" 88534 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_12" 56809 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_01" 108626 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_02" 70963 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_03" 29288 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_04" 44022 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_05" 39730 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_06" 36423 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2012_07" 23010 rows imported
Import terminated successfully without warnings.
2.分区表一个分区的备份还原
2.1备份一个分区
比如备份ANONY_ALL_2011_05分区
[oracle@hou-test backup]$ exp part/part file=ANONYMOUSUSER_ALL-ANONY_ALL_2011_05.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_05
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 13:16:07 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table ANONYMOUSUSER_ALL
. . exporting partition ANONY_ALL_2011_05 18465 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
导出时报错,解决办法1:
指定Linux系统的NLS_LANG环境变量为数据库的数据集
SQL> select userenv('language') from dual;
USERENV('LANGUAGE')
----------------------------------------------------
AMERICAN_AMERICA.ZHS16GBK
[oracle@hou-test backup]$ set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
[oracle@hou-test backup]$ export set NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
再次导出
[oracle@hou-test backup]$ exp part/part file=ANONYMOUSUSER_ALL-ANONY_ALL_2011_05.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_05
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 13:16:07 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table ANONYMOUSUSER_ALL
. . exporting partition ANONY_ALL_2011_05 18465 rows exported
EXP-00091: Exporting questionable statistics.
EXP-00091: Exporting questionable statistics.
Export terminated successfully with warnings.
依然报错,看来不大适用分区表
解决办法2:使用statistics=none,也就是不导出统计信息。
[oracle@hou-test backup]$ exp part/part file=ANONYMOUSUSER_ALL-ANONY_ALL_2011_05.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_05 statistics=none
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 13:40:34 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table ANONYMOUSUSER_ALL
. . exporting partition ANONY_ALL_2011_05 18465 rows exported
Export terminated successfully without warnings.
2.2还原一个分区
truncate ANONY_ALL_2011_05分区
SQL> alter table ANONYMOUSUSER_ALL truncate partition ANONY_ALL_2011_05 update indexes;
Table truncated.
还原
[oracle@hou-test backup]$ imp part/part file=ANONYMOUSUSER_ALL-ANONY_ALL_2011_05.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_05 ignore=y
Import: Release 11.1.0.6.0 - Production on Mon Jul 23 13:55:39 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing PART's objects into PART
. importing PART's objects into PART
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_05" 18465 rows imported
Import terminated successfully without warnings.
3.同时备份和还原多个分区
2.1备份多个分区,ANONYMOUSUSER_ALL的ANONY_ALL_2011_07和ANONY_ALL_2011_08分区。
[oracle@hou-test backup]$ exp part/part file=ANONY_ALL_2011_07-ANONY_ALL_2011_08.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_07,ANONYMOUSUSER_ALL:ANONY_ALL_2011_08 statistics=none
Export: Release 11.1.0.6.0 - Production on Mon Jul 23 14:02:38 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export done in ZHS16GBK character set and AL16UTF16 NCHAR character set
About to export specified tables via Conventional Path ...
. . exporting table ANONYMOUSUSER_ALL
. . exporting partition ANONY_ALL_2011_07 17762 rows exported
. . exporting partition ANONY_ALL_2011_08 45357 rows exported
Export terminated successfully without warnings.
2.2导入多个分区
truncate这两个分区
SQL> alter table ANONYMOUSUSER_ALL truncate partition ANONY_ALL_2011_07 update indexes;
Table truncated.
SQL> alter table ANONYMOUSUSER_ALL truncate partition ANONY_ALL_2011_08 update indexes;
Table truncated.
导入
[oracle@hou-test backup]$ imp part/part file=ANONY_ALL_2011_07-ANONY_ALL_2011_08.dmp tables=ANONYMOUSUSER_ALL:ANONY_ALL_2011_07,ANONYMOUSUSER_ALL:ANONY_ALL_2011_08 ignore=y
Import: Release 11.1.0.6.0 - Production on Mon Jul 23 14:15:29 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Export file created by EXPORT:V11.01.00 via conventional path
import done in ZHS16GBK character set and AL16UTF16 NCHAR character set
. importing PART's objects into PART
. importing PART's objects into PART
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_07" 17762 rows imported
. . importing partition "ANONYMOUSUSER_ALL":"ANONY_ALL_2011_08" 45357 rows imported
Import terminated successfully without warnings.