Tablespace Management In Oracle Version

There are two type of tablespace management LMT and DMT.
LMT:(local managed tablespace)
It came from 9i. the block information(free or used) will maintain in datafile header as 0’s & 1’s.

 DMT:(dictionary managed tablespace)
The extent information will maintain in data dictionary as FET$ and UET$.
          
DIFFERENCE BETWEEN LMT AND DMT:
No
DMT                                                             
LMT
1
2
3
4
free list maintain in data dictionary as FET$,UET$
high  I/O  process will happen
manual coalesce
more undo generated
free list maintain in data file header as 0’s & 1’s
less I/O process will happen
auto coalesce
Less undo generated
EXTENT MANAGEMENT:
collection of blocks is called as extent.
using local managed tablespace  the extent size can be managed like UNIFORM or

AUTOALLOCATE.
UNIFORM:
The extent size will allocated as same size for every new extent.
AUTOALLOCATED:
It take the default values base on storage parameters.
(STORAGE PARAMETERS IN EXTENT MANAGEMENT):
Intial   – first extent values
Next – next values in segments
Min Extents – minimum amount of extent get created at a time of table/segment.
Max Extents   – unlimited
Pct Increase – 50% of increase for next extent value.
Logging -it allow all sql statement to write in online redo logs except (select).
No-logging   – it opposite to logging and when giving the rebuild index,cts,insert into table from select statement this ill not write in online redo logs.
Blocksize  – this parameter is using to specifies the block size .
Online  –   it show the tablespcae in online .
Offline  –  after creation tablespace it show in offline.
Permanent   – it hold the permanent database objects.
Temporary   – it hold the temporary databasse objects.
(next extent/growth=prev.extent + (pct increase x prev.extent)—- this is formula for 3rd extent
In DMT Tablespace:
   create tablespace  sainora datafile ‘/u01/app/oracle/oradata/data/sainora.dbf’ size 200m extent management dictionary default  storage (intial 1m next 2m minextents  1 maxextents 10 pct increase 50%);
In LMT Tablespace:
create tablespace sainora datafile ‘/u01/app/oracle/oradata/data/sainora.dbf’ size 200m extent management local uniform size 1m;
       create tablespace sainora datafile ‘/u01/app/oracle/oradata/data/sainora.dbf’ size 200m extent management local autoallocate;
    
SEGMENT MANAGEMENT:
Collection of extents is called as segment.
It using to managed the free and used space with in a segments. it can mention as
MANUAL or AUTO.
MANUAL:
 mention the data block size for each segments using the space parameter.
AUTO:
It take automatic values based on data blocks.
It managed the free space automatically.         

(SPACE  PARAMETER IN SEGMENT MANAGEMENT):
Pct free  – 10% for updates.
Pct used  – to find the block where free or  used.
Init trans  – intial transaction for each block
Max trans  – max transaction for each block
In DMT Tablespace (manual):
create table  san_tab(id number(9),name varchar2(9) pctfree 20 pctused 50 inittrans 3 maxtrans 10;

In LMT Tablespace(auto/manual):
create table san_tab(id number(9),name varchar2(9));
VIEWS:
DBA_EXTENTS
USER_EXTENTS
DBA_DATA_FILES
V$DATAFILE
V$TABLESPACE
DBA_FREE_SPACE
DBA_SEGMENTS
USER_SEGMENTS
DBA_TABLESPACES
USER_TABLESPACES
ASSIGNMENT QUESTIONS:
1.increase the max extent.
2.find the 3rd extent size.
3.create LMT tablespace using  storage parameter(nologging).
4.how will you change the extent size,it is possible or not.
INTERVIEW  QUESTIONS:
1.find the num of extent in a table.
2.convert the dmt tablespace into lmt tablespace.
3.fine the tablespace where lmt or dmt.
4.diff between lmt and dmt.
5.how will u change the extent size.
6.when  show error like (unable to create extent)what u do?.
7.find block size and extent size in particular table or segments.

Tablespaces Monitoring,Auditing,Add,Delete,Rename,Drop,Views Relocate -Oracle

  • A database is divided  into One or more logical storage units called tablespace.
  • collection of datafiles is called as tablespace.
TYPES OF TABLESPACE:
  1. Permanent  Tablespaces
  2. Undo Tablespace
  3. Temporary Tablespaces
1.PERMANENT TABLESPACE:
(Users data files and normally contains the system (data dictionary) and users data)
 
System
  • Is  a permanent tablespace and contains the vital data dictionary (metadata about the database).
  • It created when database is created.
  • It always in online.
  • It stores tables that support the core functionality of the database such as the data dictionary tables.
  • Cannot rename or drop the system tablespace
Sysaux
  • Its introduce in oracle 10g.
  • Is an auxiliary tablespace to the system tablespace and contains performance statistics collected by the database.(ex:logminar,oracle streams)
  • It cannot be dropped or renamed.
  • Sysaux tablespace may be taken offline for performing tablespace recovery.
USER DEFINED TABLESPACES:
  • Is used to store organizational data in table accessed by application programs.
  • Flexibility in database administration.
  • Separate  data by backup reruitrmrnts.
  • Separate dynamic and static data to enable database tuning.
  • Control space allocation for both applications and system users.
  • Reduce contention for input/output path access.
Create tablespace:
Syntax:
Create  tablespace   data_tbs  datafile  ‘/home/oracle/data/data_tbs.dbf’ size 200m;
Adding  datafile :
Syntax:
Alter  tablespace  data_tbs  add  datafile  ‘/home/oracle/data/data02_tbs.dbf’ size 200m;
Renaming  tablespace:
Syntax:
Alter  tablespace  data_tbs   rename  to  data_old_tbs;
Dropping tablespace:
Syntax:
Drop tablespace  data_tbs;
Resize the datafile :
Syntax:
Alter database  datafile  ‘/home/oracle/data/data_tbs.dbf’  resize  size 300m;
Relocating  tablespace/datafile:
Syntax:
Step 1 shut the database
Step 2 use copy command to move the phy file to new location
Step 3 mount the database
Step 4 excute this command
Alter tablespcae data_tbs rename datafile ‘/home/oracle/data/data_tbs.dbf’ to ‘/home/oracle/king/data_tbs.dbf’;
Quotas on tablespces:
Syntax:
Alter user schema01 quota 50m on data_tbs;
Read only tablespace:
Syntax:
Alter tablespace data_tbs read only;
Offline/online  tablespace:
Syntax:
Alter tablespace data_tbs offline;
Alter tablespace data_tbs online;
Assing tablespace to user:
Syntax:
Alter user schema01 default tablespace data_tbs;
Bigfile tablespace:
It is new feature of oracle 10g and it contain the single datafile and allocate large size up to 4g.
It reduce the disk I/O.
Syntax:
Create  bigfile tablespace  userdata datafile  ‘/home/oracle/data/userdata.dbf’ size  10g;
Resize the bigfile tablespace:
Syntax:
Alter tablespace userdata resize 20g;
Tablespace creation in ASM:
syntax:
create tablespace sainora datafile ‘+dg1’ size 200m;
Adding datafile in ASM:
syntax:
alter tablespace sainora add datafile ‘+dg1’ size 200m;
Droping tablespace in ASM:
syntax:
drop tablespace sainora;
Drop datafile in ASM:
syntax:
alter tablespace sainora drop datafile ‘+dg1/sainora.dbf ‘;
VIEWS:
DBA_DATA_FILES
V$DATAFILE
DBA_SEGMENTS
DBA_USERS
DBA_FREE_SPACE
DBA_TABLESPACES
V$TABLESPACE
ASSIGNMENT QUESTIONS:
1.create tablespace size with 2m and insert the values above 10,00,000.
2.add the datafile in tablespace.
3.create tablespace without giving the datafile location.
4.rename the tablespace name give syntax.
5.find the default location of tablespace.
INTERVIEW QUESTIONS:                                                                               
1.create the tablespace size with 1gb.
2.How to assign quota to more then one user for same tablespace.
3.How will u drop the system tablespace.
4.resize the sysaux tablespace give syntax.
5.find the tablespace size and status.
6.find the datafile location and size.
7.find how many datafile is there in a single tablespace.
8.how to check the used space of tablespace.
9.find the free space of tablespace.
10.use of bigfile tablespace.

moving and renaming datafiles –oracle

Moving datafiles of a database: The datafiles reside under /home/oracle/OraHome1/databases/ora9 and have go to /home/oracle/databases/ora9.

SQL> select tablespace_name, substr(file_name,1,70) from dba_data_files;
TABLESPACE_NAME                SUBSTR(FILE_NAME,1,70)
—————————— ———————————————————————-
SYSTEM                         /home/oracle/OraHome1/databases/ora9/system.dbf
UNDO                           /home/oracle/OraHome1/databases/ora9/undo.dbf
DATA                           /home/oracle/OraHome1/databases/ora9/data.dbf

SQL> select member from v$logfile;
MEMBER
——————————————————————————–
/home/oracle/OraHome1/databases/ora9/redo1.ora
/home/oracle/OraHome1/databases/ora9/redo2.ora
/home/oracle/OraHome1/databases/ora9/redo3.ora

SQL> select name from v$controlfile;
NAME
——————————————————————————–
/home/oracle/OraHome1/databases/ora9/ctl_1.ora
/home/oracle/OraHome1/databases/ora9/ctl_2.ora
/home/oracle/OraHome1/databases/ora9/ctl_3.ora

Now, as the files to be moved are known, the database can be shut down:
SQL> shutdown

The files can be copied to their destination:
$ cp /home/oracle/OraHome1/databases/ora9/system.dbf  /home/oracle/databases/ora9/system.dbf
$ cp /home/oracle/OraHome1/databases/ora9/undo.dbf    /home/oracle/databases/ora9/undo.dbf
$ cp /home/oracle/OraHome1/databases/ora9/data.dbf    /home/oracle/databases/ora9/data.dbf

$ cp /home/oracle/OraHome1/databases/ora9/redo1.ora   /home/oracle/databases/ora9/redo1.ora
$ cp /home/oracle/OraHome1/databases/ora9/redo2.ora   /home/oracle/databases/ora9/redo2.ora
$ cp /home/oracle/OraHome1/databases/ora9/redo3.ora   /home/oracle/databases/ora9/redo3.ora

$ cp /home/oracle/OraHome1/databases/ora9/ctl_1.ora   /home/oracle/databases/ora9/ctl_1.ora
$ cp /home/oracle/OraHome1/databases/ora9/ctl_2.ora   /home/oracle/databases/ora9/ctl_2.ora
$ cp /home/oracle/OraHome1/databases/ora9/ctl_3.ora   /home/oracle/databases/ora9/ctl_3.ora

The init.ora file is also copied because it references the control files. I name the copied file just init.ora because it is not in a standard place anymore and it will have to be named explicitely anyway when the database is started up.
$ cp /home/oracle/OraHome1/dbs/initORA9.ora /home/oracle/databases/ora9/init.ora

The new location for the control files must be written into the (copied) init.ora file:
/home/oracle/databases/ora9/init.ora
control_files = (/home/oracle/databases/ora9/ctl_1.ora,
                 /home/oracle/databases/ora9/ctl_2.ora,
                 /home/oracle/databases/ora9/ctl_3.ora)

$ sqlplus “/ as sysdba”
SQL> startup exclusive mount pfile=/home/oracle/databases/ora9/init.ora
SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/system.dbf’ to ‘/home/oracle/databases/ora9/system.dbf’;
SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/undo.dbf’   to ‘/home/oracle/databases/ora9/undo.dbf’;
SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/data.dbf’   to ‘/home/oracle/databases/ora9/data.dbf’;

SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/redo1.ora’  to ‘/home/oracle/databases/ora9/redo1.ora’;
SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/redo2.ora’  to ‘/home/oracle/databases/ora9/redo2.ora’;
SQL> alter database rename file ‘/home/oracle/OraHome1/databases/ora9/redo3.ora’  to ‘/home/oracle/databases/ora9/redo3.ora’;

SQL> shutdown

SQL> startup pfile=/home/oracle/databases/ora9/init.ora

Moving Datafiles with/without shutting down the database –oracle

Moving Datafiles with shutting down the database
$ sqlplus “/ as sysdba”
SQL> shutdown immediate
SQL> !mv /u03/oradata/PROD/devl_PROD_01.dbf /u04/oradata/PROD
SQL> startup mount
SQL> alter database rename file ‘/u03/oradata/PROD/devl_PROD_01.dbf’
            to ‘/u04/oradata/PROD/devl_PROD_01.dbf’;
SQL> alter database open;
SQL> select * from v$datafile


Moving Datafiles without shutting down the databa
$ sqlplus “/ as sysdba”
SQL> alter tablespace development offline;
SQL> !mv /u03/oradata/PROD/devl_PROD_01.dbf /u04/oradata/PROD
SQL> alter database rename file ‘/u03/oradata/PROD/devl_PROD_01.dbf’
            to ‘/u04/oradata/PROD/devl_PROD_01.dbf’;
SQL> alter tablespace development online;
SQL> select * from v$datafile;

tablespace create,add,delete,alter,views

Tablespace : is logical storage unit in Oracle Database.
ii) Tablespace connsit of one or more datafiles (check below)
iii) Information about Tablespace can be obtained from view DBA_TABLESPACES, USER_TABLESPACES, DBA_TEMP_FILES (for Temporary Tablespaces)
iv) Tablespace is further divided in to logical units Segments (Segment is divided in to Extent and Extent in to Block) . To know more about Segment, Extents and Blocks click here
v) Various type of tablespace are BIGFILE, SYSTEM, SYSAUX, UNDO
Datafiles : is physical structure to store oracle data
ii) One or more physical datafile are logically grouped together to make a tablespace
iii) Information about Datafile can be obtained from view DBA_DATA_FILESiv) A Datafile can be associated with only one tablespace
Adding Tablespace in databaseUse CREATE TABLESPACE command to add tablespace in Database like
CREATE TABLESPACE DATAFILE
CREATE TABLESPACE my_tablespace DATAFILE ‘/u01/oracle/oradata/data01.dbf’;
To create undo tablespace
CREATE UNDOTABLESPACE  DATAFILE SIZE [AUTOEXTEND ON|OFF] [RETENTION GURANTEE|NOGURANTEE]
To create Temporary tablespace
CREATE TEMPORARYTABLESPACE  TEMPFILE SIZE [AUTOEXTEND ON|OFF] 
Adding Datafile in a TablespaceUse ALTER TABLESPACE to add datafile in tablespace like
ALTER TABLESPACE ADD DATAFILE
ALTER TABLESPACE my_tablespace ADD DATAFILE ‘/u01/oracle/oradata/data02.dbf’;
To add temporary file in TEMP table space
ALTER TABLESPACE ADD TEMPFILE ‘’ SIZE ;
Modify DatafileYou can modify datafile using ALTER DATABASE command like
ALTER DATABASE DATAFILE  AUTOEXTEND ON|OFF NEXT MAXSIZE ;
ALTER DATABASE DATAFILE ‘/u01/oracle/oradata/data02.dbf’ AUTOEXTEND ON NEXT 30M MAXSIZE 1200M;
which means datafile data02.dbf can automatically grow upto 1200 MB size in blocks of 30 MB each time as required.

