3.2. Creating a New Temporary Tablespace

A temporary tablespace is responsible for various database sorting operations. A temporary tablespace is part of the physical database files, which the Oracle control file will expect to exist under normal operations. Because the temporary tablespace doesn't have any permanent objects stored within it, there is no change in the system change number (SCN) from the checkpoint process in the control file or file header. The database will continue to function normally, with the exception of creating temporary segments, which occurs when creating indexes or performing certain select statements. Because the temporary tablespace only has temporary data stored inside, this tablespace can be re-created and reassigned in the event of datafile loss.

For example, in a media failure such as a disk failure or controller failure, the temporary datafile could become unavailable. This would cause sorting operations such as creating indexes or select statements to fail. The remedy for this situation is to drop the tablespace—including its contents if they exist—which will remove the datafile and tablespace reference from the data dictionary. Then you simply create the temporary tablespace.

Real World Scenarlo: Before Shutdown, Always Check If the Backup Is Complete

RMAN backups called by media management vendors' software can be automated to the extent that your involvement as a DBA is minimal. This is sometimes executed and controlled by the backup coordinator, which may reside within the systems administrators group. When the backup terminates for some reason, it is often difficult for you to know the extent of a backup failure and why a backup has failed, unless good communication is set up, thus leaving the database partially in backup mode with some tablespaces and the associated datafiles active in backup. Furthermore, jobs could be incomplete and hanging in the recovery catalog.

What happens when the database goes down when a tablespace or all tablespaces are in is in backup mode? The datafile is not checkpointed so that it is consistent with the rest of the database. When the database is restarted, the datafile is marked as inconsistent and in need of recovery. This situation can come as an unwanted surprise when you are bouncing the database for some reason.

You can remedy this situation without recovery by issuing the ALTER DATAFILE 'datafile name'END BACKUP command to fix this tablespace or by issuing the new Oracle 10g command ALTER DATABASE END BACKUP for all tablespaces at the same time. However, this situation can be avoided by checking the V$BACKUP table to validate that it is safe to shut down the database.


Let's see an example of creating a new temporary tablespace with the database up and running using a tempfile or locally managed extents:

SQL> create temporary tablespace temp2 tempfile
       
'C:oracleoradataora101t emp2_01.dbf' size 100m
extent management local uniform size 128k;

NOTE

You should use the TEMPFILE keyword and create the temporary tablespace as TEMPORARY TABLESPACE so that no permanent objects can be stored in the tablespace.

As you can see, being able to create a new temporary tablespace is an essential non-critical recovery task. Because there are no permanent objects in the temporary tablespace, you can easily re-create a new temporary tablespace. In the next sections, we will work with additional temporary tablespace issues. Specifically, you will learn how to deal with missing tempfiles and how to reassign the temporary tablespace.

3.2.1. Starting the Database with a Missing Tempfile

Starting a database with a missing tempfile is another non-critical recovery technique that you need to understand. A tempfile is a type of tablespace where management occurs locally or in the tablespace, as opposed to in the data dictionary. These types of tablespaces were first introduced in Oracle 8i and have significant improvements for sorting and space management. The temp-file can be used with all tablespaces as of Oracle9i. They are most commonly used with temporary tablespaces and are the default for the Database Configuration Assistant (DBCA) temporary tablespace creation.

The steps to start a database with a missing tempfile are fairly straightforward:

  1. Start and mount the database if it is not already running:

    C:Documents and Settingsdstuns>sqlplus /nolog
    
    SQL*Plus: Release 10.1.0.2.0 - Production on Sat Aug 21 19:08:48 2004
    
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    
    SQL> connect / as sysdba
    Connected.
    SQL> startup mount
    ORACLE instance started.
    
    Total System Global Area    88080384    bytes
    Fixed Size                  787588      bytes
    Variable Size               78642044    bytes
    Database Buffers            8388608     bytes
    Redo Buffers                262144      bytes
    Database mounted.
    SQL>

  2. Next, drop the tablespace:

    SQL> drop tablespace temp including contents;

  3. Finally, re-create the temporary tablespace using the following command. In the Windows environment, use C:directory to specify the file; in the Unix environment, use /directory to specify the file.

    SQL> create temporary tablespace temp tempfile
      
    'C:oracleoradataora101t emp01.dbf' size 100m
    extent management local uniform size 128k; Tablespace created.

3.2.2. Altering the Default Temporary Tablespace for a Database

Another method for remedying the loss of a temporary tablespace is to modify the existing temporary tablespace to a new or different temporary tablespace. This can be accomplished by using the ALTER DATABASE DEFAULT TEMPORARY TABLESPACE command. This is a fairly straightforward process. First, there must be a temporary tablespace existing in the database. If not, you will need to create a temporary tablespace to switch as the default tablespace.

Let's walk through an example:

  1. First, create a temporary tablespace if one doesn't exist:

    SQL> create temporary tablespace temp2 tempfile
      
    'C:oracleoradataora101t emp2_01.dbf' size 100m
    extent management local uniform size 128k; Tablespace created.

  2. Next, alter the default temporary tablespace to a different temporary tablespace using the following command:

    SQL> alter database default temporary tablespace temp2;
    
    Database altered.

NOTE

You must have another temporary tablespace available. If you attempt to switch the default tablespace to a permanent tablespace, you will get an ORA-12904 default temporary tablespace cannot be altered to PERMENANT type error.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset