Primary Storage Concepts
Introduction
Primary storage concepts explain how a database system holds, moves, reads, writes, and protects data while it is running. SQL learners often think only about tables and rows, but a database engine works with memory, pages, blocks, data files, transaction logs, dirty pages, checkpoints, indexes, temporary files, and persistent storage devices. These storage concepts explain why some queries are fast, why other queries are slow, why indexes matter, why committed data survives a crash, and why database memory configuration is so important.
At a high level, database work moves between CPU, memory, and persistent storage. The CPU executes instructions. RAM provides fast working memory. SSD or disk provides durable storage for database files. The database engine continuously moves pages from persistent storage into memory, processes them, changes them when needed, records recovery information, and writes durable changes back to storage.
CPU
|
Memory
|
Persistent Storage
For database systems, the most important practical distinction is that memory is fast but temporary, while disk or SSD storage is slower but persistent. A database wants the speed of memory and the safety of persistent storage. It achieves this by using buffer pools, transaction logs, checkpoints, background writers, and recovery mechanisms.
Memory
= Fast, temporary working storage
Disk / SSD
= Persistent storage for database files
This tutorial explains the primary storage concepts every SQL learner should understand. It covers RAM, CPU cache, persistent storage, data files, pages and blocks, buffer pools, cache hits and misses, dirty pages, clean pages, transaction logs, write-ahead logging, sequential and random I/O, HDD and SSD behavior, IOPS, throughput, latency, OLTP and analytical workloads, row storage, column storage, index storage, clustered storage, heap storage, temporary storage, memory limits, operating system cache, swap, extents, tablespaces, checkpoints, backup, replication, cloud storage, capacity planning, and common misconceptions.
What Is Primary Storage?
In traditional computer architecture, primary storage usually means storage directly accessible by the CPU, especially RAM and CPU cache. It is the fast working area used while programs are executing. In database discussions, however, people often use storage language more broadly. They may talk about memory buffers, data files, pages, blocks, transaction logs, and temporary storage together as part of database storage architecture.
Because of this, context matters. If a computer architecture discussion says primary storage, it may mean RAM and cache. If a database performance discussion says storage concepts, it may include both memory and persistent database files. A SQL learner should understand both meanings so the terms do not become confusing.
The database engine depends on primary working memory for speed, but it cannot rely only on memory for committed data. RAM is volatile, meaning contents are lost when power is removed. Persistent storage is required so database files and transaction logs survive restarts and failures.
Main Storage Layers
A simplified storage hierarchy starts with CPU registers, then CPU cache, RAM, SSD or disk, and backup or archive storage. As we move downward, speed generally decreases, capacity generally increases, and persistence generally increases. Database systems use this hierarchy constantly.
CPU Registers
|
CPU Cache
|
RAM
|
SSD / Disk
|
Backup / Archive Storage
CPU registers are extremely small and fast storage locations inside the processor. CPU cache is larger than registers but still very fast. RAM is the main memory used by the database process. SSD and HDD storage retain database files. Backup and archive storage hold recovery copies or long-term data.
Database developers usually do not manage CPU registers or CPU cache directly, but database performance can still benefit from good cache locality, efficient algorithms, and memory-friendly access patterns. Practical database tuning usually focuses more on RAM, buffer pools, indexes, disk I/O, transaction logs, and storage layout.
CPU Registers and CPU Cache
Registers are the smallest and fastest storage locations inside the CPU. They are used during actual instruction execution. When a database engine evaluates expressions, compares values, executes joins, sorts rows, hashes keys, or processes query operators, CPU instructions operate through registers at the lowest level.
SQL Query
|
Database Engine
|
CPU Instructions
|
Registers
Modern processors also use cache levels such as L1 cache, L2 cache, and L3 cache. These caches hold recently used instructions and data. They are much faster than RAM. The database engine does not ask the SQL developer to manage CPU cache manually, but engine performance can be affected by CPU cache behavior during scans, sorting, hashing, joins, compression, and expression evaluation.
CPU
|
Cache
|
RAM
For beginner SQL work, you do not need to tune CPU registers or cache directly. The important takeaway is that the database engine is a program running on real hardware. Even high-level SQL eventually becomes CPU instructions operating on memory and storage.
RAM in Database Systems
RAM is the most important primary working memory for a database system. The database engine uses RAM for buffer pools, query execution, sorting, hash tables, connections, sessions, transactions, metadata, plan cache, locks, internal structures, and temporary working data. More RAM can allow more database pages to remain cached and can reduce physical storage reads.
Database Instance
|-- Buffer Cache
|-- Query Memory
|-- Session Memory
|-- Transaction State
|-- Plan Cache
RAM is fast, but RAM is also volatile. If the server powers off, normal RAM contents are lost. This is why committed database changes must be protected by transaction logging and persistent storage. A database cannot simply change a page in RAM and consider the change durable unless recovery information has been persisted according to the database's rules.
Power Off
|
RAM Contents Lost
Database memory must also be configured carefully. Allocating too little memory can cause repeated storage reads and temporary spills. Allocating too much memory can pressure the operating system and cause swapping or instability. Good database memory planning balances database needs, operating system needs, and other processes running on the server.
Persistent Storage
Persistent storage retains data after shutdown. Common examples include SSDs, traditional hard drives, cloud block storage, persistent volumes, and storage arrays. Database files are normally stored on persistent storage because table data, index data, transaction logs, metadata, and configuration must survive restarts.
Persistent storage examples:
SSD
HDD
Cloud Block Storage
Persistent Volumes
Databases need both RAM and persistent storage. RAM provides speed. Persistent storage provides durability. The database engine combines them by keeping active pages in memory while storing durable copies and logs on persistent storage.
Persistent Storage
|
Buffer Cache in RAM
|
Query Execution
This combination provides speed, persistence, and recovery capability. Queries can read cached pages quickly. Writes can update pages in memory and record transaction logs. Background processes can later write dirty pages to data files. If a crash happens, recovery can use logs to restore a consistent database state.
Database Files
Relational databases store persistent information in files or equivalent storage structures. The exact terminology differs by product, but common categories include data files, transaction logs, control or metadata files, and temporary files. These files are managed by the database engine, not edited manually by application code.
Database storage may include:
Data Files
Transaction Logs
Control / Metadata Files
Temporary Files
Data files contain persistent database information such as table data, index data, and internal metadata. Transaction logs record changes for recovery and durability. Temporary files support operations such as sorting, hashing, and temporary tables. Control or metadata files help the engine track database structure and state.
Database
|
Data Files
|
Pages / Blocks
|
Rows
Different RDBMS products organize these files differently. Oracle uses data files, control files, redo logs, tablespaces, segments, extents, and blocks. SQL Server uses data files, log files, extents, and pages. PostgreSQL stores relation files and WAL. MySQL InnoDB uses tablespaces, pages, redo logs, and undo structures. The concepts are similar even when names differ.
Pages and Blocks
Databases usually do not read one row directly from disk in isolation. Instead, they work with fixed-size storage units called pages or blocks. A page may contain multiple rows, index entries, or internal metadata. When a query needs one row, the engine often loads the page containing that row into memory.
Database File
|-- Page 1
|-- Page 2
|-- Page 3
|-- Page 4
Suppose page 25 contains customer rows 101, 102, 103, and 104. If a query needs customer 103, the engine may load page 25 into memory and then retrieve the row from that page.
Page 25
|-- Customer 101
|-- Customer 102
|-- Customer 103
|-- Customer 104
Using pages reduces storage overhead and supports caching. Reading an entire page can be more efficient than repeatedly reading tiny pieces of storage. Once the page is in memory, other rows on that page may also be available for nearby queries.
Page or block sizes differ by database product and configuration. Common sizes may be 4 KB, 8 KB, or 16 KB. SQL Server commonly uses 8 KB pages. PostgreSQL commonly uses 8 KB pages by default. MySQL InnoDB commonly uses 16 KB pages by default. Oracle block sizes can vary. Always check the specific RDBMS when exact values matter.
Buffer Pool
A buffer pool, also called a buffer cache in many systems, is memory used to cache database pages. If a page is already in the buffer pool, the database can avoid a physical storage read. This is one of the most important performance concepts in database systems.
Disk
|
Database Page
|
Buffer Pool
|
Query
A buffer cache hit happens when the requested page is already in memory. The query can use the page without waiting for storage I/O.
Query
|
Buffer Cache
|
Page Found
|
Use It
A buffer cache miss happens when the requested page is not in memory. The engine must read the page from storage, place it into the buffer pool, and then use it.
Query
|
Buffer Cache
|
Page Not Found
|
Read from Storage
|
Place in Buffer
|
Use Page
Cache hits matter because memory access is much faster than storage access. Frequently queried product data, lookup tables, index pages, and active rows may remain in memory. This can make repeated queries much faster after the database has warmed up.
Dirty Pages and Clean Pages
A dirty page is a page that has been modified in memory but whose latest version has not yet been fully written to its normal persistent data-file location. For example, an update may load a page into RAM, change a row value, and leave the modified page in memory until a background write or checkpoint writes it to storage.
Disk Page
|
Load into RAM
|
UPDATE
|
Page Modified in RAM
|
Dirty Page
A clean page matches the version already persisted in storage. Because no unsaved modification exists, a clean page can usually be replaced from the cache more easily when memory is needed. If the engine evicts a clean page, it can simply discard the memory copy because the persistent version is already current.
Memory Page
=
Disk Page
Dirty pages require more care. If a dirty page must be removed from memory, the database must write it to persistent storage or otherwise preserve correctness through logging and recovery rules. Databases use sophisticated page replacement and background writing policies. They do not simply discard modified pages.
Page Eviction
Buffer memory is limited. When the buffer pool is full and a query needs another page, the database may remove a less useful page from memory. This is called page eviction. The engine chooses pages using replacement policies designed to keep useful pages cached and make room for new work.
Buffer Pool Full
|
Choose Page to Evict
|
Reuse Memory
If the selected page is clean, eviction is relatively simple because the page already matches persistent storage. If the selected page is dirty, the engine must ensure the changed page is written safely or that recovery information can reconstruct it as needed.
Dirty Page
|
Write to Persistent Storage
|
Evict Page
Page eviction is invisible to most SQL users, but it affects performance. If the active working set is larger than memory, pages may be repeatedly read from storage and evicted. This can create heavy I/O. Good indexing, query design, and memory sizing help reduce unnecessary page churn.
Transaction Logs
Most relational databases use transaction logs or equivalent recovery logs. These logs record database changes. They are fundamental for recovery, durability, replication, rollback, auditing in some systems, and point-in-time recovery. A transaction log is not the same as a data file. The data file stores database pages. The log records changes in a sequence that can be used for recovery.
UPDATE account balance
|
Generate Log Record
|
Persist Required Log
Transaction logs are especially important because dirty data pages may remain in memory for some time. If the server crashes before those dirty pages are written to data files, the log can help recover committed changes. If a transaction did not commit, the log and recovery information can help undo or ignore incomplete work.
| Data File | Transaction Log |
|---|---|
| Stores database pages | Records changes |
| Contains tables and indexes | Supports recovery |
| Represents current persistent database state | Represents sequence of changes |
| Often updated asynchronously | Critical records may be flushed at commit |
Write-Ahead Logging
Many RDBMSs use write-ahead logging or a similar strategy. The core rule is that required log information is persisted before the corresponding data page is written in a way that would require that log record during recovery. This is important because the database may commit a transaction without immediately writing every changed data page to its final data-file location.
Log Information
|
Persist First
|
Corresponding Data Page
Can Be Written Later
Suppose an update changes an account balance. The system may record the change in the transaction log, commit the transaction, keep the modified page in memory, and write the page to the data file later. Because the log contains recovery information, the database can reconstruct the committed change after a crash.
1. Record change in transaction log
2. Commit transaction
3. Keep modified page in memory
4. Write page to data file later
This design improves performance because every update does not need to synchronously write the full data page immediately. The log is often written sequentially, while data pages may be written later in a more efficient pattern. The database gets both performance and durability through careful coordination.
Sequential and Random I/O
Storage access can generally be described as sequential I/O or random I/O. Sequential I/O reads nearby blocks in order. Random I/O jumps between different storage locations. Both patterns appear in database workloads.
Sequential I/O:
Page 1 -> Page 2 -> Page 3 -> Page 4
Large table scans often involve sequential-style access. This can be efficient when a query needs a large portion of a table. Full scans are not inherently bad. They become problematic when the query needs only a few rows but still reads most of the table.
Random I/O:
Page 20 -> Page 950 -> Page 103 -> Page 5000
Index-based lookups may involve more random access patterns. Traditional hard drives handle random I/O poorly because the mechanical head must move. SSDs handle random I/O much better, but the access pattern still matters. Reading 10 pages is generally better than reading 1,000,000 pages when the query needs only a few records.
HDD and SSD Basics
Traditional hard disk drives store data on spinning magnetic platters. Their characteristics include large capacity, lower cost, mechanical movement, higher latency, and slower random access. Historically, database tuning paid heavy attention to minimizing random disk seeks because seek time could dominate performance.
Solid state drives contain no mechanical moving parts. They generally provide lower latency, faster random reads, faster random writes, and higher IOPS than hard disks. Modern database servers commonly rely heavily on SSD-based storage, and cloud databases often use SSD-backed block storage or distributed storage layers.
SSDs improve storage performance, but they do not remove the need for good database design. Bad queries, missing indexes, poor data modeling, lock contention, and insufficient memory can still cause serious performance problems. Better hardware helps, but it does not replace correct modeling and query tuning.
IOPS, Throughput, and Latency
IOPS means input/output operations per second. It measures how many storage operations a device or storage system can perform. Database workloads involving many small reads and writes often depend heavily on IOPS. OLTP systems with frequent primary-key lookups, inserts, updates, and short transactions often care about IOPS and latency.
Throughput measures how much data can be transferred over time, usually in MB/s or GB/s. Large sequential scans, backups, restores, data warehouse loads, and analytical queries may depend strongly on throughput.
Latency measures how long one I/O operation takes. Low latency is particularly important for transactional workloads because a single user request may wait for a small number of storage operations or a transaction log flush.
| Metric | Meaning |
|---|---|
| IOPS | Number of I/O operations |
| Throughput | Amount of data transferred |
| Latency | Time taken per operation |
Different workloads stress these metrics differently. A reporting query scanning a large table may need high throughput. A payment transaction committing a small update may need low latency log writes. A busy application with many users may require high IOPS.
OLTP and Analytical Storage Patterns
OLTP systems usually perform many small operations: inserts, updates, deletes, primary-key lookups, and short transactions. These systems often require low latency, good random I/O, high IOPS, reliable log writes, and enough memory to cache active data and indexes.
OLTP examples:
INSERT
UPDATE
DELETE
Primary-Key Lookup
Short Transactions
Analytical workloads often scan large amounts of data. A query such as SELECT region, SUM(amount) FROM sales GROUP BY region may read millions or billions of rows. These workloads may benefit from high throughput, sequential access, columnar storage, large memory, compression, partitioning, and parallel execution.
SELECT region, SUM(amount)
FROM sales
GROUP BY region;
A storage design that is excellent for OLTP may not be ideal for analytics, and an analytical warehouse design may not be ideal for small transactional updates. Understanding workload type helps explain storage choices.
Row-Oriented and Column-Oriented Storage
Traditional relational databases frequently use row-oriented storage. Data for one row is stored close together. This is useful for transactional workloads that often access complete records, such as retrieving one customer profile or updating one order.
Row 1: 101 | John | Chicago | 50000
Row 2: 102 | Alice | Dallas | 60000
Analytical databases may use column-oriented storage. Values from the same column are stored together. This can improve analytical queries that scan only a few columns across many rows.
customer_id:
101
102
103
salary:
50000
60000
70000
| Row Store | Column Store |
|---|---|
| Stores complete rows together | Stores column values together |
| Strong for transactional workloads | Strong for analytics |
| Efficient single-row operations | Efficient aggregations and scans |
| Common in OLTP | Common in OLAP |
Some modern database systems support both approaches or hybrid designs. The important storage concept is that physical layout affects query performance. SQL may be declarative, but storage organization still matters.
Index Storage
Indexes also consume storage. When you create an index, the database stores an additional access structure alongside table data. That structure helps locate rows faster for certain queries, but it increases storage usage and write maintenance.
CREATE INDEX idx_customer_email
ON customers(email);
Table Data
+
Index Structure
Indexes improve some reads by reducing the number of pages the database must access. A query that searches by customer email may use the index to find the matching row quickly. Without the index, the database may scan many table pages.
The tradeoff is that inserts, updates, and deletes may need to update indexes too. If a table has many indexes, write operations can become more expensive. Good index design considers storage usage, read benefit, write cost, and maintenance overhead.
Clustered Storage and Heap Storage
Some database systems organize table data around a clustering key or clustered index. Conceptually, the clustered key controls the primary row organization. The exact meaning differs by database product. SQL Server and MySQL InnoDB both use clustered concepts, but their implementations are not identical.
Clustered Key
|
Controls Primary Row Organization
A heap table is a table without a clustered physical organization, depending on the RDBMS. Rows are stored where space is available rather than physically ordered according to a user-visible guaranteed query order.
Heap Table
|-- Page 1
|-- Page 2
|-- Page 3
|-- Page 4
Physical storage order should not be confused with query result order. SQL does not guarantee row order unless ORDER BY is used. Even if storage is clustered, the correct way to request ordered output is still an explicit order clause.
Temporary Storage and Spills
Databases also need temporary storage for intermediate work. Sorting, hash joins, aggregation, temporary tables, index creation, and large query operations may require working space. If memory is insufficient, the database may spill intermediate data to temporary disk storage.
Query Operation
|
Memory Limit Reached
|
Temporary Disk Storage
A sort spill can happen when a query such as SELECT * FROM transactions ORDER BY amount requires more memory than available. The database may sort some data in memory, write temporary data to disk, and continue the sort using temporary storage.
Sort in Memory
|
Memory Insufficient
|
Write Temporary Data to Disk
|
Complete Sort
Hash joins and hash aggregations can spill too. If a hash table is too large for memory, the engine may use temporary disk space. Spills increase I/O and can reduce performance significantly. Better indexes, better filtering, more memory, or rewritten queries may reduce spills.
Memory Limits, Operating System Cache, and Swap
Allocating more memory can improve database performance, but memory is not always better without limits. If the database uses too much RAM, the operating system may come under pressure. This can cause swapping, out-of-memory conditions, or general instability.
Database Uses Too Much RAM
|
Operating System Under Pressure
|
Swapping / OOM / Instability
The operating system may also cache file data. Depending on the database architecture, the database buffer cache and operating system file cache may both participate. Different RDBMSs interact with the operating system cache differently. Some try to avoid double caching, while others rely on OS caching for certain operations.
Virtual memory gives applications a logical memory address space. Swap uses persistent storage as overflow for memory. While swap can help operating system stability, heavy swapping is usually undesirable for database workloads because storage is much slower than RAM.
RAM Full
|
Move Memory Pages to Disk
Storage Allocation, Extents, and Tablespaces
Databases allocate storage to tables, indexes, logs, temporary work, and metadata. This allocation is managed in database-specific units and structures. Some systems allocate pages in larger groups often called extents. Grouping pages reduces allocation overhead.
Database Storage
|-- Table Data
|-- Indexes
|-- Logs
|-- Temporary Space
Extent
|-- Page 1
|-- Page 2
|-- Page 3
|-- Page 4
|-- Page N
Some RDBMSs use tablespaces as logical storage containers. A tablespace can help organize storage for tables, indexes, users, or applications. Oracle and PostgreSQL both use the term tablespace, but their implementations differ.
Tablespace
|
Data Files
|
Pages / Blocks
A simplified Oracle storage model is tablespace to data file to segment to extent to block. A simplified SQL Server model is database to data files to extents to pages. A simplified PostgreSQL model is database relation to relation files to pages to tuples. A simplified InnoDB model is tablespace to pages to records and index structures. These details become important in advanced performance tuning and administration.
Persistent vs Volatile Storage
Volatile storage is lost after power loss. RAM and CPU cache are volatile. Persistent storage retains data after shutdown. SSDs and HDDs are persistent. Databases combine both types because each has different strengths.
| Volatile | Persistent |
|---|---|
| RAM | SSD |
| CPU cache | HDD |
| Lost after power loss | Retains data |
| Very fast | Slower |
| Used for runtime work | Used for durable storage |
Durability means committed transactions survive failures. This requires coordination between memory, transaction logs, and persistent storage. A database cannot simply say a change exists in RAM and therefore it is durable. It must ensure the appropriate persistent recovery information exists.
Commit, Durability, and Checkpoints
Consider an update followed by commit:
UPDATE accounts
SET balance = balance - 100
WHERE account_id = 1;
COMMIT;
A simplified durability flow may modify the page in RAM, create a log record, flush required log information, return commit, keep the data page dirty for a while, and write the page to storage later. Exact behavior depends on database configuration and durability settings.
Modify Page in RAM
|
Create Log Record
|
Flush Required Log
|
COMMIT Returns
|
Data Page May Be Written Later
A checkpoint helps coordinate memory and persistent storage. It writes required dirty pages and advances the recovery position. This helps reduce crash recovery work because the database has a known point where many changes are already reflected in persistent data files.
Dirty Pages in Memory
|
Checkpoint Activity
|
Pages Written to Storage
|
Recovery Position Advanced
If every update had to immediately write the full data page synchronously, performance could suffer badly. Databases use buffering and logging to decouple transaction commits from immediate data-page writes while preserving recoverability.
Storage and Query Performance
Storage access patterns directly affect query performance. Consider a query that looks up one customer by primary key. With a good index, the database can use index pages, locate the row, and read only a few pages. Without an index, it may read many table pages and check rows until it finds the match.
SELECT *
FROM customers
WHERE customer_id = 101;
With index:
Index Pages -> Locate Row -> Read Few Pages
Without index:
Read Many Table Pages -> Check Rows
A full table scan may require reading page 1, page 2, page 3, and so on through page 100,000. This can be efficient if most rows are needed. It becomes problematic when the query needs very few rows but still reads most of the table because no useful index or filter exists.
Even though SQL is declarative, storage concepts explain why two logically equivalent queries can perform differently. Internally, the database must decide which pages to read, which index to use, how much memory to allocate, what join algorithm to apply, and whether temporary storage is needed.
Compression and Partitioning
Some databases support data compression. Compression can reduce storage usage and I/O because fewer bytes may need to be read from disk. However, compression can require more CPU for compression and decompression. The tradeoff is storage and I/O savings versus CPU cost.
Less Storage
|
Less I/O
|
Possible More CPU
Large tables can also be divided into partitions. For example, an orders table may be partitioned by year. This can help with maintenance, archiving, data management, and certain query patterns.
orders
|-- 2024 partition
|-- 2025 partition
|-- 2026 partition
Partitioning does not automatically make every query faster. It helps when queries and maintenance operations can take advantage of partition boundaries. Poorly chosen partitions can add complexity without benefit. Like indexes and compression, partitioning is a physical design decision that should match workload needs.
Backup and Replication
Primary database storage should not be confused with backup storage. Primary database storage is the active storage used by the running database. Backup storage holds recovery copies. A backup is not normally used for live transactional queries.
Primary Database Storage
|
Active Database
Backup Storage
|
Recovery Copy
Replication creates additional active or standby copies of data. A primary database sends changes to a replica. Replication can improve availability or read scaling, but it is not the same as a backup. If bad data is written and replicated, the replica may receive the bad data too. Backups are still needed for recovery from mistakes, corruption, or historical restore needs.
Primary
|
Replication
|
Replica
Storage planning must account for primary data, indexes, logs, backups, replicas, temporary space, and growth. Looking only at current table size is not enough.
Storage and Cloud Databases
Cloud databases may use cloud block storage, distributed storage, network-attached storage, local SSD, persistent volumes, or object storage for backups. The application may never see the physical disk, but storage concepts still matter because latency, throughput, IOPS, durability, replication, and capacity limits still affect database behavior.
Database Engine
|
Cloud Storage Layer
|
Distributed Physical Hardware
Local storage is attached directly to the server. Network storage is accessed through a network or storage service. Each architecture has different latency, availability, scaling, and operational characteristics.
Local Storage:
Database Server -> Local SSD
Network Storage:
Database Server -> Network -> Storage System
Managed cloud databases hide much operational detail, but they do not remove the need to understand workload and storage behavior. Provisioned IOPS, storage auto-scaling, backup retention, replica lag, log volume, and temporary storage can still matter.
Storage Performance Bottlenecks
Common storage-related bottlenecks include high disk latency, low IOPS, excessive table scans, poor indexes, insufficient RAM, excessive temporary spills, slow transaction-log writes, heavy swapping, storage throttling, and full disks. Understanding storage helps diagnose these problems more precisely.
Important metrics may include read IOPS, write IOPS, read latency, write latency, throughput, buffer hit ratio, disk utilization, log flush latency, temporary disk usage, storage queue depth, and free space. The exact metrics depend on the database platform and hosting environment.
A buffer hit ratio gives an indication of how often requested database pages are found in memory rather than requiring physical storage access. A low ratio may indicate significant physical I/O, but the metric must always be interpreted with workload context. Some workloads legitimately scan large data sets. Others should mostly hit memory.
Memory Hits
-----------
Total Requests
Storage Capacity Planning
Database storage capacity must account for more than current table data. A realistic estimate includes table data, indexes, transaction logs, temporary space, expected growth, backups, replicas, staging data, maintenance overhead, and archive requirements.
Table Data
+ Indexes
+ Logs
+ Temporary Space
+ Growth
+ Backups
+ Replication
Suppose the current database is 500 GB and it grows by 50 GB per month. After 12 months, the base data may reach 1.1 TB before considering indexes, logs, backups, and temporary space.
500 GB + 600 GB = 1.1 TB
If database storage becomes full, writes may fail, transactions may fail, logs may be unable to grow, and database availability may be at risk. Monitoring free storage is therefore an important operational responsibility. Storage alerts should trigger before the database is close to full, not after users are affected.
Storage and Data Types
Data type choices affect storage. An integer normally uses less storage than storing numbers as long text. A date type is more efficient and more meaningful than storing dates as strings. Correct data types improve storage efficiency, index size, cache utilization, validation, and performance.
INT
is usually better for numeric identifiers than
VARCHAR(100)
Large objects such as BLOB, CLOB, binary data, and large text can be stored in databases, but very large media files such as images and videos are often stored outside the relational database in object storage, with metadata stored in the database.
Database:
file_id
file_name
object_storage_url
Object Storage:
actual file content
Keeping huge media files outside the core transactional database can simplify backups, reduce database size, improve content delivery, and lower storage cost. The right architecture depends on requirements, but storage impact should be considered during design.
Primary Storage vs Secondary Storage
Traditional computer terminology often uses primary storage for RAM and CPU-accessible memory, while secondary storage means SSD or HDD. Database discussions sometimes use database storage more loosely to include persistent database files. Be careful with terminology and context.
A useful database mental model is that persistent data files contain database pages. Pages move into the buffer pool in RAM. The execution engine reads and modifies pages in memory. Writes flow back toward persistent storage, coordinated with transaction logging.
Persistent Data Files
|
Database Pages
|
Buffer Pool in RAM
|
Execution Engine
|
CPU
For writes, the database locates pages, loads them into memory, modifies them, generates transaction log records, persists required log information, commits, keeps pages dirty for a time, and writes pages to storage later. This is the practical storage flow behind many SQL updates.
Complete Read Flow
Consider this query:
SELECT *
FROM customers
WHERE customer_id = 101;
A simplified read flow starts with the query, performs an index lookup if a useful index exists, identifies the needed data page, checks the buffer pool, and either reads from memory or loads the page from storage.
Query
|
Index Lookup
|
Need Data Page
|
Check Buffer Pool
|
|-- Found
| |
| Read Row
|
|-- Not Found
|
Read Page from Storage
|
Cache Page
|
Read Row
This explains why the same query may be faster the second time. The required page may already be in memory. It also explains why indexes matter. A useful index can reduce how many pages the database needs to inspect.
Complete Write Flow
Now consider a stock update:
UPDATE products
SET stock = stock - 1
WHERE product_id = 500;
A simplified storage flow locates the page, loads it into memory if needed, modifies the page, generates transaction log information, persists the required log, commits the transaction, leaves the page dirty, and writes the page to normal storage later.
Locate Page
|
Load into Memory
|
Modify Page
|
Generate Transaction Log
|
Persist Required Log
|
Commit
|
Page Remains Dirty
|
Write Page to Storage Later
This flow explains why a committed update does not always mean the updated data page has already been written to its final data-file location. Durability comes from the coordination of log records, memory, and persistent storage.
Common Misconceptions
A common misconception is that data is read directly from disk every time. Not true. Often the required pages are already in RAM, and no physical storage read is needed. This is why buffer cache efficiency matters.
Query
|
RAM / Buffer Cache
|
Result
Another misconception is that RAM contains the entire database. That is not necessarily true. A database may be 5 TB while the server has 128 GB of RAM. Only a subset of active data can remain cached. The database continuously moves pages between storage and memory.
A third misconception is that SSD removes the need for indexes. False. SSDs reduce storage latency, but reading 10 pages is still generally better than reading 1,000,000 pages when the query needs only a few records. Good indexing remains important.
A fourth misconception is that more RAM solves every performance problem. More RAM may help caching, but it cannot fix poor SQL, bad indexes, lock contention, CPU bottlenecks, bad data modeling, excessive network latency, or inefficient application patterns. Database performance requires a complete view.
Core Storage Concepts Summary
The following table summarizes the core storage concepts that appear repeatedly in SQL performance and database architecture discussions.
| Concept | Purpose |
|---|---|
| RAM | Fast runtime working memory |
| Buffer Pool | Caches database pages |
| Page / Block | Basic database I/O unit |
| Data File | Persistent table and index storage |
| Transaction Log | Records changes for recovery |
| Dirty Page | Modified page not yet written to normal storage |
| Checkpoint | Coordinates memory and storage state |
| SSD / HDD | Persistent physical storage |
| Temporary Storage | Intermediate query workspace |
| Tablespace | Logical storage organization in some RDBMSs |
| Extent | Group of pages in some RDBMSs |
Simple Architecture to Remember
A simple architecture to remember places CPU at the top, memory in the middle, and persistent database files at the bottom. The buffer pool sits in RAM and caches database pages. Data files and transaction logs live on persistent storage. The database engine coordinates movement between these layers.
CPU
|
CPU Cache
|
RAM
|
+-------------+
| Buffer Pool |
+------+------+
|
Database Pages
|
+---------+---------+
| |
Data Files Transaction Logs
| |
+---------+---------+
|
Persistent Storage
SSD / HDD
This architecture explains many database behaviors. Reads may be served from memory or require storage access. Writes modify pages in memory but use logs for durability. Checkpoints coordinate dirty pages and data files. Temporary operations may spill to disk. Indexes add storage structures that help locate rows.
Interview-Ready Explanation
A short interview answer is: primary storage concepts in databases describe how the database uses memory and persistent storage to read, write, cache, and protect data. RAM provides fast working storage, disk or SSD provides durability, buffer pools cache pages, and transaction logs protect committed changes.
A stronger answer is: databases do not usually read individual rows directly from disk every time. They read pages or blocks into a buffer pool in RAM. If a page is already cached, the database gets a buffer cache hit. If not, it reads the page from storage. Writes modify pages in memory, create transaction log records, flush required log information at commit, and write dirty pages to data files later through checkpoints or background activity.
You can also add that storage performance depends on IOPS, throughput, latency, cache efficiency, indexes, temporary spills, and workload type. OLTP workloads need low latency and high IOPS for many small operations. Analytical workloads often need high throughput and efficient scanning. SSDs help, but good indexing, memory sizing, and query design still matter.
Key Takeaway
The most important database storage concept is the interaction between memory and persistent storage. The database does not normally execute queries by repeatedly reading individual rows directly from disk. Instead, persistent storage contains pages or blocks, those pages move into the buffer pool in RAM, the database engine works on them, and SQL results are returned.
Persistent Storage
|
Pages / Blocks
|
Buffer Pool in RAM
|
Database Engine
|
SQL Result
For writes, the database changes data in memory, records recovery information, commits according to durability rules, and writes dirty pages to persistent storage later.
Change Data in Memory
|
Record Recovery Information
|
Commit
|
Write Dirty Pages to Persistent Storage
RAM provides speed, persistent storage provides durability, database pages provide the unit of data movement, buffer pools reduce physical I/O, and transaction logs protect committed changes. Understanding these concepts is essential for later topics such as indexes, execution plans, query optimization, transactions, checkpoints, recovery, partitioning, capacity planning, and database performance tuning.