tablespace AUTOEXTEND ON Next Size

AUTOEXTEND ON Next Size

UPDATE 28-Feb-11 : Apparently, in 11gR1, Bug 8318050 affects the behaviour of
Autoextend On datafiles such that the NEXT size specified may not be honoured. See
Oracle Support Article#8318050.8

In a CREATE TABLESPACE command, the DATAFILE clause is the Physical Specification
component.

In pre- 9i/10g OMF manner, the DATAFILE must be specified. A (initial) filesize must
also be specified. However, Autoextend’s NEXT size is not mandatory and Oracle can
“default”. Very unfortunately, the default AUTOEXTEND ON NEXT size is 1 Database
block (based on the blocksize of the tablespace).

But if you create your Tablespace using OMF (i.e. where “db_create_file_dest” is
configured), then Oracle defaults the initial size to 100MB and *also* defaults
the AUTOEXTEND to ON with a of 100MB ! That is much neater.

Why is the default 1 Database block bad ? Because when the datafile is full, Oracle
will extend it 1 block at-a-time, making a call to the OS to add 1 block on each
occassion. Obviously, even if you are extending a table or index with an Extent
 of 64KB, Oracle has to make 8 calls to the OS (with a datafile block size of 8KB).
That is where you will see “data file init write” waits.

