#####################################
#  create temporary tablespaceÂ÷ÀÌÁ¡                        # 
#####################################

ÀÛ¼ºÀÚ : ÀåÇüÈ­(hhjang97@venus.uos.ac.kr)
ÀÛ¼ºÀÏ : 2005. 09. 21 
¼öÁ¤ÀÏ : 

¿øº» : database.sarang.net
¼³¸í :


################################# ################################# #################################
1. create temporary tablespace TEMP01

tempfile '/oradata/temp01_01.dbf' size 1G;

 

2. create tablespace TEMP01

datafile '/oradata/temp01_01.dbf' size 1G temporary;

 

1,2¹ø ¸í·É¾î µÑ´Ù temporary tablespace¸¦ »ý¼ºÇÏ´Â ¹æ¹ýÀΰɷΠ¾Ë°íÀմµ¥¿ä?

Ȥ½Ã Â÷ÀÌÁ¡ÀÌ ÀÖ³ª¿ä?????


#################################

=========================================================

TEMPORARY TABLESPACE¿¡¼­ TEMPFILE °ú DATAFILEÀÇ Â÷ÀÌÁ¡ (8.1.X ~ 9I) 
============================================================ 


PURPOSE 
------- 
ÀÌ ¹®¼­¿¡¼­´Â Oracle 7.3ºÎÅÍ »ç¿ëµÇ¾î ¿À´ø create tablespace ... temporary 
ÇüÅ¿Í, 8iºÎÅÍ »ç¿ëµÇ´Â create temporary tablespace... ÀÇ Â÷ÀÌÁ¡À» Á¤¸®ÇØ 
º»´Ù. 
tablespaceÀÇ temporay type°ú permanent type¿¡ ´ëÇÑ ºñ±³´Â  
¸¦ ÂüÁ¶Çϵµ·Ï ÇÏ°í ¿©±â¿¡¼­´Â permanent¿¡ ´ëÇؼ­´Â ³í¿Ü·Î ÇÑ´Ù. 


Explanation 
----------- 
temporary segment°¡ »ý¼º °¡´ÉÇÑ tablespaceÀÇ type°ú temporary tablesapce¿¡¼­ 
datafile°ú tempfileÀÇ Â÷ÀÌÁ¡À» ¼³¸íÇÑ´Ù. 

1. temporary segment¸¦ »ý¼º°¡´ÉÇÑ tablespace type Á¤¸® 

temporary tablespaceÀÇ tempfile°ú datafileÀ» ºñ±³Çϱâ Àü¿¡, tablespaceÀÇ 
typeµéÀ» È®ÀÎÇØ º¸°í, ÀÌ Áß temporary segment°¡ »ý¼ºµÉ ¼ö ÀÖ´Â tablespace 
typeÀ» versionº°·Î Á¤¸®Çغ»´Ù. 

tablespace´Â 7.2±îÁö´Â permanent typeÀ¸·Î dictionary managed¹æ½ÄÀ¸·Î 
space¸¦ ÇÒ´ç/ÇØÁ¦ÇÏ´ø ¹æ½Ä¸¸ÀÌ Á¸ÀçÇß´Ù. db userÀÇ temporary tablespace·Î 
ÀÓÀÇÀÇ tablespace¸¦ ÁöÁ¤°¡´ÉÇÏ¿´°í, ÇØ´ç db userÀÇ sort operationÀº 
ÁöÁ¤µÈ tablespace¿¡¼­ ¹ß»ýÇϸç, ´Ù¸¥ tablespace¿Í Ưº°È÷ ±¸ºÐµÇ´Â °ÍÀº 
¾ø¾ú´Ù. 

ÀÌÈÄ, 7.3¿¡ temporary typeÀÌ Ãß°¡µÇ°í, 8i¿¡¼­ locally managed type°ú ÀÏ¹Ý 
datafileÀÌ ¾Æ´Ñ tempfileÀÌ ¼Ò°³µÇ¸é¼­ 8i¸¦ ±âÁØÀ¸·Î ±âº»ÀûÀ¸·Î ´ÙÀ½°ú °°ÀÌ 
4°¡Áö ÇüÅÂÀÇ tablespace ÇüÅ°¡ °¡´ÉÇÏ´Ù. 
ÀÌÁß (1) ~ (3)¹ø±îÁö´Â ÀÏ¹Ý datafileÇüÅÂÀÌ°í, (4)¹øÀÇ °æ¿ì´Â ÀÌ ¹®¼­¿¡¼­ 
ÀÚ¼¼È÷ »ìÆ캼 tempfileÀÌ´Ù. 
(locally managed¿Í dictionary managedÀÇ Â÷ÀÌÁ¡ ¹× »ç¿ë ¹æ¹ýÀº 
°ú  ÂüÁ¶) 

  (1) permanent-dictionary managed 
  (2) permanent-locally managed 
  (3) temporary-dictionary managed 
  (4) tempfile-locally managed 

