| Lesson 3 | Tablespaces and datafiles |
| Objective | Describe how tables, tablespaces, and datafiles fit together in an Oracle RDBMS |
In Oracle (including Oracle 23ai), application data is stored using a layered storage model. You work with logical objects such as tables and indexes, but Oracle ultimately persists that data in physical files managed by the database.
The key to understanding how Oracle stores data is to separate: logical placement (where an object belongs) from physical storage (where bytes live on disk).
In short: tables (segments) live in tablespaces, and tablespaces are stored in datafiles.
Oracle does not allocate space “row by row.” It allocates storage in progressively larger units:
Modern Oracle best practice is to use locally managed tablespaces with
automatic segment space management (ASSM). In these tablespaces, Oracle manages free space efficiently
without legacy parameters such as PCTINCREASE.
When you create a table, you can optionally specify a tablespace. If you do not, Oracle uses the user’s default tablespace.
CREATE TABLE person (
person_id NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
first_name VARCHAR2(30) NOT NULL,
last_name VARCHAR2(30) NOT NULL
)
TABLESPACE user1;
The TABLESPACE clause is a logical directive. It tells Oracle which tablespace should own the
table segment. Oracle then allocates extents from that tablespace as the segment grows.
The following images illustrate a simple (but accurate) idea: a single tablespace can span multiple datafiles, and Oracle will allocate extents across available free space in those files. The object’s logical home is the tablespace; the object’s physical blocks are distributed wherever free space exists in the tablespace’s datafiles.
In the next lesson, you will apply this model by specifying storage-related choices when creating tables and by understanding how Oracle grows segments as rows are inserted.