In the example below, the (automatic) datafile for Tablespace AN_OMF_TBS get’s
created with both the initial and increment at 100MB and AutoExtend ON. However,
 for Tablespace REGULAR_TBS, I have to specify the initial size for the datafile.
If I do not specify AutoExtend, the file is created with AutoExtend OFF. For the
third tablespace, called ANOTHER_TBS, when I designate AutoExtend ON but do not
specify the incremental size, Oracle defaults it to 1 Oracle Block.

SQL> select tablespace_name, file_name, bytes/1048576 File_Size_MB, autoextensible,
increment_by from dba_data_files order by file_id;

TABLESPACE_NAME FILE_NAME                                               FILE_SIZE_MB AUT INCREMENT_BY
————— ——————————————————- ———— — ————
SYSTEM          /oracle_fs/Databases/ORT24FS/system01.dbf                        590 YES        1,280
UNDOTBS1        /oracle_fs/Databases/ORT24FS/undotbs01.dbf                       155 YES          640
SYSAUX          /oracle_fs/Databases/ORT24FS/sysaux01.dbf                        270 YES        1,280
USERS           /oracle_fs/Databases/ORT24FS/users01.dbf                          85 YES          160
EXAMPLE         /oracle_fs/Databases/ORT24FS/example01.dbf                       100 YES           80
TEST_A_TBS      /oracle_fs/Databases/ORT24FS/test_a_tbs.dbf                      100 NO             0

