Tablespaces
Miroslav Biňas
(c) 2016
Introduction
● database is centralized repository of
related data
www.cde.sk
Data in Database
System Data User Data Undo Data Temp Data
Database
www.cde.sk
Data in Database
● different data types in db
○ system data - data dictionary tables
maintained by db
○ feature data - based on db features
○ user data - consists of db objects
created by db users
○ undo data - consists of previous
values generates by transactions
○ temp data - used for temp storage
of data for special operations such
as sorting
www.cde.sk
Tablespaces in Database
System Data User Data Undo Data Temp Data
(SYSTEM) (USERS) (UNDOTBS1) (TEMP)
Database
www.cde.sk
Tablespaces in Database
● database consists of one or more
logical structures called tablespaces
● every tablespace has name
● logically separate/group the data
● helps with data management and
admin tasks
www.cde.sk
Datafiles and Tablespaces I.
Datafile 1 Datafile 2 Datafile N
Tablespace
www.cde.sk
Datafiles and Tablespaces I.
● each tablespace consists of one or
more files called datafiles
○ usually with .dbf extension
○ filename does not need to match to
the tablespace name in any way,
but it's easier
● datafiles can grow automatically
○ the max size can be limited
○ more datafiles can be added later
www.cde.sk
Datafiles and Tablespaces I.
● database stores data logically into
tablespaces and physically into
datafiles
www.cde.sk
Datafiles and Tablespaces II.
Table 1
Datafile 1 Datafile 2 Datafile 3
Table 2
Tablespace
www.cde.sk
Datafiles and Tablespaces II.
● datafile is organized into data blocks
○ each block contains data from just
one table
www.cde.sk
Introduction to
Tablespace Management
● can be done in two ways
○ with CLI tools (e.g. sqlplus, SQL
Developer)
○ with GUI tools (e.g. SQL Developer)
● admin tasks
○ create/remove tablespace
○ make tablespace online/offline
○ resize tablespace datafile
○ add/rename/move datafiles
www.cde.sk
Obtaining Tablespace Info
● tablespace info views
○ v$tablespace
○ dba_tablespaces
● data file information views
○ v$datafile
○ dba_data_files
● temp file information views
○ v$tempfile
○ dba_temp_files
www.cde.sk
Create New Tablespace
● syntax:
CREATE [TYPE] TABLESPACE name
DATAFILE '/path/'
SIZE size;
● by default, user tablespace is created
● other types: UNDO, TEMPORARY
● example
CREATE TABLESPACE tbs
DATAFILE '/path/tbs.dbf'
SIZE 10M;
www.cde.sk
Resize Tablespace
ALTER DATABASE
DATAFILE '/path/tbs.dbf'
RESIZE 15M;
www.cde.sk
Remove Tablespace
● drop tablespace only (logicaly)
DROP TABLESPACE tbs;
● drop tablespace with it's datafile
(physicaly)
DROP TABLESPACE tbs
INCLUDING CONTENTS
AND DATAFILES;
www.cde.sk
Questions?
www.cde.sk
Tablespace SYSTEM
● auto created in every Oracle db
● always online when db is open
● contains data dictionary tables for
entire database
○ metadata
www.cde.sk
Temporary Tablespace
● contains temp data for operations such
as JOIN, UNION, ORDER BY, …
○ data are created and removed
automatically based on operation
www.cde.sk