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]
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
.dbffile 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:
| Clause | Meaning |
|---|---|
DATAFILE | Specifies the physical file path and name |
SIZE | Initial size of the datafile |
AUTOEXTEND ON | Allows the file to grow automatically |
NEXT | Size by which the file grows each time |
MAXSIZE | Maximum 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
| Feature | Tablespace | Datafile |
|---|---|---|
| Nature | Logical | Physical |
| Location | Oracle metadata | OS file system |
| Relationship | Contains datafiles | Belongs to one tablespace |
| Command | CREATE TABLESPACE | ALTER 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.