0 6

BIT352 ยท 0 ยท 5 marks

What is tablespace and datafile in oracle? How we can add new tablespace and datafiles in oracle database?

What is tablespace and datafile in oracle? How we can add new tablespace and datafiles in oracle database? [5]

Database AdministrationChapter 4: Tablespace and Storage ManagementAdding new tablespaces and datafiles

Quick answer

A tablespace is the logical storage unit in an Oracle database. It is a logical grouping of one or more datafiles that stores database objects such as tables, indexes, and other schema objects. Every Oracle database has at least one tablespace called the SYSTEM tablespace.

Tablespace and Datafile in Oracle

Tablespace

Key points:

  • Tablespace is a logical concept
  • It acts as a bridge between the physical storage (datafiles) and the logical database objects
  • Common tablespaces: SYSTEM, SYSAUX, USERS, TEMP, UNDOTBS

Datafile

A datafile is the physical file stored on disk that corresponds to a tablespace. Each tablespace consists of one or more datafiles, but a datafile can belong to only one tablespace.

Key points:

  • Datafile is a physical concept (actual .dbf file on OS)
  • It stores the actual data of database objects
  • Its size can be fixed or set to auto-extend

Relationship

Database
  โ””โ”€โ”€ Tablespace (Logical)
        โ””โ”€โ”€ Datafile(s) (Physical - .dbf files on disk)

Adding a New Tablespace in Oracle

Use the CREATE TABLESPACE statement:

CREATE TABLESPACE my_tablespace
DATAFILE '/u01/oradata/mydb/my_tablespace01.dbf'
SIZE 100M
AUTOEXTEND ON
NEXT 10M
MAXSIZE 500M;

Explanation of clauses:

ClauseMeaning
DATAFILESpecifies the physical file path and name
SIZEInitial size of the datafile
AUTOEXTEND ONAllows the file to grow automatically
NEXTSize by which the file grows each time
MAXSIZEMaximum size the file can reach

Adding a New Datafile to an Existing Tablespace

Use the ALTER TABLESPACE statement:

ALTER TABLESPACE my_tablespace
ADD DATAFILE '/u01/oradata/mydb/my_tablespace02.dbf'
SIZE 50M
AUTOEXTEND ON
NEXT 5M
MAXSIZE 200M;

This adds a second datafile to the existing my_tablespace, increasing its total storage capacity.


Summary

FeatureTablespaceDatafile
NatureLogicalPhysical
LocationOracle metadataOS file system
RelationshipContains datafilesBelongs to one tablespace
CommandCREATE TABLESPACEALTER TABLESPACE ... ADD DATAFILE

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.