資料庫遷移之資料泵實驗

孤竹星發表於2015-10-16
environment

source host:
os system:server2008x64 
oracle version:10.0.2.0.5 32bit

destination host:
os system:server2008x64
oracle version:10.0.2.0.5 64bit

對資料庫中的表進行拆分匯出匯入,減少停機時間,首先將表比較大而不變化的資料先匯出,匯入,最好在匯出變化的資料

source host:
C:\Users\Administrator>sqlplus /@orcl as sysdba

SQL> create tablespace loneboo datafile 'D:\oracle\product\10.2.0\oradata\orcl\loneboo01.dbf' size 200m;

表空間已建立。

SQL> create user loneboo identified by loneboo default tablespace loneboo temporary tablespace temp;

使用者已建立。

SQL> grant connect,dba to loneboo;

SQL> exit

tables: A partition table
B partition blob table


create table A
(
  ID         NVARCHAR2(10) not null,
  CREATEDATE DATE,
  NAME       NVARCHAR2(20)
)
partition by range (CREATEDATE)
(
  partition R_CREATE1501 values less than (TO_DATE(' 2015-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1502 values less than (TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1503 values less than (TO_DATE(' 2015-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1504 values less than (TO_DATE(' 2015-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1505 values less than (TO_DATE(' 2015-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1506 values less than (TO_DATE(' 2015-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    )
)
;
-- Create/Recreate primary, unique and foreign key constraints 
alter table A
  add constraint PK_A_ID primary key (ID)
  using index 
  tablespace LONEBOO
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );






-- Create table
create table B
(
  ID         NVARCHAR2(10) not null,
  CREATEDATE DATE,
  NAME       NVARCHAR2(20),
  DATA     BLOB
  
)
partition by range (CREATEDATE)
(
  partition R_CREATE1501 values less than (TO_DATE(' 2015-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1502 values less than (TO_DATE(' 2015-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1503 values less than (TO_DATE(' 2015-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1504 values less than (TO_DATE(' 2015-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1505 values less than (TO_DATE(' 2015-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    ),
  partition R_CREATE1506 values less than (TO_DATE(' 2015-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
    tablespace LONEBOO
    pctfree 10
    initrans 1
    maxtrans 255
    storage
    (
      initial 64K
      next 1M
      minextents 1
      maxextents unlimited
    )
)
;
-- Create/Recreate primary, unique and foreign key constraints 
alter table B
  add constraint PK_B_ID primary key (ID)
  using index 
  tablespace LONEBOO
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    next 1M
    minextents 1
    maxextents unlimited
  );




-- Create table
create table C
(
  ID   nvarchar2(20),
  NAME nvarchar2(50),
  AGE  number
)
;
-- Create/Recreate primary, unique and foreign key constraints 
alter table C
  add constraint pk_c_id primary key (ID);

INSERT INTO a VALUES ('1',to_date('2015-01-01','yyyy-mm-dd'),'hello');
INSERT INTO a VALUES ('2',to_date('2015-02-01','yyyy-mm-dd'),'world');
INSERT INTO a VALUES ('3',to_date('2015-03-01','yyyy-mm-dd'),'join');
INSERT INTO a VALUES ('4',to_date('2015-04-01','yyyy-mm-dd'),'syn');
INSERT INTO a VALUES ('5',to_date('2015-05-01','yyyy-mm-dd'),'koko');

INSERT INTO B VALUES ('1',to_date('2015-01-01','yyyy-mm-dd'),'hello',NULL);
INSERT INTO B VALUES ('2',to_date('2015-02-01','yyyy-mm-dd'),'world',NULL);
INSERT INTO B VALUES ('3',to_date('2015-03-01','yyyy-mm-dd'),'join',NULL);
INSERT INTO B VALUES ('4',to_date('2015-04-01','yyyy-mm-dd'),'syn',NULL);
INSERT INTO B VALUES ('5',to_date('2015-05-01','yyyy-mm-dd'),'koko',NULL);

透過sql development將圖片加入到data欄位中

INSERT INTO C VALUES ('1','hello',20);
INSERT INTO C VALUES ('2','world',30);
INSERT INTO C VALUES ('3','join',40);

建立目錄

C:\Users\Administrator>sqlplus loneboo/loneboo@orcl


SQL*Plus: Release 10.2.0.5.0 - Production on 星期一 10月 12 11:59:56 2015


Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create directory dirloneboo as 'D:\dirloneboo';

1.匯出後設資料
expdp loneboo/loneboo@orcl schemas=loneboo directory='dirloneboo' exclude=statistics  content=metadata_only dumpfile=loneboometadata.dmp logfile=loneboometadata.log

2.匯出分割槽表部分資料
expdp loneboo/loneboo@orcl directory='dirloneboo' exclude=statistics content=data_only parallel=10 tables=A,B query=\"where createdate <to_date('2015-03-01','yyyy-mm-dd')\" dumpfile=loneboombigtable%U.dmp logfile=loneboombigtable.log

3.匯出小表全部資料

expdp loneboo/loneboo@orcl directory='dirloneboo' exclude=statistics content=data_only parallel=10  tables=C dumpfile=loneboosmalltable%U.dmp logfile=loneboosmalltable.log

4.匯出分割槽表剩餘資料

expdp loneboo/loneboo@orcl directory='dirloneboo' exclude=statistics content=data_only parallel=10 tables=A,B query=\"where createdate >= to_date('2015-03-01','yyyy-mm-dd')\" dumpfile=lonebootableother%U.dmp logfile=lonebootableother.log

destination host 步驟:

C:\Users\Administrator>sqlplus /@orcl as sysdba

SQL> create tablespace loneboo datafile 'D:\oracle\product\10.2.0\oradata\orcl\loneboo01.dbf' size 200m;

表空間已建立。

SQL> create user loneboo identified by loneboo default tablespace loneboo temporary tablespace temp;

使用者已建立。

SQL> grant connect,dba to loneboo;

SQL> exit

C:\Users\Administrator>sqlplus loneboo/loneboo@orcl

SQL> create directory dirloneboo as 'D:\dirloneboo';

目錄已建立。

複製匯出的檔案到destination host 的 D:\dirloneboo

1.匯入後設資料
impdp loneboo/loneboo@orcl schemas=loneboo directory='dirloneboo' dumpfile=loneboometadata.dmp logfile=imploneboometadata.log

2.匯入大表的部分資料
impdp loneboo/loneboo@orcl directory='dirloneboo'  content=data_only parallel=10  dumpfile=loneboombigtable%U.dmp logfile=imploneboodata.log

3.匯入小表的全部資料
impdp loneboo/loneboo@orcl directory='dirloneboo' content=data_only parallel=10 dumpfile=loneboosmalltable%U.dmp logfile=imploneboosmalltable.log

4.匯入大表的剩餘資料
impdp loneboo/loneboo@orcl directory='dirloneboo' content=data_only parallel=10 dumpfile=lonebootableother%U.dmp logfile=imploneboopardata.log

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28282660/viewspace-1814505/,如需轉載,請註明出處,否則將追究法律責任。

相關文章