54

I have a large Oracle table, which contains 542512 rows. It has three columns and when I try to create an index for it with the following command:

  CREATE INDEX FTS_INDEX ON FILTERED_TEKLI_IIS_TABLOSU (ilAdi,ilceAdi,caddeAdi)

Oracle gives the following error:

SQL Error: ORA-01652: unable to extend temp segment by 128 in tablespace SYSTEM
01652. 00000 -  "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.

I searched for this error and found that it is produced when Oracle hasn't enough space to store intermediate data when executing operations like joining tables, creating indices etc. on large tables. But I did not found a clear solution for this. These ALTER TABLESPACE and ADD DATAFILE commands seem to do the job, but I am not sure how to call these and with which parameters. Any help would be appreciated.

Ufuk Can Bicici
  • 3,589
  • 4
  • 28
  • 57
  • 2
    "Use ALTER TABLESPACE ADD DATAFILE statement to add one or more files to the tablespace indicated." More information you can find at http://www.dba-oracle.com/sf_ora_01652_unable_to_extend_temp_segment_by_string_in_tablespace_string.htm –  Aug 17 '14 at 15:42

1 Answers1

74

Each tablespace has one or more datafiles that it uses to store data.

The max size of a datafile depends on the block size of the database. I believe that, by default, that leaves with you with a max of 32gb per datafile.

To find out if the actual limit is 32gb, run the following:

select value from v$parameter where name = 'db_block_size';

Compare the result you get with the first column below, and that will indicate what your max datafile size is.

I have Oracle Personal Edition 11g r2 and in a default install it had an 8,192 block size (32gb per data file).

Block Sz   Max Datafile Sz (Gb)   Max DB Sz (Tb)

--------   --------------------   --------------

   2,048                  8,192          524,264

   4,096                 16,384        1,048,528

   8,192                 32,768        2,097,056

  16,384                 65,536        4,194,112

  32,768                131,072        8,388,224

You can run this query to find what datafiles you have, what tablespaces they are associated with, and what you've currrently set the max file size to (which cannot exceed the aforementioned 32gb):

select bytes/1024/1024 as mb_size,
       maxbytes/1024/1024 as maxsize_set,
       x.*
from   dba_data_files x

MAXSIZE_SET is the maximum size you've set the datafile to. Also relevant is whether you've set the AUTOEXTEND option to ON (its name does what it implies).

If your datafile has a low max size or autoextend is not on you could simply run:

alter database datafile 'path_to_your_file\that_file.DBF' autoextend on maxsize unlimited;

However if its size is at/near 32gb an autoextend is on, then yes, you do need another datafile for the tablespace:

alter tablespace system add datafile 'path_to_your_datafiles_folder\name_of_df_you_want.dbf' size 10m autoextend on maxsize unlimited;
Brian DeMilia
  • 13,103
  • 1
  • 23
  • 33
  • It seems that I have solved it by adding a new datafile to the SYSTEM tablespace. But when I have looked at my current Tablespaces via the SELECT * FROM DBA_DATA_FILES command, I saw that all the current tablespaces are auto extendable. Then why did Oracle fail to extend the tablespace to the needed amount? – Ufuk Can Bicici Aug 17 '14 at 16:17
  • 1
    Because of the max of 32gb. Even w/ auto extend on, it won't just increase indefinitely, it still has that upper boundary. In other words, you need to add a datafile for each 32gb of data within each tablespace. So if you have a tablespace you're expecting to need a terabyte of data, you'll have to have 3 datafiles, each w/ autoxtend on and a max file size (because the actual max is 32) – Brian DeMilia Aug 17 '14 at 16:22
  • 1
    @UfukCanBiçici That 32gb depends on what your database's block size is. I BELIEVE that is the default, but you can check to see what yours actually is, in any case, by running the above query and referring to the above chart (I just added that info to the answer). – Brian DeMilia Aug 17 '14 at 16:26
  • 2
    Just to clarify in my second comment, for a terabyte (1000gb) you'd actually need 32 datafiles. I was thinking of 100gb, in which case you'd only need 3. You can always add multiple datafiles for a tablespace, with a small start size (ie. 10mb or something small) w/ a max size of unlimited (up to the boundary), and auto extend on, in anticipation of the eventual need for them being used. – Brian DeMilia Aug 17 '14 at 16:31
  • does putting indexes in a separate tablespace have some performance benefits? – Toolkit May 21 '17 at 04:35
  • @Toolkit it depends but in more cases than not it is becoming less relevant so i edited that part of my answer out as it doesn't directly pertain to the matter at hand anyway. this provides some insight though: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1463404632043 – Brian DeMilia Aug 11 '17 at 02:46