6 rows selected.

SQL> alter system set db_create_file_dest=’/var/tmp’;

System altered.

SQL> create tablespace an_omf_tbs;

Tablespace created.

SQL> select tablespace_name, file_name, bytes/1048576 File_Size_MB, autoextensible,
increment_by from dba_data_files order by file_id;

TABLESPACE_NAME FILE_NAME                                               FILE_SIZE_MB AUT INCREMENT_BY
————— ——————————————————- ———— — ————
SYSTEM          /oracle_fs/Databases/ORT24FS/system01.dbf                        590 YES        1,280
UNDOTBS1        /oracle_fs/Databases/ORT24FS/undotbs01.dbf                       155 YES          640
SYSAUX          /oracle_fs/Databases/ORT24FS/sysaux01.dbf                        270 YES        1,280
USERS           /oracle_fs/Databases/ORT24FS/users01.dbf                          85 YES          160
EXAMPLE         /oracle_fs/Databases/ORT24FS/example01.dbf                       100 YES           80
TEST_A_TBS      /oracle_fs/Databases/ORT24FS/test_a_tbs.dbf                      100 NO             0
AN_OMF_TBS      /var/tmp/ORT24FS/datafile/o1_mf_an_omf_t_541wgb0c_.dbf           100 YES       12,800

