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

ProductMemory and process (thread) architectureConnections, cursors, and SQL cacheProduct overview
PostgreSQLPostgreSQL Memory and Process ArchitecturePostgreSQL Connections, Cursors, and SQL CachePostgreSQL
MySQLMySQL Memory and Thread ArchitectureMySQL Connections, Cursors, and SQL CacheMySQL (InnoDB)
OracleOracle Memory and Process ArchitectureOracle Connections, Cursors, and SQL CacheOracle Database
SQL ServerSQL Server Memory and Thread ArchitectureSQL Server Connections, Cursors, and Plan CacheSQL Server / Azure SQL
KDBSKDBS Memory and Thread ArchitectureKDBS Connections, Portals, and Statement CacheKDBS
  • 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.

  1. The Execution entity handling the connection receives SQL and looks in the SQL and catalog cache for 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).
  2. 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 the Log buffer (③).
  3. 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.
  4. Background work writes the modified pages (dirty pages) to the Data file later (⑤). If the server dies before that, it reapplies them from the log file.
  5. Work memory is 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 2 still holds Process 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 2 has No 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 1 and Connection 3 run alternately as coroutine tasks inside the same reactor.
PostgreSQLMySQLOracleSQL ServerKDBS
Operating system processesSeveralOneSeveral (Linux default)OneOne
One connectionBackend processConnection threadServer process (dedicated server)Session. A worker per requestConnection structure inside a reactor
SchedulingOperating systemOperating systemOperating systemCooperative (SQLOS)Cooperative (reactor)
Maximum connections setting (default)max_connections (100)max_connections (151)PROCESSES, SESSIONSuser connections (0 = 32,767)max_connections (0 = unlimited)
Server feature to reduce connectionsNone (external pooler)Thread cache, thread pool (Enterprise)Shared server, DRCPNot neededNot needed
Parallel queryParallel worker processesPartial (parallel scan)Parallel execution serversParallel planNone

Memory

PostgreSQLMySQLOracleSQL ServerKDBS
Form of the shared areaShared memory segmentProcess address spaceSGA (shared memory)Process address spaceProcess address space
Buffer poolshared_buffersInnoDB buffer poolBuffer cacheBuffer poolBuffer pool (buffer_pool_frames)
Default buffer pool size128MB128MBAutomatic within the SGAAutomatic within the allowed memoryNo default (required setting)
Log bufferWAL buffer (wal_buffers)Log buffer (innodb_log_buffer_size)Redo log buffer (LOG_BUFFER)Log bufferWAL ring (fixed at 1MiB)
Work memorywork_mem: per operationSession buffers: per purposePGA: instance-wide total targetMemory grant: reserved per query before executionRow count limit
When work memory runs outTemporary fileTemporary file, on-disk temporary tableTemporary tablespacetempdbStatement fails
Overall limit settingNone (per area)None (per area)SGA_TARGET + PGA_AGGREGATE_LIMIT, or MEMORY_TARGETmax server memoryNone
Operating system cacheUsed together8.4 default bypasses it (O_DIRECT)Usually bypassedNot usedUsed together

Background Work

Each product has differently named processes or threads doing the same jobs.

JobPostgreSQLMySQL (InnoDB)OracleSQL ServerKDBS
Write the log to the file at commitThe backend process itselflog writer and log flusher threadsLGWRLOG WRITERReactor (one core) or WAL writer thread
Periodic log writewalwriterlog writerLGWR (every 3 seconds)LOG WRITERWAL drain timer
Checkpointcheckpointerpage cleaner, log checkpointerCKPT (record) + DBWn (write)CHECKPOINT, RECOVERY WRITERCheckpoint task
Writes to free buffersbackground writerpage cleanerDBWnLAZY WRITERwriteback timer
Old version cleanupautovacuum workerpurge threadUndo reused after the retention periodVersion store cleanup, GHOST CLEANUPDelete-mark cleanup by the writeback timer
Recovery at startupstartup processInnoDB recovery during startupSMONPer-database recoveryRecovery at mount

Connections, Cursors, and SQL Cache

PostgreSQLMySQLOracleSQL ServerKDBS
Cache that shares execution plansNoneNoneLibrary cache in the shared poolPlan cacheNone
What a session reusesAnalysis result and plan of a prepared statementParse and prepare result of a prepared statementSession cursor cachePrepared handleSyntax tree of a named statement
Key used to look up the cacheStatement nameStatement IDSQL text hash + execution environmentSQL text hash + SET optionsStatement shape (only for join order and statistics)
Statements that differ only in literalsEach gets its own plan (no cache)Each is optimized separatelyEach is hard parsed separately. CURSOR_SHARING = FORCE merges themEach is compiled separately. Simple and forced parameterization merge themMerged as the same shape
Plan when values differChoice between a value-specific plan and a generic planOptimized on every executionBind peeking, adaptive cursor sharingParameter sniffingCompiled on every execution
Result cacheNoneNone (removed in 8.0)Server result cacheNoneNone
Server cursorPortal. DECLARE, FETCHStored program cursor, protocol cursorEvery statement is a cursorT-SQL cursor, API cursorPortal (no SQL statement)
What the server holds during piecewise readsExecution state and snapshotInternal temporary tableExecution state and read point (SCN)A copy or keys in tempdb, depending on the typeThe whole result (up to 16MiB in memory)
Default result deliveryWhole result to the clientWhole result to the clientArray fetchStreamed as producedStreamed or collected in a portal
CancellationCancel request on a new connectionKILL QUERY from another connectionCancel from another session, client interrupt requestAttention on the same connectionCancel 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 atPostgreSQLMySQLOracleSQL ServerKDBS
Processes and threadspg_stat_activityperformance_schema.threadsV$PROCESS, V$BGPROCESSsys.dm_os_schedulers, sys.dm_os_workerssched in SHOW META
Shared memory layoutpg_shmem_allocationssys.memory_global_by_current_bytesV$SGAINFO, V$SGA_DYNAMIC_COMPONENTSsys.dm_os_memory_clerkspool, wal in SHOW META
Work memorypg_backend_memory_contextssys.memory_by_thread_by_current_bytesV$PGASTATsys.dm_exec_query_memory_grants
Connections and sessionspg_stat_activitySHOW PROCESSLISTV$SESSIONsys.dm_exec_sessions, sys.dm_exec_requestssys.session_state
Cached statements and planspg_prepared_statements (own session)performance_schema.prepared_statements_instancesV$SQL, V$SQLAREAsys.dm_exec_cached_plans, sys.dm_exec_query_statsSHOW PLANS, sys.statement_stats
Open cursorspg_cursors (own session)V$OPEN_CURSORsys.dm_exec_cursors

From the Articles

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