ORACLE 创建和使用分区

  以system身份登陆数据库,查看 v$option视图,如果其中Partition为TRUE,则支持分区功能;否则不支持。Partition有基于范围、哈希、综和三种类型。
  1 、以system 身份创建独立的表空间(大小可以根据数据量的多少而定)

  create tablespace g_2010q1 datafile '/home/oradata/oradata/test/g_2010q1.dbf' size 50M default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

  create tablespace g_2010q2 datafile '/home/oradata/oradata/test/g_2010q2.dbf' size 50M default storage (initial 100k next 100k minextents 1 maxextents unlimited pctincrease 1);

 
  2 、用EXPORT工具把旧数据备份在guestbook.dmp中
  把原来的guestbook表改名

alter table guestbook rename to guestbookold;

  以guestbook 身份创建分区的表

create table guestbook(
  id number(16) primary key,
  username varchar2(64),
  sex varchar2(2),
  email varchar2(256),
  expression varchar2(128),
  content varchar2(4000),
  time date,
  ip varchar2(64)
  );

  

partition by range (time)
  partition g_2010q1 values less than (to_date('2010-01-01','yyyy-mm-dd'))
  tablespace g_2010q1
  storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0),
  partition g_2010q2 values less than (to_date('2010-02-01','yyyy-mm-dd'))
  tablespace g_2010q2
  storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0),
  partition g_2010q3 values less than (to_date('2010-03-01','yyyy-mm-dd'))
  tablespace g_2010q3
  storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0),
  );

 

3、IMPORT导入数据,参数ignore=y
  
4、分区表的扩容:

create tablespace g_2010q4 datafile '/home/oradata/oradata/test/g_2010q4.dbf' size 50m default storage (initial 100k   next 100k minextents 1 maxextents unlimited pctincrease 1);

 
 为表添加新分区和表空间:

alter table guestbook add partition g_2010q4
 values less than (to_date('2010-04-01','yyyy-mm-dd')
 tablespace g_2010q3 
 storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0); 

 
5、EXPORT 分区:
 % exp guestbook/guestbook_password tables=guestbook:g_2010q1 rows=Y file=g_2010q1.dmp

  

6、删除不必要的分区
  将1月份的数据备份,将1月份的分区删除。

alter table guestbook drop partion g_2010q1;

 

 删除物理文件
 %rm /home/oradata/oradata/test/g_2010q1.dbf

  7、IMPORT分区:
  例如在4月份,用户要查看1月的数据,先创建表空间

  create tablespace g_2010q13 datafile '/home/oradata/oradata/test/g_2010q13.dbf' size 50m default storage (initial    100k  next 100k minextents 1 maxextents unlimited pctincrease 1);

   
  为表添加新分区和表空间:

alter table guestbook add partition g_2010q13
  values less than (to_date('2010-01-01','yyyy-mm-dd')
  tablespace g_2010q13 
  storage(initial 100k next 100k minextents 1 maxextents unlimited pctincrease 0); 

   
  导入数据
  %imp guestbook/guestbook_password file=g_2010q1.dmp tables=(guestbook:g_2010q13) ignore=y

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值