Oracle's Default TEMPORARY Tablespaces - Page 2October 10, 2003 The TEMPORARY TablespaceYou can create a TEMPORARY tablespace by issuing the statement in Listing 3. This is the simplest form of the CREATE TEMPORARY command. You may also issue a statement such as in Listing 4. The difference in the two statements is the specifying of the TEMPFILE location. In the first example, Oracle will use the initialization parameter DB_CREATE_FILE_DEST if specified. If this parameter is not specified you must use the statement in Listing 4 or the statement will fail. If you would like to set the DB_CREATE_FILE_DEST, just issue a statement such as that in Listing 5. If you are wondering how the files look for the tablespaces just created you can look at Listing 6. Listing 3 CREATE TEMPORARY TABLESPACE temp01 Listing 4
CREATE TEMPORARY TABLESPACE temp02
TEMPFILE 'C:\ORACLE\ORADATA\HCMC\ts02.tmp' SIZE 100M;
Listing 5 alter system set db_create_file_dest = 'C:\ORACLE\ORADATA\HCMC'; Listing 6 -SQL> select tablespace_name,file_name,bytes/1024/1024 from dba_temp_files; TABLESPACE_NAME FILE_NAME BYTES/1024/102 ----------------- ------------------------------------------------ -------------- TEMP01 C:\ORACLE\ORADATA\HCMC\O1_MF_TEMP01_ZR0VCW00_.TMP 100 TEMP02 C:\ORACLE\ORADATA\HCMC\TS02.TMP 100 The DEFAULT TEMPORARY TablespaceThe default temporary tablespace is nothing more than a temporary tablespace that has been designated a global temporary tablespace for all users that have not been explicitly defined a temporary tablespace at user creation time. You can specify a default temporary tablespace by issuing a statement such as in Listing 7. Listing 7 ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp01; Now if we were to create a user, their temporary tablespace would be TEMP01. The best thing about using default temporary tablespaces is that if you were to switch the default temporary tablespace, all users that were assigned the initial default temporary tablespace would inherit the new default temporary tablespace. Take a look at Listing 8 to see the progression of switching a default temporary tablespace and the users' inheriting it. Listing 8 -SQL> CREATE USER tempuser IDENTIFIED BY tempuser; User created. -SQL> select username,temporary_tablespace from dba_users where username = 'TEMPUSER'; USERNAME TEMPORARY_TABLESPACE ------------------------------ ------------------------------ TEMPUSER TEMP01 -SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp02; Database altered. -SQL> select username,temporary_tablespace from dba_users where username = 'TEMPUSER'; USERNAME TEMPORARY_TABLESPACE ------------------------------ ------------------------------ TEMPUSER TEMP02 The DEFAULT TablespaceOk, too much of a good thing. Now the last remaining problem with creation of a user is the DEFAULT tablespace. When we create a user and do not specify the default tablespace, the user is assigned the SYSTEM tablespace. Look at Listing 9. I personally will look to Oracle to change this very soon. I understand the reasoning behind assigning temporary tablespaces and default tablespaces to the SYSTEM tablespace in earlier versions. Most of the systems were not that large and many installations were just running with the SYSTEM tablespace. The unfortunate thing is that today, a single tablespace cannot hold all the data and performance is much more important in the systems of today. Listing 9
-SQL> select username,temporary_tablespace,default_tablespace
from dba_users where username = 'TEMPUSER';
USERNAME TEMPORARY_TABLESPACE DEFAULT_TABLESPACE
--------------- ------------------------------ ------------------------------
TEMPUSER TEMP02 SYSTEM
In previous releases of Oracle, if you forgot to assign a
temporary tablespace to a user, the SYSTEM tablespace was used. This could and
did cause some major contention and performance issues. Oracle has always
stated that it was a bad practice to assign the SYSTEM tablespace to a users'
default or temporary tablespace. While getting the DEFAULT tablespace
assignment still requires some intervention, the assigning of a TEMPORARY
tablespaces has become a bit less worrisome. |