7 rows selected.

SQL> create tablespace REGULAR_TBS datafile ‘/oracle_fs/Databases/ORT24FS/regular_tbs.dbf’;
create tablespace REGULAR_TBS datafile ‘/oracle_fs/Databases/ORT24FS/regular_tbs.dbf’
*
ERROR at line 1:
ORA-01119: error in creating database file ‘/oracle_fs/Databases/ORT24FS/regular_tbs.dbf’
ORA-17610: file ‘/oracle_fs/Databases/ORT24FS/regular_tbs.dbf’ does not exist and no size specified
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

SQL> create tablespace REGULAR_TBS datafile ‘/oracle_fs/Databases/ORT24FS/regular_tbs.dbf’ size 100M;

Tablespace created.

SQL> select tablespace_name, file_name, bytes/1048576 File_Size_MB, autoextensible, increment_by from
dba_data_files order by file_id;

TABLESPACE_NAME FILE_NAME                                               FILE_SIZE_MB AUT INCREMENT_BY
————— ——————————————————- ———— — ————
SYSTEM          /oracle_fs/Databases/ORT24FS/system01.dbf                        590 YES        1,280
UNDOTBS1        /oracle_fs/Databases/ORT24FS/undotbs01.dbf                       155 YES          640
SYSAUX          /oracle_fs/Databases/ORT24FS/sysaux01.dbf                        270 YES        1,280
USERS           /oracle_fs/Databases/ORT24FS/users01.dbf                          85 YES          160
EXAMPLE         /oracle_fs/Databases/ORT24FS/example01.dbf                       100 YES           80
TEST_A_TBS      /oracle_fs/Databases/ORT24FS/test_a_tbs.dbf                      100 NO             0
AN_OMF_TBS      /var/tmp/ORT24FS/datafile/o1_mf_an_omf_t_541wgb0c_.dbf           100 YES       12,800
REGULAR_TBS     /oracle_fs/Databases/ORT24FS/regular_tbs.dbf                     100 NO             0

8 rows selected.

SQL> create tablespace ANOTHER_TBS datafile ‘/oracle_fs/Databases/ORT24FS/another_tbs.dbf’ size 100M autoextend on ;

Tablespace created.

SQL> select tablespace_name, file_name, bytes/1048576 File_Size_MB, autoextensible, increment_by from dba_data_files
order by file_id;

TABLESPACE_NAME FILE_NAME                                               FILE_SIZE_MB AUT INCREMENT_BY
————— ——————————————————- ———— — ————
SYSTEM          /oracle_fs/Databases/ORT24FS/system01.dbf                        590 YES        1,280
UNDOTBS1        /oracle_fs/Databases/ORT24FS/undotbs01.dbf                       155 YES          640
SYSAUX          /oracle_fs/Databases/ORT24FS/sysaux01.dbf                        270 YES        1,280
USERS           /oracle_fs/Databases/ORT24FS/users01.dbf                          85 YES          160
EXAMPLE         /oracle_fs/Databases/ORT24FS/example01.dbf                       100 YES           80
TEST_A_TBS      /oracle_fs/Databases/ORT24FS/test_a_tbs.dbf                      100 NO             0
AN_OMF_TBS      /var/tmp/ORT24FS/datafile/o1_mf_an_omf_t_541wgb0c_.dbf           100 YES       12,800
REGULAR_TBS     /oracle_fs/Databases/ORT24FS/regular_tbs.dbf                     100 NO             0
ANOTHER_TBS     /oracle_fs/Databases/ORT24FS/another_tbs.dbf                     100 YES            1

9 rows selected.

SQL>

You would be well-adviced to remember that when you create or add a non-OMF datafile,
you should specify the Increment size with the AutoExtend ON. Else, you might suffer
the overheads of Oracle having to make multiple calls to the OS whenever extending the datafile (imagine extending a datafile 1 block at each call for an extent of 64MB !)

SQL> create tablespace LAST_TBS datafile ‘/oracle_fs/Databases/ORT24FS/last_tbs.dbf’
size 100M autoextend on next 100M;

Tablespace created.

SQL> select tablespace_name, file_name, bytes/1048576 File_Size_MB, autoextensible,
increment_by from dba_data_files order by file_id;

