2081 5

BIT352 ยท 2081 ยท 5 marks

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

What is tablespace and datafile in oracle? How can we 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 a logical storage unit in an Oracle database that groups related logical structures (tables, indexes, etc.) together. It is the bridge between the physical and logical components of an Oracle database. Every Oracle database has at least one tablespace called the SYSTEM tablespace.

Tablespace and Datafile in Oracle

Tablespace

Key points:

  • It is a logical storage container
  • A database is divided into one or more tablespaces
  • Each tablespace belongs to only one database

Datafile

A datafile is a physical operating system file that actually stores the data on disk. Every tablespace is made up of one or more datafiles.

Key points:

  • It is a physical file stored on the disk (e.g., .dbf file)
  • One tablespace can have multiple datafiles
  • One datafile belongs to only one tablespace

Relationship:

Database --> Tablespace (Logical) --> Datafile (Physical)

Adding a New Tablespace

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 ONAutomatically extends when full
NEXTSize by which file extends each time
MAXSIZEMaximum size the file can grow to

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 tablespace my_tablespace, increasing its total storage capacity.


Summary

ConceptTypeDescription
TablespaceLogicalGroups database objects logically
DatafilePhysicalActual file on disk storing data
CREATE TABLESPACEDDLCreates a new tablespace with datafile
ALTER TABLESPACE ... ADD DATAFILEDDLAdds a new datafile to existing tablespace

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