如果更新oracle分区字段,则会报如下错误:
[img]http://dl.iteye.com/upload/picture/pic/118884/cb5aa656-913f-3048-9017-e83f0cf90fe8.jpg[/img]
解决办法:
不知道对于性能会有什么样的影响。
查看用户表、索引、分区表占用空间
查询表占用空间的大小:
索引占用空间
分区表TABLE PARTITION占用空间
查看各个表空间使用情况
增加表空间大小
将分区表的数据和索引分开,分别放在另外两个表空间
1:创建表空间
2:将各个分区数据依次迁移至数据表空间
3:如果某个表分区p0是空的,但查询很慢,则用以下语句truncate一下
4:依次创建索引(注意:分区数必须与表的分区数一致,否则报错ORA-14024)
碰到的问题:
一:
修改0分区数据,直接把数据移至其它分区时报错:oracle ORA-01502
解决办法:alter index PK_XXX_ID rebuild ; (重建主键索引)
原因:以前move过分区到其它表空间
二:
迁移数据至其它分区800多万条,耗时差不多半小时,建议分批处理:
三:
创建表空间时,大小会有限制,否则会报错:
[img]http://dl.iteye.com/upload/picture/pic/120090/fcb10544-526e-31a4-9326-834e86c07629.jpg[/img]
[img]http://dl.iteye.com/upload/picture/pic/118884/cb5aa656-913f-3048-9017-e83f0cf90fe8.jpg[/img]
解决办法:
alter table XXXXX enable row movement;
不知道对于性能会有什么样的影响。
查看用户表、索引、分区表占用空间
select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments group by segment_name;
查询表占用空间的大小:
select segment_name, sum(bytes)/1024/1024 Mbytese from user_segments where segment_type='TABLE' group by segment_name;
索引占用空间
select segment_name ,sum(bytes)/1024/1024 from user_segments where segment_type ='INDEX' group by segment_name;
分区表TABLE PARTITION占用空间
select segment_name,sum(bytes)/1024/1024 Mbytes from user_segments where segment_type='TABLE PARTITION' group by segment_name;
查看各个表空间使用情况
select dbf.tablespace_name,
dbf.totalspace "总量(M)",
dbf.totalblocks as 总块数,
dfs.freespace "剩余总量(M)",
dfs.freeblocks "剩余块数",
(dfs.freespace / dbf.totalspace) * 100 "空闲比例"
from (select t.tablespace_name,
sum(t.bytes) / 1024 / 1024 totalspace,
sum(t.blocks) totalblocks
from dba_data_files t
group by t.tablespace_name) dbf,
(select tt.tablespace_name,
sum(tt.bytes) / 1024 / 1024 freespace,
sum(tt.blocks) freeblocks
from dba_free_space tt
group by tt.tablespace_name) dfs
where trim(dbf.tablespace_name) = trim(dfs.tablespace_name);
SELECT Total.name "Tablespace Name",
Free_space,
(total_space - Free_space) Used_space,
total_space
FROM (select tablespace_name, sum(bytes / 1024 / 1024) Free_Space
from sys.dba_free_space
group by tablespace_name) Free,
(select b.name, sum(bytes / 1024 / 1024) TOTAL_SPACE
from sys.v_$datafile a, sys.v_$tablespace B
where a.ts# = b.ts#
group by b.name) Total
WHERE Free.Tablespace_name = Total.name
增加表空间大小
1:找出该表空间对应的数据文件及路径
select * from dba_data_files t
where t.tablespace_name = 'USERS'
2:增大数据文件
alter database datafile '全路径的数据文件名称' resize ***M (M或者G)
3:增加数据文件
alter tablespace 表空间名称
add datafile '全路径的数据文件名称' size ***M (M或者G)
注解:表空间尽量让free百分比保持在10%以上,如果低于10%就增加datafile或者resizedatafile,一般数据文件不要超过2G
4:检查tablespace的free空间能不能满足最大的next_extent,不能则扩展tablespace
select s.owner,s.segment_name,s.segment_type,s.tablespace_name, s.next_extent
from dba_segments s
where s.next_extent > (select MAX(f.bytes)
from dba_free_space f
where f.tablespace_name = s.tablespace_name)
order by s.tablespace_name
设置自动扩展:
alter database datafile 'D:\oradata\orcl\PERFSTAT.DBF' autoextend on;
将分区表的数据和索引分开,分别放在另外两个表空间
1:创建表空间
CREATE TABLESPACE xxx_data
LOGGING
DATAFILE '/home/oracle/oradata/oratuank/xxx_data01.dbf'
SIZE 5120M
AUTOEXTEND ON
NEXT 5120M MAXSIZE 25600M
EXTENT MANAGEMENT LOCAL;
CREATE TABLESPACE xxx_index
LOGGING
DATAFILE '/home/oracle/oradata/oratuank/xxx_index01.dbf'
SIZE 5120M
AUTOEXTEND ON
NEXT 5120M MAXSIZE 25600M
EXTENT MANAGEMENT LOCAL;
2:将各个分区数据依次迁移至数据表空间
alter table xxx move partition P0 tablespace sms_data;
alter table xxx move partition P1 tablespace sms_data;
...
如果使用以下操作会报错:
alter table sp_sms_list1 move tablespace xxx_data;
ORA-14511: cannot perform operation on a partitioned object
3:如果某个表分区p0是空的,但查询很慢,则用以下语句truncate一下
ALTER TABLE xxxxxx TRUNCATE PARTITION p0
4:依次创建索引(注意:分区数必须与表的分区数一致,否则报错ORA-14024)
create index index_xxx_columnname on xxx_table(columnname) local (
partition p0 tablespace xxx_index,
partition p1 tablespace xxx_index,
partition p2 tablespace xxx_index,
partition p3 tablespace xxx_index,
partition p4 tablespace xxx_index,
partition p5 tablespace xxx_index,
partition p6 tablespace xxx_index,
partition p7 tablespace xxx_index,
partition p8 tablespace xxx_index,
partition p9 tablespace xxx_index,
partition p10 tablespace xxx_index,
partition p11 tablespace xxx_index,
partition p12 tablespace xxx_index
);
碰到的问题:
一:
修改0分区数据,直接把数据移至其它分区时报错:oracle ORA-01502
解决办法:alter index PK_XXX_ID rebuild ; (重建主键索引)
原因:以前move过分区到其它表空间
二:
迁移数据至其它分区800多万条,耗时差不多半小时,建议分批处理:
update xxxxx partition(p0)
set p_month = to_number(to_char(post_time, 'MM'))
三:
创建表空间时,大小会有限制,否则会报错:
[img]http://dl.iteye.com/upload/picture/pic/120090/fcb10544-526e-31a4-9326-834e86c07629.jpg[/img]