TABLESPACE_NAME FILE_NAME                                               FILE_SIZE_MB AUT INCREMENT_BY
————— ——————————————————- ———— — ————
SYSTEM          /oracle_fs/Databases/ORT24FS/system01.dbf                        590 YES        1,280
UNDOTBS1        /oracle_fs/Databases/ORT24FS/undotbs01.dbf                       155 YES          640
SYSAUX          /oracle_fs/Databases/ORT24FS/sysaux01.dbf                        270 YES        1,280
USERS           /oracle_fs/Databases/ORT24FS/users01.dbf                          85 YES          160
EXAMPLE         /oracle_fs/Databases/ORT24FS/example01.dbf                       100 YES           80
TEST_A_TBS      /oracle_fs/Databases/ORT24FS/test_a_tbs.dbf                      100 NO             0
AN_OMF_TBS      /var/tmp/ORT24FS/datafile/o1_mf_an_omf_t_541wgb0c_.dbf           100 YES       12,800
REGULAR_TBS     /oracle_fs/Databases/ORT24FS/regular_tbs.dbf                     100 NO             0
ANOTHER_TBS     /oracle_fs/Databases/ORT24FS/another_tbs.dbf                     100 YES            1
LAST_TBS        /oracle_fs/Databases/ORT24FS/last_tbs.dbf                        100 YES       12,800

10 rows selected.

SQL>  

Creating Temporary Tablespace

Creating Temporary Tablespace
From Oracle 9i, we can specify a default temporary tablespace when you create a
 database, using the DEFAULT TEMPORARY TABLESPACE extension to the CREATE DATABASE
statement.
e.g.
SQL> CREATE DATABASE oracular …..
DEFAULT TEMPORARY TABLESPACE temp_ts …..;

Oracle provides various ways of creating TEMPORARY tablespaces.
Prior to Oracle 7.3 – CREATE TABLESPACE temp DATAFILE …;
Example:
SQL> CREATE TABLESPACE TEMPTBS DATAFILE ‘/path/temp.dbf’ SIZE 2048M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING DEFAULT NOCOMPRESS ONLINE EXTENT
MANAGEMENT DICTIONARY;

Oracle 7.3 & 8.0 – CREATE TABLESPACE temp DATAFILE … TEMPORARY;
Example:
SQL> CREATE TABLESPACE TEMPTBS DATAFILE ‘/path/temp.dbf’ SIZE 2048M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING DEFAULT NOCOMPRESS ONLINE
TEMPORARY EXTENT MANAGEMENT DICTIONARY;

Oracle 8i and above – CREATE TEMPORARY TABLESPACE temp TEMPFILE …;
Examples:
SQL> CREATE TEMPORARY TABLESPACE TEMPTBS TEMPFILE ‘/path/temp.dbf’ SIZE 1000M
AUTOEXTEND ON NEXT 8K MAXSIZE 1500M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
BLOCKSIZE 8K;

SQL> CREATE TEMPORARY TABLESPACE TEMPTBS2 TEMPFILE ‘/path/temp2.dbf’ SIZE 1000M
AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL BLOCKSIZE 2K;

The MAXSIZE clause will default to UNLIMITED, if no value is specified.
All extents of temporary tablespaces are the same size, so UNIFORM keyword is
optional – if UNIFORM is not defined it will default to 1 MB.

Example using OMF (Oracle Managed Files):
SQL> CREATE TEMPORARY TABLESPACE temp;

Restrictions:
(1) We cannot specify nonstandard block sizes for a temporary tablespace or if you
intend to assign this tablespace as the temporary tablespace for any users.
(2) We cannot specify FORCE LOGGING for an undo or temporary tablespace.
(3) We cannot specify AUTOALLOCATE for a temporary tablespace.

Tempfiles (Temporary Datafiles)
Unlike normal datafiles, tempfiles are not fully allocated. When you create a tempfiles,
Oracle only writes to the header and last block of the file. This is why it is much
quicker to create a tempfiles than to create a normal datafile.

Tempfiles are not recorded in the database’s control file. This implies that just
recreate them whenever you restore the database, or after deleting them by accident.
You can have different tempfile configurations between primary and standby databases
in dataguard environment, or configure tempfiles to be local instead of shared in a
RAC environment.

One cannot remove datafiles from a tablespace until you drop the entire tablespace.
However, one can remove a tempfile from a database. Look at this example:
SQL> alter database tempfile ‘tempfile_name’ drop including datafiles;
//If the file was created as tempfile

SQL> alter database datafile ‘tempfile_name’ drop;
//If the file was created as datafile

Dropping temp tablespace
SQL> drop tablespace temp_tbs;
SQL> drop tablespace temp_tbs including contents and datafiles;

If you remove all tempfiles from a temporary tablespace, you may encounter error:
ORA-25153: Temporary Tablespace is Empty.

