Database Architecture   «Prev  Next»

Lesson 6Tablespaces
ObjectiveExplain how Oracle manages space.

What is tablespace in Oracle?

In Oracle Database Management Systems, a tablespace serves as a logical container that holds segments—objects like tables, indexes, and other data structures. Essentially, it is an abstraction layer that manages physical storage, abstracting the underlying operating system files into logical storage units. The primary objective of a tablespace is to facilitate the organized storage of data, making it easier for database administrators (DBAs) to manage database growth, performance optimization, and data availability.
Each tablespace in Oracle is comprised of one or more data files, which are essentially physical storage units residing on disk. These data files are managed by Oracle software, and the data within them is accessed and manipulated through SQL queries. The Oracle DBMS allows for the creation of multiple tablespaces to aid in categorizing data based on usage patterns, performance requirements, or other administrative policies. By isolating certain types of data in specific tablespaces, DBAs can exercise granular control over database management tasks such as backup, recovery, and migration.

Key Functions and Objectives of Tablespaces

  1. Space Management: Tablespaces help in segregating data logically. Each tablespace can have specific attributes for managing space like the extent size, the method of space allocation, etc. This segregation aids in optimal space utilization and management.
  2. Performance Optimization: By strategically placing data in different tablespaces that reside on different storage disks, DBAs can distribute I/O operations more evenly across the storage subsystem, thereby improving performance.
  3. Backup and Recovery: Tablespaces allow for targeted backup and restore operations. Instead of backing up the entire database, a DBA can choose to back up specific tablespaces that contain crucial data.
  4. Data Availability: By employing tablespaces, one can achieve higher data availability. For example, if a tablespace becomes unavailable due to some failure, only the data residing in that specific tablespace will be affected, not the entire database.
  5. Security: Tablespaces can be made read-only, which helps in safeguarding historical or archive data. Also, specific access permissions can be set at the tablespace level.
  6. Data Migration: Tablespaces facilitate smoother data migration procedures. DBAs can move tablespaces between different databases or different physical locations with ease, without affecting the database's overall availability.
  7. Logical and Physical Storage: While providing a logical layer for data organization, tablespaces also play a role in physical storage by determining how data is stored at the file level. This includes data file attributes like initial size, auto-extend properties, and maximum size.
  8. Compliance and Auditing: Using tablespaces, organizations can more readily comply with data storage and retention policies. This is crucial for adhering to various legal and business requirements.
In summary, tablespaces in Oracle serve as a critical management construct, enabling database administrators to effectively organize, store, and manage data for optimal performance, availability, and security. Their design considers both logical and physical storage requirements and thus plays a pivotal role in comprehensive database management.
While Oracle physically stores 1) table and 2) index data in datafiles, it manages the relationship between tables, indexes, and datafiles using a logical concept called the tablespace. A tablespace is a grouping of one or more datafiles. When you create a table or an index, you need to tell Oracle where to store that object. You do that by providing a tablespace name. In turn, the tablespace definition includes a list of one or more datafiles, which is where Oracle actually stores the data. Move your mouse over the following diagram to see how this works:

Tables, Tablespaces, and Datafiles

In the first example, Table A maps to Tablespace A, which maps to Datafile A.
In the first example, Table A maps to Tablespace A, which maps to Datafile A.

  1. Table A: Table A's data is stored in Tablespace A.
  2. Table B: Table B's data is stored in Tablespace A.
  3. Table C: Table C's data is stored in Tablespace B.
  4. Tablespace A: Tablespaces may contain data from several objects, in this case Tables A and B.
  5. Tablespace B: Tablespace B contains only data from Table C.
  6. Datafile A: May contain data from Table A or Table B or both.
  7. Datafile B: May contain data from Table A or Table B or both.
  8. Datafile C: May contain data from Table A or Table B or both.
  9. Datafile D: Will only contain data from Table C.

Tablespace mapped to a Datafile in Oracle

In Oracle, a tablespace is a logical storage container that is used to group related database objects, such as tables and indexes. A datafile, on the other hand, is a physical file on disk that is used to store the data for the objects in a tablespace. When a tablespace is created in Oracle, one or more datafiles must be associated with it.
The mapping between a tablespace and its datafiles is maintained in the Oracle data dictionary, which is a set of database tables and views that store information about the database's structure and schema. Specifically, the information about the mapping between a tablespace and its datafiles is stored in the following data dictionary views:
  1. DBA_DATA_FILES: This view contains information about all datafiles in the database, including the tablespace to which each datafile belongs.
  2. DBA_TABLESPACES: This view contains information about all tablespaces in the database, including the datafiles that are associated with each tablespace.
  DATAFILE '/path/to/my_tablespace.dbf' SIZE 100M;

In this example, the "DATAFILE" parameter specifies the path to the datafile that will be associated with the "my_tablespace" tablespace. Multiple datafiles can be associated with a single tablespace, and datafiles can also be added or removed from a tablespace as needed. The mapping between tablespaces and datafiles is an important part of managing the storage and performance of an Oracle database, and is a key consideration in database design and administration.

Note: While a tablespace may contain many datafiles, a datafile can only be part of one tablespace.

How tablespaces create flexibility

You can see that the tablespace stands between the object (table, index, etc) that you have created, and the physical location where that object is stored. The benefit you get from this relationship is the flexibility to add datafiles as the objects in a tablespace grow. Tablespaces allow a many-to-many relationship between database objects and datafiles. Many tables and indexes may be stored in a datafile, and many datafiles may be used for one table or index. The advantage to this twofold: you can easily add new datafiles whenever you need more space, and you can spread your datafiles over multiple disks as a way to distribute the I/O load.

Overview of Tablespaces

A tablespace is a logical storage container for segments. Segments are database objects, such as tables and indexes, that consume storage space. At the physical level, a tablespace stores data in one or more data files or temp files. A database must have the SYSTEM and SYSAUX tablespaces. The following figure shows the tablespaces in a typical database. The following sections describe the tablespace types.

Figure 3-6: Tablespaces
Figure 3-6: Tablespaces