码迷,mamicode.com
首页 > 数据库 > 详细

oracle数据库ORA-01654 错误的解决方法

时间:2015-12-22 23:04:14      阅读:574      评论:0      收藏:0      [点我收藏+]

标签:

引言:

数据库突然报: ORA-01654: unable to extend index BO.INDEX_indexname by 311072 in tablespace 错误,上网查原因,发现解决方法只有一个,就

是增加tablespace的大小.现归纳解决此问题的方法如下.

方法1:

   当出现类似错误时,首先检查tablespace的空间是否足够大,如果不够大,说明tablespace的空间不够扩展了,这时候需要将tablespace的datafile的

size变大,方法很简单我就不讲了,或增加新的datafile到此tablespace中,使用alter tablespace mytablespace add datafile ‘XXX‘ size xxxx就OK啦



方法2:

   这就是我这此遇到的问题.我的datafile的size为2000m,而我的index的next extent为2G,pct increase为50,这样一来下一个要扩展的extent为3G,

而我的datafile的Size为2G,故无发找到连续3G的空间,当然会出错.

   问题找到了,解决当然很简单,修改next extent 为128k,pct increase为0,问题解决.

不知道是谁设定的,真是个低级错误.

---------------------------------------------分割线---------------------------------------------

问题现象:

测试库使用如下方式创建索引:

create index IDX_ANA_OFFICE on ANA (OFFICE_CITY, OFFICE_NO)
tablespace IDX
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 128K
next 128K
minextents 1
maxextents unlimited
pctincrease 0
);
报错:ORA-01654: unable to extend index GALT.IDX_OFFICE by 128 in tablespace IDX
 
改为默认创建:
create index IDX_ANA_PNR_OFFICE on ANA (OFFICE_CITY, OFFICE_NO)
tablespace IDX;
 
查看SQL是:
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);

问题追查:
1、首先针对1654这个报错,MOS是这样介绍的:

Error:  ORA-01654
Text:   unable to extend index %s.%s by %s in tablespace %s
-------------------------------------------------------------------------------
Cause:  Failed to allocate extent for index segment in tablespace.
Action: Use the ALTER TABLESPACE ADD DATAFILE statement to add one or more
        files to the specified tablespace

(1)、针对表空间不足的情况,建议使用DBA_FREE_SPACE视图进行查询(Note: 121259.1提供了若干脚本)。
(2)、另外,针对索引的问题,DBA_INDEXES视图则描述了下一个分区(NEXT_EXTENT)的大小,以及所有索引的百分比增长(PCT_INCREASE)。“next_extent”指

的是试图分配的区大小(也就是报错中涉及的内容)。
区分配计算:next_extent = next_extent * (1 + (pct_increase/100))
在Concept中描述了为段分配区的算法
How Extents Are Allocated
Oracle uses different algorithms to allocate extents, depending on whether they are locally managed or dictionary managed. With

locally managed tablespaces, Oracle looks for free space to allocate to a new extent by first determining a candidate datafile in the

tablespace and then searching the datafile’s bitmap for the required number of adjacent free blocks. If that datafile does not have

enough adjacent free space, then Oracle looks in another datafile.
MOS也提出了若干可能的解决方法:

Possible solutions:
------------------
- Manually coalesce adjacent free extents:
        ALTER TABLESPACE <tablespace name> COALESCE;
  The extents must be adjacent to each other for this to work.

- Add a datafile:
        ALTER TABLESPACE <tablespace name> ADD DATAFILE ‘<full path and file
        name>‘ SIZE <integer> <k|m>;

- Resize the datafile:
        ALTER DATABASE DATAFILE ‘<full path and file name>‘ RESIZE <integer> <k|m>;

- Enable autoextend:
        ALTER DATABASE DATAFILE ‘<full path and file name>‘ AUTOEXTEND ON
        MAXSIZE UNLIMITED;

- Defragment the Tablespace

- Lower "next_extent" and/or "pct_increase" size:
        ALTER <segment_type> <segment_name> STORAGE ( next <integer> <k|m>
        pctincrease <integer>);

