前提:
查询分区:Select *From user_extents WHERE partition_name='分区名';
1)创建表空间
create tablespace HRPM0
datafile '/oradata/misdb/HRPM0.DBF' size 5m autoextend on next 10m maxsize unlimited
2)删除表空间(同时把数据文件也删除)
DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
如果不想删除数据文件:
Drop tablespace tablespace_name;
3) 修改表空间大小
alter database datafile '/path/NADDate05.dbf' resize 100M
4)添加数据文件(在建立表空间时,若是约束了表空间的大小,那么一段时间后,这个表空间就会被装满,无法再添加其他对象。则需要给表空间添加数据文件):
Alter tablespace tablespace_name add datafile’ '/path/NADDate06.dbf’ size 100M;
4) 备注:
4.1).--.禁止undo tablespace自动增长
alter database datafile 'full_path\undotbs01.dbf' autoextend off;
4.2).--创建一个新的小空间的undo tablespace
create undo tablespace undotBS2 datafile 'full_path\UNDOTBS02.DBF' size 100m;
4.3).--设置新的表空间为系统undo_tablespace
alter system set undo_tablespace=undotBS2;
4.4).-- Drop旧的表空间
drop tablespace undotbs1 including contents;
4.5).--查看所有表空间的情况
select * from dba_tablespaces
5)查到一个最好用的表:dict
5.1)select*fromdictwheretable_namelike '%PART%'
5.2)ALL_TAB_PARTITIONS:可以查出表所对应的分区内容;
5.3)dab_tab_partitons:与上2);
5.4)dba_ind_partitons:查询分区的索引;
5.5)子分区也是一样的(dba_tab_subpartitons,dba_ind_partitons)
一、使用分区的优点:
1、增强可用性:如果表的某个分区出现故障,表在其他分区的数据仍然可用;
2、维护方便:如果表的某个分区出现故障,需要修复数据,只修复该分区即可;
3、均衡I/O:可以把不同的分区映射到磁盘以平衡I/O,改善整个系统性能;
4、改善查询性能:对分区对象的查询可以仅搜索自己关心的分区,提高检索速度。
二、Oracle数据库提供对表或索引的分区方法有几种(收集到四种):
1、范围分区
2、列表分区
3、Hash分区(散列分区)
4、复合分区
三、详描述分区实例:
1)下面将以实例的方式分别对这三种分区方法来说明分区表的使用。为了测试方便,我们先建三个表空间。
create tablespacedinya_space01datafile 'C:\表空间\dinya01.dbf' size 5M;create tablespacedinya_space02datafile 'C:\表空间\dinya02.dbf'SIZE 5M;create tablespacedinya_space03datafile 'C:\表空间\dinya03.dbf' SIZE 5M;
select*fromuser_tablespaces
三个>
1.1)范围分区
范围分区就是对数据表中的某个值的范围进行分区,根据某个值的范围,决定将该数据存储在哪个分区上。如根据序号分区,根据业务记录的创建日期进行分区等。
需求描述:有一个物料交易表,表名:material_transactions。该表将来可能有千万级的数据记录数。要求在建该表的时候使用分区表。这时候我们可以使用序号分区三个区,每个区中预计存储三千万的数据,也可以使用日期分区,如每五年的数据存储在一个分区上。
根据交易记录的序号分区建表:----为了测试需要做以下修改;
create table dinya_test
(
transaction_id number primary key,
item_id number(8) not null,
item_description varchar2(300),
transaction_date date not null
)
partition by range (transaction_id)
(
partition part_01 values less than(2) tablespace dinya_space01,-----2条以下的交易在此分区上:part_01
partition part_02 values less than(3) tablespace dinya_space02,-----等于+大于2而小于3的交易在此分区:part_02
partition part_03 values less than(maxvalue) tablespace dinya_space03----大于3的交易在此分区:part_03
-----------------以上在pl/sql测试成功;
----------------以下没有在pl/sql测试!
根据交易日期分区建表:
SQL> create table dinya_test
(
transaction_id number primary key,
item_id number(8) not null,
item_description varchar2(300),
transaction_date date not null
)
partition by range (transaction_date)
(
partition part_01 values less than(to_date('2006-01-01','yyyy-mm-dd')) tablespace dinya_space01,
partition part_02 values less than(to_date('2010-01-01',&#