[ÁÖÀÇ] À§ÀÇ Á¾·ù¿¡ temporary datafile¿¡ locally managed ÇüÅÂÀÇ tablespace´Â 
       ¾ø´Â°Í¿¡ ÁÖÀÇÇÑ´Ù. 
       ±×¸®°í ¸¸¾à system tablespace°¡ locally managed·Î ÀÌ¹Ì »ý¼ºµÈ °æ¿ì¿¡´Â 
       ÀÌÈÄ ¸ðµç tablespace´Â locally managed·Î »ý¼ºÀÌ °¡´ÉÇÏ°í, dictionary 
       managed ÇüÅ´ »ý¼ºÇϸé ORA-12913 (Cannot create dictionary managed 
       tablespace) ¿À·ù°¡ ¹ß»ýÇÏ°Ô µÈ´Ù. 


ÀÌ·¯ÇÑ ¿©·¯°¡Áö typeÀÇ tablespaceÁß temporary segment¸¦ »ý¼ºÇÒ ¼ö ÀÖ´Â 
tablespace¿¡ Á¦¾àÀÌ Á¸ÀçÇÑ´Ù. 

- 8i: ¾î¶°ÇÑ ÇüÅÂÀÇ tablespace¶óµµ db userÀÇ temporary tablespace·Î ÁöÁ¤ 
      °¡´ÉÇÏ´Ù. ´Ü, permanent-locally managed ÇüÅÂÀÇ tablespace¿¡ sort°¡ 
      ¹ß»ýÇÏ°Ô µÇ¸é ORA-3212 (Temporary Segment cannot be created in 
      locally-managed tablespace) ¿À·ù°¡ ¹ß»ýÇÏ°Ô µÈ´Ù. 


       SQL> alter user scott temporary tablespace PERM_LOCAL; 
       User altered. 
       
       connect scott/tiger 
       SQL> select * from dept order by 1; 
       ORA-03212: Temporary Segment cannot be created in locally-managed 
                  tablespace 
       
- 9i: db userÀÇ default temporary tablespace ÁöÁ¤ ÀÚü°¡ ´ÙÀ½ µÎ °¡Áö 
      type¸¸ÀÌ °¡´ÉÇÑ´Ù. 

         -temporary-dictionary managed 
         -tempile-locally managed 
         
       ¸¸¾à permanent typeÀÇ tablespace¸¦ db userÀÇ tempoary tablespace·Î 
       ÁöÁ¤Çϸé, ORA-12911 (permanent tablespace cannot be temporary tablespace) 
       ¿À·ù°¡ ¹ß»ýÇÑ´Ù. 


2. tempfile°ú datafileÀÇ ºñ±³ 

¾Æ·¡¿¡¼­ tablespaceÁöÁ¤½Ã tempfile°ú datafileÇüŸ¦ ºñ±³ÇÏ°Ô µÇ´Âµ¥, 
´Ü, datafileÇüÅÂÀÇ °æ¿ì permanent type¿¡ ´ëÇؼ­´Â ¾ð±ÞÇÏÁö ¾Ê´Â´Ù. 