Use the following statement to add a tempfile to a temporary tablespace:
SQL> ALTER TABLESPACE temp ADD TEMPFILE ‘/path/temp01.dbf’ SIZE 512m
AUTOEXTEND ON NEXT 250m MAXSIZE UNLIMITED;

Except for adding a tempfile, you cannot use the ALTER TABLESPACE statement for a
locally managed temporary tablespace (operations like rename, set to read only,
recover, etc. will fail).

Locally managed temporary tablespaces have temporary datafiles (tempfiles), which are
similar to ordinary datafiles except:
You cannot create a tempfile with the ALTER DATABASE statement.
You cannot rename a tempfile or set it to read-only.
Tempfiles are always set to NOLOGGING mode.
When you create or resize tempfiles, they are not always guaranteed allocation of
disk space for the file size specified. On certain file systems (like UNIX) disk
blocks are allocated not at file creation or resizing, but before the blocks are
accessed.
Tempfile information is shown in the dictionary view DBA_TEMP_FILES and the dynamic
performance view V$TEMPFILE.
Note: This arrangement enables fast tempfile creation and resizing, however, the disk
could run out of space later when the tempfiles are accessed.

Default Temporary Tablespaces
From Oracle 9i, we can define a default temporary tablespace at database creation time, or by issuing an “ALTER DATABASE” statement:

SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp;

By default, the default temporary tablespace is SYSTEM. Each database can be
assigned one and only one default temporary tablespace. Using this feature,
a temporary tablespace is automatically assigned to users.

The following restrictions apply to default temporary tablespaces:
-DEFAULT TEMPORARY TABLESPACE must be of type TEMPORARY.
-DEFAULT TEMPORARY TABLESPACE cannot be taken off-line.
-DEFAULT TEMPORARY TABLESPACE cannot be dropped until you create another one.

To see the default temporary tablespace for a database, execute the following query:
SQL> select PROPERTY_NAME,PROPERTY_VALUE from database_properties where property_name
like ‘%TEMP%’;

The DBA should assign a temporary tablespace to each user in the database to prevent
them from allocating sort space in the SYSTEM tablespace. This can be done with one
of the following commands:
SQL> CREATE USER scott TEMPORARY TABLESPACE temp;
SQL> ALTER USER scott TEMPORARY TABLESPACE temp;

To change a user account to use a non-default temp tablespace
SQL> ALTER USER user1 SET TEMPORARY TABLESPACE temp_tbs;

Assigning temporary tablespace group as default temporary tablespace:

SQL> ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp_grp;
Assigning temporary tablespace group to a user (same as assigning temporary tablespace
to a user):
SQL> ALTER USER scott TEMPORARY TABLESPACE temp_grp;

All new users that are not explicitly assigned a TEMPORARY TABLESPACE will get the
default temporary tablespace as its TEMPORARY TABLESPACE. Also, when you assign a
TEMPORARY tablespace to a user, Oracle will not change this value next time you change
the default temporary tablespace for the database.

Monitoring Temporary Tablespaces
Unlike datafiles, tempfiles are not listed in V$DATAFILE and DBA_DATA_FILES. Use
V$TEMPFILE and DBA_TEMP_FILES instead.

SQL> SELECT tablespace_name, file_name, bytes FROM dba_temp_files WHERE tablespace_name = ‘TEMP’;
TABLESPACE_NAME FILE_NAME BYTES
—————– ——————————– ————–
TEMP /../temp01.dbf 11,175,650,000

SQL> select file#, name, round(bytes/(1024*1024),2) “SIZE IN MB’s” from v$tempfile;

One can monitor temporary segments from V$SORT_SEGMENT and V$SORT_USAGE.

DBA_FREE_SPACE does not record free space for temporary tablespaces.
Use DBA_TEMP_FREE_SPACE or V$TEMP_SPACE_HEADER instead.

SQL> select TABLESPACE_NAME, BYTES_USED, BYTES_FREE from V$TEMP_SPACE_HEADER;
TABLESPACE_NAME BYTES_USED BYTES_FREE
—————————— ———- ———-
TEMPTBS 4214226944 80740352

From 11g, we can check free temp space in new view DBA_TEMP_FREE_SPACE.
SQL> select * from DBA_TEMP_FREE_SPACE;

Resizing tempfile
SQL> alter database tempfile temp-name resize integer K|M|G|T|P|E;
SQL> alter database tempfile ‘/path/temp01.dbf’ resize 1000M;

Resizing temporary tablespace
SQL> alter tablespace temptbs resize 1000M;

Renaming (temporary) tablespace, this is from Oracle 10g
SQL> alter tablespace temp rename to temp2;


