ITPub博客

首页 > 数据库 > Oracle > [20150729]数据泵造成的数据损失2.txt

[20150729]数据泵造成的数据损失2.txt

原创 Oracle 作者:lfree 时间:2015-07-29 09:13:29 1 删除 编辑

[20150729]数据泵造成的数据损失2.txt

--前一阵子,重复测试:
http://blog.itpub.net/267265/viewspace-1725204/

--参看链接,重复测试http://yangtingkun.net/?p=652

1.建立测试环境:
SCOTT@test> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production


CREATE TABLE T_PART PARTITION BY RANGE (CREATED)
(PARTITION P1 VALUES LESS THAN (TO_DATE('2012-1-1', 'YYYY-MM-DD')),
PARTITION P2 VALUES LESS THAN (TO_DATE('2012-2-1', 'YYYY-MM-DD')),
PARTITION P3 VALUES LESS THAN (TO_DATE('2012-3-1', 'YYYY-MM-DD')),
PARTITION P4 VALUES LESS THAN (TO_DATE('2012-4-1', 'YYYY-MM-DD')),
PARTITION PMAX VALUES LESS THAN (MAXVALUE))
AS SELECT * FROM DBA_OBJECTS;


SCOTT@test> select count(*) from t_part partition (p1);
  COUNT(*)
----------
     67590

SCOTT@test> select count(*) from t_part partition (p2);
  COUNT(*)
----------
       115

SCOTT@test> select count(*) from t_part partition (p3);
  COUNT(*)
----------
         9

SCOTT@test> select count(*) from t_part partition (p4);
  COUNT(*)
----------
        31

SCOTT@test> select count(*) from t_part partition (pmax);
  COUNT(*)
----------
     10082


$ expdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part.log tables=t_part:p3,t_part:p4

Export: Release 11.2.0.3.0 - Production on Wed Jul 29 08:50:35 2015

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SCOTT"."SYS_EXPORT_TABLE_01":  scott/a******* directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part.log tables=t_part:p3,t_part:p4
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 16 MB
Processing object type TABLE_EXPORT/TABLE/TABLE
. . exported "SCOTT"."T_PART":"P3"                       11.49 KB       9 rows
. . exported "SCOTT"."T_PART":"P4"                       13.89 KB      31 rows
Master table "SCOTT"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SCOTT.SYS_EXPORT_TABLE_01 is:
  /u01/app/oracle11g/admin/test/dpdump/t_part.dmp
Job "SCOTT"."SYS_EXPORT_TABLE_01" successfully completed at 08:51:03

--上次我使用如下命令会导致其它分区的信息删除。这次不做了,参考:
http://blog.itpub.net/267265/viewspace-1725204/

2.导入1个分区:
impdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p3 table_exists_action=replace

--实际上imdpd导入分区也存在如下参数:
PARTITION_OPTIONS
Specify how partitions should be transformed.
Valid keywords are: DEPARTITION, MERGE and [NONE].

--缺省是NONE,这样会导出其它分区的信息破坏。加入参数PARTITION_OPTIONS=DEPARTITION看看:

impdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p3 table_exists_action=replace PARTITION_OPTIONS=DEPARTITION

$ impdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p3 table_exists_action=replace PARTITION_OPTIONS=DEPARTITION
Import: Release 11.2.0.3.0 - Production on Wed Jul 29 08:55:03 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/x******* directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p3 table_exists_action=replace PARTITION_OPTIONS=DEPARTITION
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."T_PART_P3"                         11.49 KB       9 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 08:55:11

--如果你仔细看imported 那行,可以发现实际上是建立了一个新表SCOTT.T_PART_P3.
SCOTT@test> select count(*) from t_part_p3;
  COUNT(*)
----------
         9
SCOTT@test> select count(*) from t_part;
  COUNT(*)
----------
     77827

--看看要好好理解PARTITION_OPTIONS的含义。原来t_part并没有变化。

3.做一次merge看看。

impdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p4 table_exists_action=replace PARTITION_OPTIONS=MERGE

$ impdp scott/btbtms directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p4 table_exists_action=replace PARTITION_OPTIONS=MERGE

Import: Release 11.2.0.3.0 - Production on Wed Jul 29 09:10:04 2015
Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Master table "SCOTT"."SYS_IMPORT_TABLE_01" successfully loaded/unloaded
Starting "SCOTT"."SYS_IMPORT_TABLE_01":  scott/a******* directory=DATA_PUMP_DIR dumpfile=t_part.dmp logfile=t_part_imp.log tables=t_part:p4 table_exists_action=replace PARTITION_OPTIONS=MERGE
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
. . imported "SCOTT"."T_PART":"P4"                       13.89 KB      31 rows
Job "SCOTT"."SYS_IMPORT_TABLE_01" successfully completed at 09:10:06

SCOTT@test> select count(*) from t_part partition (p4);
select count(*) from t_part partition (p4)
                     *
ERROR at line 1:
ORA-14501: object is not partitioned

--why?什么回事?

SCOTT@test> select count(*) from t_part;
  COUNT(*)
----------
        31

SCOTT@test> @ddl scott.t_part
C100
-----------------------------------------------------------------------------
  CREATE TABLE "SCOTT"."T_PART"
   (    "OWNER" VARCHAR2(30),
        "OBJECT_NAME" VARCHAR2(128),
        "SUBOBJECT_NAME" VARCHAR2(30),
        "OBJECT_ID" NUMBER,
        "DATA_OBJECT_ID" NUMBER,
        "OBJECT_TYPE" VARCHAR2(19),
        "CREATED" DATE,
        "LAST_DDL_TIME" DATE,
        "TIMESTAMP" VARCHAR2(19),
        "STATUS" VARCHAR2(7),
        "TEMPORARY" VARCHAR2(1),
        "GENERATED" VARCHAR2(1),
        "SECONDARY" VARCHAR2(1),
        "NAMESPACE" NUMBER,
        "EDITION_NAME" VARCHAR2(30)
   ) SEGMENT CREATION IMMEDIATE
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "USERS" ;

--可以发现t_part定义被覆盖了,变成了普通表。
--这些在以后工作中要注意,再次说明理解参数以及测试很重要。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-1754950/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    2468
  • 访问量
    6276516