Course contentsShow
← Databases & SQL
Lesson 573 of 1,9536. Query Performance and IndexingFree lesson

Tablespace Architecture

Organize data across multiple physical files to parallelize storage subsystem traffic.

In this lesson, you will learn how to leverage tablespace architecture to distribute your database files across multiple physical storage devices to eliminate I/O bottlenecks.

Moving Beyond a Single Disk

When we store our database on a single physical drive, every read and write operation competes for the same disk head or controller. Even with modern SSDs, pushing massive amounts of traffic through one path creates a performance "ceiling." Tablespaces allow you to break through this limit by logically grouping database objects and mapping them to specific physical locations on different hardware.

Parallelizing the Load

Think of a tablespace as a container that maps your logical data—such as specific tables or indexes—to physical files. By placing high-traffic tables on one tablespace (mapped to Disk A) and their associated indexes on another tablespace (mapped to Disk B), the database engine can perform parallel I/O operations.

For example, when the engine executes a query, it can simultaneously read the data rows from the table file and the index entries from the index file because they are traversing separate physical channels:

-- Example: Creating tablespaces on different physical paths
CREATE TABLESPACE ts_data LOCATION '/mnt/fast_ssd_array/data';
CREATE TABLESPACE ts_index LOCATION '/mnt/dedicated_index_nvme/indexes';

-- Directing a table to a specific tablespace
CREATE TABLE users (
    user_id INT PRIMARY KEY,
    username TEXT
) TABLESPACE ts_data;

-- Directing the index to a separate physical disk
CREATE INDEX idx_user_name ON users(username) TABLESPACE ts_index;

By decoupling the data storage from the index storage, you ensure that the "random access" patterns required for index lookups do not stall the sequential reads of your primary table data. This separation is particularly effective in high-concurrency systems where the disk subsystem is the primary constraint on throughput.

Instead of waiting for one disk to finish processing a write request, the database engine can distribute the load across the entire storage subsystem, effectively multiplying your available I/O bandwidth.

Key Takeaway: Tablespace architecture allows you to distribute data across multiple physical devices, enabling parallel I/O streams that prevent storage hardware from becoming a performance bottleneck.