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]
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.,
.dbffile) - 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:
| Clause | Meaning |
|---|---|
DATAFILE | Specifies the physical file path and name |
SIZE | Initial size of the datafile |
AUTOEXTEND ON | Automatically extends when full |
NEXT | Size by which file extends each time |
MAXSIZE | Maximum 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
| Concept | Type | Description |
|---|---|---|
| Tablespace | Logical | Groups database objects logically |
| Datafile | Physical | Actual file on disk storing data |
CREATE TABLESPACE | DDL | Creates a new tablespace with datafile |
ALTER TABLESPACE ... ADD DATAFILE | DDL | Adds 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.