(1) tempileÀÇ Æ¯Â¡ 

    Oracle7.3¿¡¼­ tablespace¿¡ »ý¼º½Ã temporary optionÀ» ÀÌ¿ëÇÏ¿© »ý¼ºµÇ´Â 
    tablespace¸¦ ±¸¼ºÇÏ´Â È­ÀÏÀº datafileÀÌ´Ù. ´ÜÁö ÀÌ°ÍÀÌ ±âÁ¸ÀÇ permanent 
    type°ú ±¸º°µÇ´Â°ÍÀº ÀÌ tablespace¿¡ »ý¼ºµÇ´Â segmentµéÀÌ ¸Å¹ø sort 
    operation¸¶´Ù º°µµ·Î »ý¼ºµÇ´Â ´ë½Å, ÇϳªÀÇ segment·Î ¸¸µé¾îÁö¸é¼­ 
    ´Ù¸¥ session¿¡¼­ÀÇ sort operationÀÌ °°Àº segment¸¦ °øÀ¯ÇÏ´Â °ÍÀÌ´Ù. 
    (ÀÚ¼¼ÇÑ °ÍÀº  ÂüÁ¶) 
   
    Oracle8.1ºÎÅÍ Ãß°¡µÈ tempfileÇüÅÂÀÇ Áß¿äÇÑ Æ¯Â¡Àº tempfile¿¡ ¹ß»ýÇÏ´Â 
    º¯°æ»çÇ×Àº redo log file¿¡ ±â·ÏµÇÁö ¾Ê´Â´Ù´Â °ÍÀÌ´Ù. tempfile¿¡ 
    checkpointÁ¤º¸µµ ±â·ÏÇÏÁö ¾Ê°í ÀÌ¿¡ µû¶ó datafile recovery½Ã¿¡µµ 
    tempfile¿¡ ´ëÇؼ­´Â recovery°¡ ÇÊ¿ä¾ø°Ô µÈ´Ù. 
    ÀÌ¿Í °°Àº ÀÌÀ¯·Î standby database¿¡¼­ read-only mode·Î openÇÏ°í 
    Á¶È¸½Ã sort°¡ ¹ß»ýÇÏ¿© tempfileÀÌ º¯°æµÇ´Â°ÍÀº ¹®Á¦°¡ µÇÁö ¾Ê¾Æ 
    »ç¿ëÀÌ °¡´ÉÇÏ´Ù. 

    ±×¸®°í ÀÌ¹Ì ¾Õ¿¡¼­ ¼³¸íÇÑ °Í°ú °°ÀÌ tempfileÀº Ç×»ó locally managed 
    typeÀ¸·Î¸¸ »ý¼ºÀÌ µÇ¸ç, datafileÇüÅÂÀÇ temporary tablespace´Â ´ÙÀ½°ú 
    °°ÀÌ locally managed typeÀ¸·Î »ý¼º ÀÚü°¡ ºÒ°¡´ÉÇÏ´Ù. 

     SQL> create tablespace temp_datafile_local 
      2   DATAFILE '/ora/oradata/V920/temp_data.dbf' size 100M 
      3   TEMPORARY 
      4   EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K; 
   
     ORA-25144: invalid option for CREATE TABLESPACE with TEMPORARY contents 
     

(2) temporary tablespace »ý¼º ¹æ¹ý ºñ±³ 

  - tempfileÇüÅÂÀÇ °æ¿ì 
    tempfile·Î temporary tablespace¸¦ »ý¼ºÇÏ´Â °æ¿ì´Â ´ÙÀ½°ú °°ÀÌ 
    »ý¼ºÇÏ¿©¾ß Çϸç, ¹Ýµå½Ã locally managed ÇüÅ·θ¸ »ý¼º °¡´ÉÇÏ´Ù. 

     SQL>  create TEMPORARY tablespace temp_tempfile_local 
       2   TEMPFILE '/ora/V920/temp_temp.dbf' size 100M 
       3   EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K; 

    ¾Æ·¡ ¸í·É¾î¿¡¼­ 3¹ø lineÀ» Á¦°ÅÇÏ°í »ý¼ºÇÏ¿©µµ default·Î locally 
    managed·Î »ý¼ºÀÌ µÇ¸ç, dictionary managed ÇüÅ·Π»ý¼ºÇÏ°íÀÚ 
    3¹ø line´ë½Å storage optionÀ» Ãß°¡Çϸé 
    ORA-2180 (invalid option for CREATE TABLESPACE) ¿À·ù°¡ ¹ß»ýÇÑ´Ù. 

  - datafileÇüÅÂÀÇ °æ¿ì     
    ´ÙÀ½°ú °°Àº ÇüÅ·Π»ý¼ºÇÏ°Ô µÇ¸é, dictionary managed typeÀÇ 
    temporary datafileÇüÅ·Πtablespace°¡ ¸¸µé¾îÁø´Ù. ´Ü, 9iÀÇ °æ¿ì 
    ÀÌ¹Ì ¾Õ¿¡¼­ ¾ð±ÞÇÑ´ë·Î system tablespace°¡ locally managedÀÎ °æ¿ì¿¡´Â 
    ÀÌ¿Í °°Àº dictionary managed tablespace »ý¼ºÀº ORA-12913ÀÌ ¹ß»ýÇϸ鼭 
    ºÒ°¡´ÉÇÏ°Ô µÈ´Ù. 

     SQL> create tablespace temp_datafile_dict 
       2  datafile '/ora/oradata/V920/temp_data.dbf' size 100M 
       3  TEMPORARY; 