reclaim used space
Several methods existed to reclaim the space used for a larger than normal temporary
tablespace.
(1) Restarting the database, if possible.
(2) The method that exists for all releases of Oracle is, simply drop and recreate the
temporary tablespace back to its original (or another reasonable)size.
(3) If you are using Oracle9i or higher, drop the large tempfile (which will drop the
 tempfile from the data dictionary and the OS file system).

Views:
DBA_TEMP_FILES
DBA_DATA_FILES
DBA_TABLESPACES
DBA_TEMP_FREE_SPACE (Oracle 11g)
V$TEMPFILE
V$TEMP_SPACE_HEADER
V$TEMPORARY_LOBS
V$TEMPSTAT
V$TEMPSEG_USAGE

USERS TABLESPACE RECOVERY USING RMAN

PRE-REQUISITE: RMAN BACKUP and database in ARCHIVELOG mode.
If there is a requirement to do a USERS RECOVERY test using RMAN backup.
Copy loop.sql from  /opt/oracle/scripts on ITLINUXDEVBLADE07 to $SCRPT on new machine.
cd $SCRPT
sql
SQL> create tablespace users datafile ‘/opt/oracle/oradata/dgtest9i/users01.dbf’ size 10m;
Tablespace created.
SQL> create table test (col_1 number(10), col_2 date) tablespace users;
Table created.
SQL> @loop
PL/SQL procedure successfully completed.
SQL> select count(*) from test;
  COUNT(*)
———-
     50000
Simulate users by removing datafile belonging to USERS tablespace
cd /opt/oracle/oradata/dgtest9i
[oracle@itlinuxdevblade07 dgtest9i]$ ls -lrt users*
-rw-r—–    1 oracle   dba      10493952 May  7 10:09 users01.dbf
[oracle@itlinuxdevblade07 dgtest9i]$ rm users01.dbf
[oracle@itlinuxdevblade07 dgtest9i]$cd $SCRPT
SQL> @loop
declare
*
ERROR at line 1:
ORA-01116: error in opening database file 4
ORA-01110: data file 4: ‘/opt/oracle/oradata/dgtest9i/users01.dbf’
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
ORA-06512: at line 7
SQL> select count(*) from test;
  COUNT(*)
———-
     50682
SQL>
Now RECOVER the USERS tablespace.
SQL> shutdown abort;
ORACLE instance shut down.
SQL>
SQL> startup mount;
ORACLE instance started.
Total System Global Area  236422544 bytes
Fixed Size                   742800 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 798720 bytes
Database mounted.
SQL>
create recovertbs.rcv file
run{
restore tablespace users;
recover tablespace users;
sql’ alter database open’;
sql ‘alter tablespace users online’;
}
$> rman target / catalog rman/rman@rmanp  cmdfile=recovertbs.rcv
Recovery Manager: Release 9.2.0.4.0 – 64bit Production
Copyright (c) 1995, 2002, Oracle Corporation.  All rights reserved.
connected to target database: DGTEST9I (DBID=227642821)
connected to recovery catalog database
RMAN> run{
2> restore tablespace users;
3> recover tablespace users;
4> sql’ alter database open’;
5> sql ‘alter tablespace users online’;
6> }
7>
Starting restore at 07-MAY-06
allocated channel: ORA_SBT_TAPE_1
channel ORA_SBT_TAPE_1: sid=11 devtype=SBT_TAPE
channel ORA_SBT_TAPE_1: Data Protection for Oracle: version 5.2.4.0
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=9 devtype=DISK
channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00003 to /opt/oracle/oradata/dgtest9i/users01.dbf
channel ORA_DISK_1: restored backup piece 1
piece handle=/opt/oracle/product9204/dbs/7thif4vn_1_1 tag=TAG20060507T081903 params=NULL
channel ORA_DISK_1: restore complete
Finished restore at 07-MAY-06
Starting recover at 07-MAY-06
using channel ORA_SBT_TAPE_1
using channel ORA_DISK_1
starting media recovery
archive log filename=/opt/oracle/dgtest9i/arch/arch39.log thread=1 sequence=39
archive log filename=/opt/oracle/dgtest9i/arch/arch40.log thread=1 sequence=40
archive log filename=/opt/oracle/dgtest9i/arch/arch41.log thread=1 sequence=41
media recovery complete
Finished recover at 07-MAY-06
sql statement:  alter database open
sql statement: alter tablespace users online
Recovery Manager complete.
[oracle@itlinuxdevblade07 scripts]$sql
SQL> select count(*) from test;
  COUNT(*)
———-
     50682
SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 – 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 – Production
[oracle@itlinuxdevblade07 scripts]$ sql
SQL*Plus: Release 9.2.0.4.0 – Production on Sun May 7 10:05:02 2006
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 – 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 – Production
SQL> @loop
PL/SQL procedure successfully completed.
SQL>