下面这句话我认为是重点:
“这个错误并未指出表空间中是否有足够的空间,仅仅说明Oracle不能找到一个足够大的连续空间用来匹配next extent。
 
 
2、另一篇文章“TROUBLESHOOTING GUIDE (TSG) - UNABLE TO CREATE / EXTEND Errors”说明了各种关于“UNABLE TO CREATE / EXTEND”的错误。
“unable to extend"的错误是指当没有足够连续的空间用来分配段的情况。
 
I. 提出了解决这种错误所需要的信息:
(1)、判断报错表空间中最大的连续空间是多少。
SELECT max(bytes) FROM dba_free_space WHERE tablespace_name = ‘<tablespace name>‘;
这个SQL返回的是表空间最大允许的连续块大小。(DBA_FREE_SPACE不会返回临时表空间的信息,可以参考“DBA_FREE_SPACE Does not Show Information

about Temporary Tablespaces (文档 ID 188610.1)”这篇文章会介绍如何查看临时表空间的连续块大小)。
如果在这个报错之后立即执行上述SQL,则返回的表空间中连续的最大块会小于这个对象正在试图分配的next extent的空间。
 
(2)、判断NEXT_EXTENT大小。
a) 对于PCT_INCREASE=0的字典管理表空间(DMT)或者使用统一UNIFORM区管理的本地管理表空间(LMT),使用如下SQL:
SELECT NEXT_EXTENT, PCT_INCREASE
FROM DBA_SEGMENTS
WHERE SEGMENT_NAME = <segment name>
AND SEGMENT_TYPE = <segment type>
AND OWNER = <owner>
AND TABLESPACE_NAME = <tablespace name>;
其中segment_type会展示在错误信息中,可能包含如下类型的segment:
CLUSTER
INDEX
INDEX PARTITION
LOB PARTITION
LOBINDEX
LOBSEGMENT
NESTED TABLE
ROLLBACK
TABLE
TABLE PARTITION
TYPE2 UNDO
TYPE2 UNDO (ORA-1651)
同样地,segment_name可以在错误信息中找到。
b) 对于使用SYSTEM|AUTOALLOCATE区管理的本地管理表空间(LMT)。
没有方法可以查询它的next extent大小。只能查询错误信息,错误信息中的块数乘以表空间的块大小,以此来判断需要创建的区大小。
c) 对于PCT_INCREASE>0的字典管理表空间(DMT)。
SELECT EXTENT_MANAGEMENT FROM DBA_TABLESPACES WHERE TABLESPACE_NAME = ‘<tablespace name>‘;
使用如下公式计算需要分配的区大小:
extent size = next_extent * (1 + (pct_increase/100)
例如:
next_extent = 512000
pct_increase = 50
next extent size = 512000 * (1 + (50/100)) = 512000 * 1.5 = 768000
注意:
ORA-01650 Rollback Segment
pct_increase仅用于Oracle若干早期版本,后面版本中回滚段的pct_increase默认是0。
ORA-01652 Temporary Segment
临时段与表空间创建的存储默认值相同。
如果查询出现错误,则需要判断这个查询语句是否尽可能地最优以完成排序。
 
(3)、判断表空间是否包含了AUTOEXTENSIBLE,并已经达到MAXSIZ。
对于数据文件:
SELECT file_name, bytes, autoextensible, maxbytes FROM dba_data_files WHERE tablespace_name=‘<tablespace name> ‘;
对于临时文件:
SELECT file_name, bytes, autoextensible, maxbytes FROM dba_temp_files WHERE tablespace_name=‘<tablespace name> ‘;
 
(4)、判断哪种解决方法最优。
如果NEXT EXTENT的容量(步骤2或3)大于空闲空间最大的连续块,那么“Manually Coalesce Adjacent Free Extents”是个选择。如果coalesce后仍旧没有足

够的连续空间,那么可能需要其他的选项。
如果表空间的数据文件/临时文件的卷有足够的空间,那么添加数据文件/临时文件或消除表空间碎片化可能管用,将这个文件添加到新卷中。
如果表空间是AUTOEXTENSIBLE并且已经MAXSIZE,那么需要提高最大容量(确认有足够的卷空间),或者添加数据文件/临时文件,或者消除碎片化。
如果NEXT EXTENT的容量(步骤2或3)小于空闲空间最大的连续块,那么就需要联系Oracle支持。
 
II. 可能的解决方案:
(1)、手工合并相邻的空闲区。
ALTER TABLESPACE <tablespace name> COALESCE;
(2)、将一个或多个数据文件/临时文件修改为使用AUTOEXTEND。
ALTER DATABASE DATAFILE|TEMPFILE ‘<full path and name>‘ AUTOEXTEND ON MAXSIZE <integer> <k | m | g |
注意:强烈建议明确MAXSIZE参数,防止数据文件/临时文件消耗卷上的所有可用空间。
(3)、添加数据文件/临时文件。
ALTER TABLESPACE <tablespace name> ADD DATAFILE|TEMPFILE ‘<full path and file name>‘ SIZE <integer> <k | m | g | t | p | e>;
(4)、如果段是字典管理表空间,可以降低“next_extent”和/或“pct_increase”的大小。
对于非临时段和非分区段:
ALTER <SEGMENT TYPE> <segment_name> STORAGE ( next <integer> <k | m | g | t | p | e> pctincrease <integer>);
对于非临时段和分区段:
ALTER TABLE <table_name> MODIFY PARTITION <partition_name> STORAGE ( next <integer> <k | m | g | t | p | e> pctincrease <integer>);
对于临时段:
ALTER TABLESPACE <tablespace name> DEFAULT STORAGE (initial <integer> <k | m | g | t | p | e> next <integer> <k | m | g | t | p | e>

pctincrease <integer>);
(5)、重改数据文件/临时文件的大小。
ALTER DATABASE DATAFILE|TEMPFILE ‘<full path and file name>‘ RESIZE <integer> <k | m | g | t | p | e>;
(6)、消除表空间的碎片。
 
附录:和此类解决方法相关的报错:
ORA-1650: unable to extend rollback segment %s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for a rollback segment in the tablespace.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1651: unable to extend save undo segment by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for saving undo entries for the indicated offline tablespace.
Action: Check the storage parameters for the SYSTEM tablespace. The tablespace needs to be brought back online so the undo can be

applied.

ORA-1652: unable to extend temp segment by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for a temporary segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1653: unable to extend table %s.%s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for a table segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1654: unable to extend index %s.%s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for an index segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1655: unable to extend cluster %s.%s by %s for tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for a cluster segment in tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1658: unable to create INITIAL extent for segment in tablespace %s
Cause: Failed to find sufficient contiguous space to allocate INITIAL extent for segment being created.
Action: Use ALTER TABLESPACE ADD DATAFILE to add additional space to the tablespace or retry with a smaller value for INITIAL

ORA-1659 unable to allocate MINEXTENTS beyond %s in tablespace %s
Cause: Failed to find sufficient contiguous space to allocate MINEXTENTS for the segment being created.
Action: Use ALTER TABLESPACE ADD DATAFILE to add additional space to the tablespace or retry with smaller value for MINEXTENTS, NEXT

or PCTINCREASE

ORA-1683: unable to extend index %s.%s partition %s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for index segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1688: unable to extend table %s.%s partition %s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for table segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1691: unable to extend lob segment %s.%s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for LOB segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-1692: unable to extend lob segment %s.%s partition %s by %s in tablespace %s
Cause: Failed to allocate an extent of the required number of blocks for LOB segment in the tablespace indicated.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.


ORA-3233: unable to extend table %s.%s subpartition %s by %s in tablespace %s
Cause: Failed to allocate an extent for table subpartition segment in tablespace.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-3234: unable to extend index %s.%s subpartition %s by %s in tablespace %s
Cause: Failed to allocate an extent for index subpartition segment in tablespace.
Action: Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.

ORA-3238: unable to extend LOB segment %s.%s subpartition %s by %s in tablespace %s
Cause: An attempt was made to allocate an extent for LOB subpartition segment in tablespace, but the extent could not be allocated

because there is not enough space in the tablespace indicated.
Action: Use the ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated.
 
 
总结:
针对上面案例中的错误,总体讲是空间不足导致的,之所以使用第二个SQL可以,原因可能就是这种参数值设置下的满足可以空闲空间连续块的容量,上面采用的

是减小extent分配大小的方式,另外上面提到的扩大文件、修改参数值、消除碎片化等方法都可以尝试使用。



原网址:http://www.linuxidc.com/Linux/2013-12/93685.htm

oracle数据库ORA-01654 错误的解决方法

标签:

原文地址:http://www.cnblogs.com/lcss/p/5068344.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!