4 Tablespace And Storage Management

Database Administration ยท Unit 4

Tablespace and Storage Management

Exam-focused notes for Tablespace and Storage Management (Database Administration, BIT352): what the TU syllabus asks and how it has actually been tested, with 6 solved past questions from this unit.

Tablespace and Storage Management in short

This chapter covers how Oracle stores data in tablespaces and datafiles, how undo works, and how space is used inside blocks. Good storage management keeps the database from running out of space.

Tablespace and Storage Management: notes

Tablespace concepts and types

A tablespace is a logical storage unit that groups related segments. It is stored physically in one or more datafiles.

Types of tablespaces:

  • SYSTEM: holds the data dictionary. It is always online.
  • SYSAUX: helper tablespace for features such as AWR.
  • Permanent: holds user tables and indexes.
  • Temporary: holds sort and join work that lasts only for a session.
  • Undo: holds old copies of changed data for rollback and read consistency.

By space management, a tablespace can be locally managed (uses a bitmap in the datafile, the default and best choice) or dictionary managed (older method). A bigfile tablespace has one very large datafile. A smallfile tablespace can have many.

SELECT tablespace_name, contents, extent_management, status
FROM   dba_tablespaces;

Datafile management and creation

A datafile is a physical file that stores the data of a tablespace. Datafiles are created when you create a tablespace or add to one.

-- make a datafile grow automatically
ALTER DATABASE DATAFILE '/u01/oradata/orcl/users01.dbf'
  AUTOEXTEND ON NEXT 10M MAXSIZE 2G;

-- resize a datafile
ALTER DATABASE DATAFILE '/u01/oradata/orcl/users01.dbf' RESIZE 500M;

-- take a datafile offline or online
ALTER DATABASE DATAFILE '/u01/oradata/orcl/users01.dbf' OFFLINE;

To move a datafile in older versions, take the tablespace offline, copy the file at the operating system level, then run ALTER TABLESPACE ... RENAME DATAFILE ... TO .... Newer versions also allow ALTER DATABASE MOVE DATAFILE.

What this unit covers

  • Tablespace concepts and types
  • Datafile management and creation
  • Adding new tablespaces and datafiles
  • UNDO tablespace and UNDO RETENTION policy
  • Viewing and altering UNDO RETENTION
  • Space management and segment creation
  • Extent and row chaining concepts
  • Row migration in storage

Space management and segment creation

2081 ยท 10 marks

What is space management? How space management is done? How can you create tables without segments?[10]

Space management refers to the process of efficiently allocating, monitoring, and reclaiming storage space within a database. It involves managing how data is stored in segments, extents, and data blocks to ensure optimal use of physical disk space and to avoid fragmentation or wastage. Space man...

Open this answer on its own page โ†’

Adding new tablespaces and datafiles

2081 ยท 5 marks

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

Show solved answer

Tablespace and Datafile in Oracle

Tablespace

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.

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
Open this answer on its own page โ†’

0 ยท 5 marks

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

Show solved answer

Tablespace and Datafile in Oracle

Tablespace

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.

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 .dbf file 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:

ClauseMeaning
DATAFILESpecifies the physical file path and name
SIZEInitial size of the datafile
AUTOEXTEND ONAllows the file to grow automatically
NEXTSize by which the file grows each time
MAXSIZEMaximum 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

FeatureTablespaceDatafile
NatureLogicalPhysical
LocationOracle metadataOS file system
RelationshipContains datafilesBelongs to one tablespace
CommandCREATE TABLESPACEALTER TABLESPACE ... ADD DATAFILE
Open this answer on its own page โ†’

UNDO tablespace and UNDO RETENTION policy

2081.1 ยท 10 marks

What is Tablespace? What is UNDO RETENTION Policy? Write different commands to manage the tablespaces in Oracle.[10]

Note: The reference notes did not contain material on this topic. The following answer is based on standard Oracle Database concepts as taught in TU BSc CSIT Database Administration curriculum. --- A Tablespace is the logical storage unit in an Oracle database that groups related logical structur...

Open this answer on its own page โ†’

0 ยท 5 marks

What is UNDO tablespace and UNDO RETENTION policy? How to view and alter UNDO RETENTION Policy in oracle. [5]

An UNDO tablespace is a special type of tablespace in Oracle Database used to store undo data (also called rollback data). When a transaction modifies data, Oracle saves the before-image of the data in the undo tablespace so that: - Transaction Rollback - Uncommitted changes can be undone if a tr...

Open this answer on its own page โ†’

Extent and row chaining concepts

2081.1 ยท 5 marks

What is Extent? Explain Row chaining and Migration in brief. [5]

An extent is a contiguous set (group) of data blocks allocated to a segment (such as a table or index) within a tablespace in Oracle database storage. When a segment needs more space, the database allocates a new extent. An extent is the next level of logical storage above a data block and below ...

Open this answer on its own page โ†’