天天看點

ORA-01654錯誤

問題現象:

測試庫使用如下方式建立索引:

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是這樣介紹的:

(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也提出了若幹可能的解決方法:

下面這句話我認為是重點:

 “這個錯誤并未指出表空間中是否有足夠的空間,僅僅說明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.

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.

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.

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.

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.

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.

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.

ORA-1692: unable to extend lob segment %s.%s partition %s by %s in tablespace %s

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.

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.

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配置設定大小的方式,另外上面提到的擴大檔案、修改參數值、消除碎片化等方法都可以嘗試使用。