該篇接着http://589985.blog.51cto.com/160×××/1359260繼續討論ORA-01652的第二種情況,在一次CTAS建表中發現報如下錯誤
SQL> create table test as select * from dba_objects;
create table test as select * from dba_objects
*
ERROR at line 1:
ORA-01652: unable to extend temp segment by 128 in tablespace SHAO
這個報錯很容易懂就是你的表空間不夠用了,處理方法也很簡單,給shao加數據文件,或者resize已有數據文件(如果數據文件爲不可自動擴展的話)。但是我還是覺得這個報錯很奇怪,爲什麼要在永久表空間裏擴展臨時段呢?永久表空間裏怎麼會出現臨時段呢?
很是好奇,然後在mos和谷歌上找了很久加上自己作試驗,基本把這個問題給弄清楚了。
我們先來看一下mos上是怎麼解釋的(Doc ID 19047.1),我截取了其中的一段相關內容
NOTE: A "temp segment" is not necessarily a SORT segment in a temporary tablespace.
It is also used for temporary situations while creating or dropping objects like tables and indexes in permanent tablespaces.
eg: When you perform a CREATE INDEX a TEMP segment is created to hold what will be the final permanent index data.
This TEMP segment is converted to a real INDEX segment in the dictionary at the end of the CREATE INDEX operation.
It remains a temp segment for the duration of the CREATE INDEX operation and so failures to extend it report ORA-1652 rather than an INDEX related space error.
--這段是說在create index時會在相應的永久表空間上建一個臨時段,當create index語句結束該臨時段轉變爲真正的索引段。而在create index語句沒有結束之前該段一直是臨時段,所以在表空間不足時報的就是不能臨時段不能擴展而不是索引段。
A TEMPORARY segment may be from:
A SORT | Used for a SELECT or for DML/DDL |
CREATE INDEX | The index create performs a SORT in the users default TEMP tablespace and ALSO uses a TEMP segment to build the final index in the INDEX tablespace. Once the index build is complete the segment type is changed. |
CREATE PK CONSTRAINT | |
ENABLE CONSTRAINT | |
CREATE TABLE | New tables start out as TEMPORARY segments. Eg: If MINEXTENTS is > 1 or you issue CREATE table as SELECT. |
Accessing a GLOBAL TEMPORARY TABLE | When you access a global temporary table a TEMP segment is instantiated to hold the temporary data. |
從上面該表中我們可以知道,CTAS;CREATE PK CONSTRAINT;ENABLE CONSTRAINT等動作同create index一樣會在永久表空間中產生臨時表(測試發現alter table test move;也是);
下面是我測試的情況
1)create index
SQL> create index IND_TESTFLASH_NAME on test_flash(object_name);
Index created.
--session1中執行(然後立即在session2中執行下面語句)
SQL> select segment_name,segment_type,tablespace_name,buffer_pool from dba_segments where segment_type='TEMPORARY';
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME BUFFER_
--------------------------------------------------------------------------------- ------------------ ------------------------------ -------
5.266 TEMPORARY SHAO DEFAULT
--session2 中執行(注意要在session1 中create index語句沒有結束之前執行)
SQL>select segment_name,segment_type,tablespace_name,buffer_pool from dba_segments where segment_type='TEMPORARY';
no rows selected
--在session1中create index結束後再次執行該語句結果爲空
由上面的實驗可以看出在create index的過程中確實在表空間shao中產生了臨時段,create index語句結束時該段又消失了(轉變爲真正的index段)
CTAS;CREATE PK CONSTRAINT;ENABLE CONSTRAINT;alter table move等測試結果同上,就不在一一貼出來了。