DBMS Architecture at a Glance
A database server does not run on disk files alone. It needs execution entities (processes or threads) that open, read, and write the files, and the memory they use. Together they are called an instance. The names and the way each product divides the work differ, but the jobs are the same. This document first shows that common structure, then points to the per-product documents.
Per-Product Documents
| Product | Memory and process (thread) architecture | Connections, cursors, and SQL cache | Product overview |
|---|---|---|---|
| PostgreSQL | PostgreSQL Memory and Process Architecture | PostgreSQL Connections, Cursors, and SQL Cache | PostgreSQL |
| MySQL | MySQL Memory and Thread Architecture | MySQL Connections, Cursors, and SQL Cache | MySQL (InnoDB) |
| Oracle | Oracle Memory and Process Architecture | Oracle Connections, Cursors, and SQL Cache | Oracle Database |
| SQL Server | SQL Server Memory and Thread Architecture | SQL Server Connections, Cursors, and Plan Cache | SQL Server / Azure SQL |
| KDBS | KDBS Memory and Thread Architecture | KDBS Connections, Portals, and Statement Cache | KDBS |
- The memory and process (thread) architecture documents cover which processes or threads make up the server, how memory is divided into areas, and how a single statement and a single commit travel through them.
- The connections, cursors, and SQL cache documents cover how a client connects and a session is created, where and for how long the parsed and planned result of a statement is kept, and what the server holds for a cursor that reads a result in pieces.
Common Structure
Figure. Components of a database server
flowchart TB
CL["Client"] -->|"Connect, SQL"| EX["Execution entity handling the connection<br/>process, thread, worker, reactor"]
subgraph SHM ["Shared memory area"]
SC["SQL and catalog cache"]
BP["Buffer pool"]
LB["Log buffer"]
end
WM["Work memory<br/>sort, hash, cursor state"]
subgraph BG ["Background work"]
LW["Log write"]
PW["Dirty page write, checkpoint"]
CLN["Old version cleanup, recovery, monitoring"]
end
subgraph DISK ["Disk"]
LF["Log file"]
DF["Data file"]
end
EX -->|"① Parse, plan"| SC
EX -->|"② Read and modify pages"| BP
EX -->|"③ Record changes"| LB
EX -->|"Sort, hash"| WM
LB --> LW
LW -->|"④ Write before commit"| LF
BP --> PW
PW -->|"⑤ Write later"| DF
CLN -.-> BP
Diagram notes: all five products have something that corresponds to each box in this figure.
- The
Execution entity handling the connectionreceives SQL and looks in theSQL and catalog cachefor the parsed statement or the table definition (①). Products differ on whether they also keep the execution plan in the shared area (Oracle and SQL Server do; the others do not). - Data is read and modified in pages of the
Buffer pool, not on disk (②). Each time it modifies a page, it writes what changed into theLog buffer(③). - A commit is complete only when the log of that transaction has been written to the
Log file(④). Writing the log before the data file is the WAL rule. Background workwrites the modified pages (dirty pages) to theData filelater (⑤). If the server dies before that, it reapplies them from the log file.Work memoryis not shared. It is memory needed by a single request only, such as sorts, hashes, and the execution state of a cursor.
Execution Model
Figure. Execution entities with three connections
block-beta
columns 5
h0["Model"] h1["Connection 1 (running)"] h2["Connection 2 (idle)"] h3["Connection 3 (running)"] h4["Number of execution entities"]
a0["Process per connection<br/>PostgreSQL, Oracle dedicated server"] a1["Process 1"] a2["Process 2"] a3["Process 3"] a4["Number of connections"]
b0["Thread per connection<br/>MySQL"] b1["Thread 1"] b2["Thread 2"] b3["Thread 3"] b4["Number of connections"]
c0["Worker per request<br/>SQL Server"] c1["Worker A"] c2["No worker"] c3["Worker B"] c4["Number of running requests"]
d0["Reactor per core<br/>KDBS"] d1["Task on reactor 0"] d2["No task"] d3["Task on reactor 0"] d4["Number of cores"]
class h0,h1,h2,h3,h4 meta
class a0,b0,c0,d0 plain
class a1,a3,b1,b3,c1,c3 hot
class a2,b2 muted
class c2,d2 free
class d1,d3 data
class a4,b4,c4,d4 slot
Diagram notes: each row is one model, and the three middle cells show what three connections (two running a statement, one idle) occupy.
- Process per connection. The idle
Connection 2still holdsProcess 2. Each process has its own address space, so data to be shared goes into a shared memory segment. If one process dies, the other connections are largely unaffected, but connecting is expensive and each connection uses a lot of memory. - Thread per connection. The structure is the same, with threads instead of processes. All threads use the same address space, so no shared memory segment is needed and creating one is cheap.
- Worker per request. The idle
Connection 2hasNo worker. A session is a structure that holds only state, and it borrows a worker thread only when a request arrives. Each CPU has a scheduler, and workers yield voluntarily as they run. - Reactor per core. The number of threads is fixed at the number of cores, regardless of the number of connections. The statements of
Connection 1andConnection 3run alternately as coroutine tasks inside the same reactor.
| PostgreSQL | MySQL | Oracle | SQL Server | KDBS | |
|---|---|---|---|---|---|
| Operating system processes | Several | One | Several (Linux default) | One | One |
| One connection | Backend process | Connection thread | Server process (dedicated server) | Session. A worker per request | Connection structure inside a reactor |
| Scheduling | Operating system | Operating system | Operating system | Cooperative (SQLOS) | Cooperative (reactor) |
| Maximum connections setting (default) | max_connections (100) | max_connections (151) | PROCESSES, SESSIONS | user connections (0 = 32,767) | max_connections (0 = unlimited) |
| Server feature to reduce connections | None (external pooler) | Thread cache, thread pool (Enterprise) | Shared server, DRCP | Not needed | Not needed |
| Parallel query | Parallel worker processes | Partial (parallel scan) | Parallel execution servers | Parallel plan | None |
Memory
| PostgreSQL | MySQL | Oracle | SQL Server | KDBS | |
|---|---|---|---|---|---|
| Form of the shared area | Shared memory segment | Process address space | SGA (shared memory) | Process address space | Process address space |
| Buffer pool | shared_buffers | InnoDB buffer pool | Buffer cache | Buffer pool | Buffer pool (buffer_pool_frames) |
| Default buffer pool size | 128MB | 128MB | Automatic within the SGA | Automatic within the allowed memory | No default (required setting) |
| Log buffer | WAL buffer (wal_buffers) | Log buffer (innodb_log_buffer_size) | Redo log buffer (LOG_BUFFER) | Log buffer | WAL ring (fixed at 1MiB) |
| Work memory | work_mem: per operation | Session buffers: per purpose | PGA: instance-wide total target | Memory grant: reserved per query before execution | Row count limit |
| When work memory runs out | Temporary file | Temporary file, on-disk temporary table | Temporary tablespace | tempdb | Statement fails |
| Overall limit setting | None (per area) | None (per area) | SGA_TARGET + PGA_AGGREGATE_LIMIT, or MEMORY_TARGET | max server memory | None |
| Operating system cache | Used together | 8.4 default bypasses it (O_DIRECT) | Usually bypassed | Not used | Used together |
Background Work
Each product has differently named processes or threads doing the same jobs.
| Job | PostgreSQL | MySQL (InnoDB) | Oracle | SQL Server | KDBS |
|---|---|---|---|---|---|
| Write the log to the file at commit | The backend process itself | log writer and log flusher threads | LGWR | LOG WRITER | Reactor (one core) or WAL writer thread |
| Periodic log write | walwriter | log writer | LGWR (every 3 seconds) | LOG WRITER | WAL drain timer |
| Checkpoint | checkpointer | page cleaner, log checkpointer | CKPT (record) + DBWn (write) | CHECKPOINT, RECOVERY WRITER | Checkpoint task |
| Writes to free buffers | background writer | page cleaner | DBWn | LAZY WRITER | writeback timer |
| Old version cleanup | autovacuum worker | purge thread | Undo reused after the retention period | Version store cleanup, GHOST CLEANUP | Delete-mark cleanup by the writeback timer |
| Recovery at startup | startup process | InnoDB recovery during startup | SMON | Per-database recovery | Recovery at mount |
Connections, Cursors, and SQL Cache
| PostgreSQL | MySQL | Oracle | SQL Server | KDBS | |
|---|---|---|---|---|---|
| Cache that shares execution plans | None | None | Library cache in the shared pool | Plan cache | None |
| What a session reuses | Analysis result and plan of a prepared statement | Parse and prepare result of a prepared statement | Session cursor cache | Prepared handle | Syntax tree of a named statement |
| Key used to look up the cache | Statement name | Statement ID | SQL text hash + execution environment | SQL text hash + SET options | Statement shape (only for join order and statistics) |
| Statements that differ only in literals | Each gets its own plan (no cache) | Each is optimized separately | Each is hard parsed separately. CURSOR_SHARING = FORCE merges them | Each is compiled separately. Simple and forced parameterization merge them | Merged as the same shape |
| Plan when values differ | Choice between a value-specific plan and a generic plan | Optimized on every execution | Bind peeking, adaptive cursor sharing | Parameter sniffing | Compiled on every execution |
| Result cache | None | None (removed in 8.0) | Server result cache | None | None |
| Server cursor | Portal. DECLARE, FETCH | Stored program cursor, protocol cursor | Every statement is a cursor | T-SQL cursor, API cursor | Portal (no SQL statement) |
| What the server holds during piecewise reads | Execution state and snapshot | Internal temporary table | Execution state and read point (SCN) | A copy or keys in tempdb, depending on the type | The whole result (up to 16MiB in memory) |
| Default result delivery | Whole result to the client | Whole result to the client | Array fetch | Streamed as produced | Streamed or collected in a portal |
| Cancellation | Cancel request on a new connection | KILL QUERY from another connection | Cancel from another session, client interrupt request | Attention on the same connection | Cancel request on a new connection |
For the two products that share execution plans (Oracle and SQL Server), whether you use bind variables (parameters) is a central tuning topic. A statement with literals embedded becomes a different cache entry for each value, so compilation repeats and the cache overflows. Products that do not share plans avoid this problem, but they pay the planning cost for each connection or each execution, even for the same statement.
Where to Check
| What to look at | PostgreSQL | MySQL | Oracle | SQL Server | KDBS |
|---|---|---|---|---|---|
| Processes and threads | pg_stat_activity | performance_schema.threads | V$PROCESS, V$BGPROCESS | sys.dm_os_schedulers, sys.dm_os_workers | sched in SHOW META |
| Shared memory layout | pg_shmem_allocations | sys.memory_global_by_current_bytes | V$SGAINFO, V$SGA_DYNAMIC_COMPONENTS | sys.dm_os_memory_clerks | pool, wal in SHOW META |
| Work memory | pg_backend_memory_contexts | sys.memory_by_thread_by_current_bytes | V$PGASTAT | sys.dm_exec_query_memory_grants | |
| Connections and sessions | pg_stat_activity | SHOW PROCESSLIST | V$SESSION | sys.dm_exec_sessions, sys.dm_exec_requests | sys.session_state |
| Cached statements and plans | pg_prepared_statements (own session) | performance_schema.prepared_statements_instances | V$SQL, V$SQLAREA | sys.dm_exec_cached_plans, sys.dm_exec_query_stats | SHOW PLANS, sys.statement_stats |
| Open cursors | pg_cursors (own session) | V$OPEN_CURSOR | sys.dm_exec_cursors |
From the Articles
- 1.5 Buffer Pool
- 1.6 Buffer Pool Management Rules by Database
- 1.7 Double Buffering
- 6.3 Group Commit
- 6.4 Checkpoint
NOTE Default values and names in the tables are based on PostgreSQL 17, MySQL 8.0 and 8.4, Oracle 23, SQL Server 2022, and KDBS v3.5. They can vary by version, so also check the notes in the per-product documents.
Related pages
- ACID
- PostgreSQL Memory and Process Architecture
- MySQL memory and thread structure
- Oracle memory and process structure
- SQL Server Memory and Thread Structure
- KDBS Memory and Thread Architecture
- PostgreSQL connections, cursors, and SQL cache
- MySQL Connections, Cursors, and SQL Cache
- Oracle Connections, Cursors, and the SQL Cache
- SQL Server Connections, Cursors, and Plan Cache
- KDBS connections, portals, and statement cache
- Operating system cache and direct I/O