(3) dictionary view ÀÇ Â÷ÀÌ 

    ¸ÕÀú dba_tablespaces¸¦ ÅëÇØ 
     SQL> select tablespace_name, contents, extent_management, 
          allocation_type from dba_tablespaces; 

     TABLESPACE_NAME          CONTENTS  EXTENT_MAN   ALLOCATIO 
     ------------------------ ---------  ----------  --------- 
     TEMP_TEMPFILE_LOCAL      TEMPORARY LOCAL        UNIFORM 
     TEMP_DATAFILE_DICT       TEMPORARY DICTIONARY 

  - tempfileÀÇ °æ¿ì 

     SQL> select STATUS, ENABLED, NAME from v$tempfile; 

     STATUS  ENABLED    NAME 
     ------- ---------- ---------------------------------- 
     ONLINE  READ WRITE /ora/V920/temp_temp.dbf 

     SQL> select FILE_NAME, TABLESPACE_NAME from dba_temp_files; 

     FILE_NAME                            TABLESPACE_NAME     
     ------------------------------------ ------------------- 
     /ora/V920/temp_temp.dbf  TEMP_TEMPFILE_LOCAL 


  - datafile ÇüÅÂÀÇ °æ¿ì 

    ´ÙÀ½°ú °°ÀÌ v$datafile°ú dba_data_files¸¦ ÅëÇØ Á¶È¸ÇÑ´Ù. 

     SQL> select STATUS, ENABLED, NAME from v$datafile; 

     STATUS  ENABLED    NAME 
     ------- ---------- ---------------------------------- 
     ONLINE  READ WRITE /ora/oradata/V920/temp_data.dbf 

     SQL> select FILE_NAME, TABLESPACE_NAME from dba_data_files; 

     FILE_NAME                            TABLESPACE_NAME     
     ------------------------------------ ------------------- 
     /ora/oradata/V920/temp_data.dbf      TEMP_DATAFILE_DICT 


(4) tempfileÀÇ »èÁ¦¿¡ ´ëÇؼ­ 

    datafileÀÇ °æ¿ì tablespace¸¦ »èÁ¦ÇÏÁö ¾Ê°í datafile¸¸ »èÁ¦ÇÏ´Â ¹æ¹ýÀº 
    Á¸ÀçÇÏÁö ¾Ê´Â´Ù. ¹°·Ð alter database datafile 'filename' offline drop; 
    °ú °°Àº command°¡ ÀÖÁö¸¸ À̰͵µ datafileÀ» µ¥ÀÌŸº£À̽º¿¡¼­ Áö¿öÁÖ´Â 
    °ÍÀÌ ¾Æ´Ï¸ç ÀÌ·¸°Ô offline dropµÈ datafileÀ» Æ÷ÇÔÇÏ´Â tablespace´Â 
    recovery°¡ ºÒ°¡´ÉÇÑ °æ¿ì¶ó¸é tablespaceÀÚü¸¦ »èÁ¦ÇØ¾ß ÇÑ´Ù. 

    ±×·±µ¥ tempfileÀÇ °æ¿ì´Â temporary tablespace´Â ±×´ë·Î À¯ÁöÇÑ Ã¤, 
    tempfile¸¸ »èÁ¦ÇÏ´Â °ÍÀÌ °¡´ÉÇÏ´Ù. 

      SQL> alter database tempfile '/oradata/V817/temp_temp01.dbf' 
        2  drop; 
   
    8iÀÇ °æ¿ì¶ó¸é ÀÌ¿Í °°Àº ¸í·É¾î ÈÄ ½ÇÁ¦ directory·Î À̵¿ÇÏ¿© Á÷Á¢ 
    tmep_temp01.dbf¸¦ »èÁ¦ÇÏ¿©¾ß ÇÑ´Ù. 

    9i¿¡¼­´Â dropµÚ¿¡ including datafiles ¶ó´Â optionÀ» Ãß°¡ÇÏ¿© tempfileÀÇ 
    drop½Ã ¹Ù·Î os»ó¿¡¼­µµ »èÁ¦µÇµµ·Ï ÇÒ ¼ö ÀÖ´Ù. 

      SQL> alter database tempfile '/oradata/V817/temp_temp01.dbf' 
        2  drop including contents; 

    ¸¸¾à ÀÌ·¯ÇÑ ¹æ¹ýÀ¸·Î, tempfileÀ» ÇØ´ç temporary tablespace¿¡¼­ ¸ðµÎ 
    »èÁ¦ÇÑ °æ¿ì, ½ÇÁ¦ ÇØ´ç tablespace¿¡ disk sort°¡ ÇÊ¿äÇÏ°Ô µÇ¸é, 
    ±×¶§´Â ORA-25153 (Temporary Tablespace is Empty) ¿À·ù°¡ ¹ß»ýÇÏ°Ô µÈ´Ù. 

    À̶§´Â ´ÙÀ½°ú °°ÀÌ ÀÓÀÇÀÇ tempfileÀ» ´Ù½Ã Ãß°¡ÇÒ ¼ö ÀÖ´Ù. 

      SQL> alter tablespace TEMP_TEMPFILE_LOCAL 
        2  add tempfile '/oradata/V817/temp_temp02.dbf'; 




#################################
# 
#################################