Database Architecture and Storage
What a relational database is made of, using Oracle as the example: the instance and its files, database objects, tablespaces and blocks, how storage grows, and how other platforms name the same parts.
Instance vs database
A relational database system has two halves: the instance, the software running in memory, and the database, the files stored on disk. The instance does the work; the database holds the data.
- Memory
- Reading from memory is thousands of times faster than reading from disk, so the instance keeps data in memory as much as it can. Oracle's shared memory is the system global area (SGA). It holds the buffer cache (recently used data blocks), the redo log buffer (recent changes), and the shared pool (parsed SQL and execution plans, ready to reuse). Each session also gets private memory, the program global area (PGA), for work such as sorting.
- Processes
- On Linux, every connection gets its own server process to run its SQL. Background processes handle housekeeping. The main ones are the database writer (DBWn), which saves changed blocks to disk; the log writer (LGWR), which saves redo; the checkpoint process (CKPT); the system monitor (SMON), which recovers the instance after a crash; the process monitor (PMON), which cleans up after failed sessions; and the archiver (ARCn), which copies filled redo logs.
- Files
- The permanent copy of everything: the data, the redo logs of changes, and the control files that describe how it all fits together.
Each instance has a name, its SID (system identifier), such as ORCL. The environment variable ORACLE_SID tells tools which instance you mean, and ORACLE_HOME points to where the Oracle software is installed.
Seeing it on a Linux server
Because Oracle runs each background process separately on Linux, you can see the instance with ps. Every background process is named ora_, then the process, then the SID:
$ ps -eo pid,cmd | grep -E "[o]ra_|[o]racleORCL"
2101 ora_pmon_ORCL
2105 ora_dbw0_ORCL
2107 ora_lgwr_ORCL
2109 ora_ckpt_ORCL
2111 ora_smon_ORCL
2117 ora_arc0_ORCL
3310 oracleORCL (LOCAL=NO)
The last line is a server process for a session connected over the network (LOCAL=NO). If the server loses power, all of these processes and everything in memory are gone, but the database files remain. When the instance starts again, it reads those files and picks up where it left off.
Starting Oracle: three stages
Oracle makes the split between instance and database especially clear, because it starts in three stages:
- NOMOUNT. The instance starts: it reads its parameter file, allocates the SGA, and starts the background processes. No database is attached yet.
- MOUNT. The instance reads the control files to learn where the database's files are.
- OPEN. The instance opens the data files and redo logs, and users can connect.
$ sqlplus / as sysdba
SQL> STARTUP
ORACLE instance started.
Total System Global Area 4294964000 bytes
Database mounted.
Database opened.
One instance, many pluggable databases
Modern Oracle uses a multitenant design, and since Oracle 21c it's the only option. The instance runs one container database (CDB), which holds one or more pluggable databases (PDBs). Each PDB looks like a separate database to the applications that use it, while all of them share the instance's memory and background processes.
The files that make up a database
Here's a typical layout for a database named ORCL on Linux:
/u01/app/oracle/oradata/ORCL/
├── control01.ctl # control file (a second copy is kept on another disk)
├── redo01.log # online redo logs, used in rotation
├── redo02.log
├── redo03.log
├── system01.dbf # SYSTEM tablespace: the data dictionary
├── sysaux01.dbf # SYSAUX tablespace: supporting tools and statistics
├── undotbs01.dbf # UNDO tablespace: old versions of changed data
├── temp01.dbf # TEMP tablespace: sorts that don't fit in memory
├── users01.dbf # USERS tablespace: default home for user data
└── SALESPDB/ # each pluggable database has its own data files
$ORACLE_HOME/dbs/spfileORCL.ora # server parameter file
/u01/app/oracle/diag/rdbms/orcl/ORCL/trace/alert_ORCL.log # alert log
- Data files
- Hold the actual data: tables, indexes, and other objects. In Oracle they usually end in
.dbf, and every data file belongs to a tablespace, covered below. They're usually the largest files on the server. - Redo logs
- Record every change made to the data, in order, before that change is written to the data files. This is called write-ahead logging. Oracle uses a small set of online redo logs in rotation: when one fills, it switches to the next. In ARCHIVELOG mode, which every production database should use, the archiver copies each filled log to an archived redo log before it's reused. Archived logs make point-in-time recovery and standby databases (Data Guard) possible.
- Control files
- Small binary files that describe the database: its name, where its data files and redo logs are, and how far recovery has progressed. The database can't open without one, so Oracle keeps identical copies, ideally on different disks. This is called multiplexing.
- Parameter file
- The instance's settings, such as how much memory to use. Oracle normally uses a binary server parameter file (spfile), changed with
ALTER SYSTEM SET. A text version, the pfile (init<SID>.ora), is also possible. - Alert log and trace files
- The alert log is a running record of startups, shutdowns, errors, and important events. DBAs read it first when something goes wrong. Detailed trace files for individual problems sit in the same directory.
- Network files
- The listener, a separate process that accepts new connections on port 1521, is configured in
listener.ora. Clients look up connection details intnsnames.ora. Both live in$ORACLE_HOME/network/admin.
Database objects
Everything you create inside a database is called an object. These are the ones you'll work with most:
- Schema
- The set of objects owned by one database user. In Oracle, creating a user creates a schema with the same name, so the user
SALESowns theSALESschema. A table's full name includes its schema, as insales.orders. - Table
- Stores data in rows and columns. Each column has a data type, such as
NUMBER,VARCHAR2(text), orDATE. Constraints keep the data valid: a primary key uniquely identifies each row, and a foreign key links a row to a row in another table. - Index
- A separate, sorted structure that helps the database find rows without reading the whole table. More on indexes below.
- View
- A saved query that looks and acts like a table but stores no data of its own. Views hide complex joins and can limit which rows and columns a user can see. A materialized view is different: it stores the query's results and is refreshed to stay current.
- Sequence
- Generates unique numbers, one after another, often used as IDs for new rows. Since Oracle 12c, an identity column can create and use a sequence for you.
- Stored procedures, functions, and packages
- Named blocks of code saved in the database and run on demand, for example to close out the month's accounts. Functions return a value and can be used inside queries. In Oracle they're written in PL/SQL, and related procedures and functions are often grouped into a package.
- Trigger
- Code that runs automatically when something happens to a table, such as an insert, update, or delete. A common use is auditing, for example recording who changed a salary and when.
Here's how a few of them are created in Oracle:
CREATE USER sales IDENTIFIED BY "Change_Me_2026" QUOTA UNLIMITED ON users; -- also creates the SALES schema
CREATE TABLE sales.orders (
id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- numbered by a sequence
customer VARCHAR2(100) NOT NULL,
amount NUMBER(10,2) NOT NULL
);
CREATE INDEX sales.orders_customer_idx ON sales.orders (customer);
CREATE VIEW sales.big_orders AS
SELECT id, customer, amount FROM sales.orders WHERE amount > 1000;
Oracle describes every object in its data dictionary, which you query like any other table. Views starting with USER_ show your own objects, ALL_ the ones you can access, and DBA_ everything:
SELECT object_name, object_type FROM dba_objects WHERE owner = 'SALES';
Storage: tablespaces and data files
Oracle separates how data is organized, called logical storage, from where it actually lives on disk, called physical storage. The link between the two is the tablespace: a logical storage area made up of one or more data files.
- Tablespace
- A logical storage area, made of one or more data files.
- Segment
- The space used by one object, such as a table or an index.
- Extent
- A group of neighboring blocks, handed to a segment all at once when it needs more room.
- Block
- The smallest unit of storage, 8 KB by default.
- Data file
- The actual file on disk that stores a tablespace's data. A tablespace can be spread across many data files.
Every Oracle database starts with the same standard tablespaces:
| Tablespace | What it holds |
|---|---|
SYSTEM | The data dictionary: Oracle's own description of every object. |
SYSAUX | Supporting data for Oracle's tools, such as performance statistics. |
UNDOTBS1 | Undo: the old versions of changed data, used to roll back and to give queries a consistent view. |
TEMP | Temporary space for sorts and joins that don't fit in memory. |
USERS | The default home for users' tables and indexes. |
Applications usually get their own tablespaces. Here, a new tablespace starts at 10 GB and grows automatically, 1 GB at a time, up to 100 GB:
CREATE TABLESPACE app_data
DATAFILE '/u02/oradata/ORCL/app_data01.dbf' SIZE 10G
AUTOEXTEND ON NEXT 1G MAXSIZE 100G;
-- later, when it needs more room
ALTER TABLESPACE app_data
ADD DATAFILE '/u02/oradata/ORCL/app_data02.dbf' SIZE 10G;
Inside the data files: blocks and indexes
Data files are divided into fixed-size chunks called blocks, 8 KB each by default (most other platforms call them pages). Each block holds a number of rows, and Oracle always reads and writes whole blocks, never single rows.
To find rows, the database either reads every block of the table, a full table scan, or uses an index. An index works like the index at the back of a book: a small, sorted structure that points straight to the blocks holding the rows you want.
The execution plan shows which one Oracle chose. Here, it uses the primary key's index to jump straight to one row (output trimmed):
EXPLAIN PLAN FOR SELECT * FROM sales.orders WHERE id = 1001;
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
------------------------------------------------------------
| Id | Operation | Name | Rows | Cost |
------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID| ORDERS | 1 | 2 |
| 2 | INDEX UNIQUE SCAN | SYS_C008120 | 1 | 1 |
------------------------------------------------------------
Without a usable index, the plan would show TABLE ACCESS FULL instead. Indexes make reads much faster, but every index has to be updated whenever its table changes, so each one slows down writes a little. Choosing the right indexes is a big part of performance tuning.
How storage grows and is monitored
In Oracle, storage fills up in layers:
- Blocks fill up. New rows go into free space in a table's existing blocks.
- The segment gets a new extent. When its blocks are full, the table is given another extent from the tablespace's free space.
- The data file grows. When the tablespace has no free space left, a data file with
AUTOEXTEND ONgrows itself, up to itsMAXSIZE. - Writes fail. When every file has hit its maximum size, or the disk is full, inserts and updates fail.
ORA-01653: unable to extend table SALES.ORDERS by 128 in tablespace APP_DATA
The fix is to give the tablespace more room: resize a data file, raise its maximum size, or add another data file.
It's not just tables that grow
- Indexes grow along with their tables, and together can take up as much space as the data itself. When an index can't grow, the error is
ORA-01654. - Archived redo logs pile up in the fast recovery area until they're backed up and deleted, usually by RMAN, Oracle's backup tool. When the area fills up, Oracle stops accepting changes and reports
ORA-00257: Archiver error. This is one of the most common production emergencies. - Undo grows with large or long-running transactions.
- Temporary space in
TEMPgrows when large sorts and joins don't fit in the PGA. When it runs out, queries fail withORA-01652. - Deleting data doesn't shrink files. Deleted rows free up space inside blocks for new rows, but the segment keeps its extents and the data files stay the same size. Space can be reclaimed, for example with
ALTER TABLE … SHRINK SPACE, but DBAs do it carefully and rarely.
Monitoring storage
DBAs watch storage at every layer, and set alerts well before anything fills up. By default, Oracle raises its own warning when a tablespace is 85% full, and a critical alert at 97%.
- How full each tablespace is, counting the room its files can still auto-extend into.
- Free space on each disk or file system.
- Space used in the fast recovery area by archived logs and backups.
- The growth rate over time, which tells you when you'll run out and feeds capacity planning.
-- how full is each tablespace, counting room to auto-extend?
SELECT tablespace_name, ROUND(used_percent, 1) AS pct_used
FROM dba_tablespace_usage_metrics
ORDER BY used_percent DESC;
On Linux, df -h shows how full the file system holding the data files is:
$ df -h /u01
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 500G 400G 100G 80% /u01
On other platforms
PostgreSQL, SQL Server, and MySQL work the same way underneath, but use different names. Use this section as a reference when you meet them.
| Oracle | PostgreSQL | SQL Server | MySQL (InnoDB) | |
|---|---|---|---|---|
| The running server | Instance | Server (main process postgres) | Instance | Server (mysqld) |
| What one server holds | A container database (CDB) holding pluggable databases (PDBs) | A "database cluster": many databases in one data directory | Many databases, plus system databases such as master and tempdb | Many databases; "database" and "schema" mean the same thing |
| Shared memory | System global area (SGA): buffer cache, shared pool, redo log buffer | Shared buffers and WAL buffers | Buffer pool and plan cache | InnoDB buffer pool and log buffer |
| The change log | Online and archived redo logs, written by the log writer (LGWR) | Write-ahead log (WAL), in the pg_wal directory | Transaction log (.ldf file) | InnoDB redo log, plus the binary log (binlog) for replication and point-in-time recovery |
| Old row versions | Undo tablespace | Kept in the table itself, cleaned up by VACUUM | Transaction log, plus the version store in tempdb | InnoDB undo logs |
| Storage areas | Tablespaces: segments, extents, and blocks | Tablespaces are just directories: pg_default and pg_global | Filegroups, such as PRIMARY | System, file-per-table, general, undo, and temporary tablespaces |
| Data files | .dbf files | A set of files per table and index, in 1 GB pieces, under the data directory | .mdf (primary) and .ndf (secondary) files | .ibd files, usually one per table |
| Control information | Control files | pg_control file | master database | Data dictionary (mysql.ibd) |
| Configuration | Server parameter file (spfile) | postgresql.conf and pg_hba.conf | Stored in master; changed with sp_configure | my.cnf (Linux) or my.ini (Windows) |
| Diagnostic log | Alert log | Server log | Error log (ERRORLOG) | Error log |
| Default port | 1521 | 5432 | 1433 | 3306 |
Key takeaways
- The instance is memory (the SGA and PGA) plus processes; the database is the files on disk. Oracle starts in three stages, NOMOUNT, MOUNT, and OPEN, and one instance can serve many pluggable databases.
- The key files are data files, redo logs, control files, and the parameter file. Never delete redo logs or control files.
- A schema is the set of objects a user owns: tables, indexes, views, sequences, PL/SQL procedures, and triggers.
- Tablespaces are made of segments, extents, and 8 KB blocks, stored in data files. Indexes let Oracle jump to the right blocks instead of scanning the whole table.
- Data files auto-extend until they hit their maximum size or the disk fills, so DBAs monitor tablespaces, disks, and the fast recovery area, and watch the growth trend.
- PostgreSQL, SQL Server, and MySQL use different names for the same ideas. The On other platforms section maps them.