Oracle memory and process structure

Oracle distinguishes the instance from the database. The instance is a bundle of memory (the SGA) and background processes, and the database is the files on disk (data files, online redo logs, control files). The instance must mount and open the database before it can be used. On Unix and Linux the default is the process model, and one server process is attached to each session (dedicated server). Memory splits into the SGA, which all processes share, and the PGA, which each process has separately.

Key specs

ItemValue
Execution modelUnix and Linux: process model (default). Windows: threads inside a single process
Sessions and processesDedicated server (one server process per session, default) or shared server (dispatchers and a shared server pool)
Process count limitPROCESSES. Number of operating system processes, including background processes. Changing it requires a restart
Session count limitSESSIONS, 1.5 × PROCESSES + 22 by default
Shared memorySGA. If you give the total size with SGA_TARGET, component sizes are tuned automatically (ASMM)
SGA sizing unitGranule. 4MB or more depending on the SGA size
Process memoryPGA. PGA_AGGREGATE_TARGET (target for the total), PGA_AGGREGATE_LIMIT (limit for the total)
Fully automatic managementMEMORY_TARGET (AMM): manages SGA and PGA together under a single target
Redo log bufferLOG_BUFFER. Fixed at startup and cannot be changed at runtime
Dirty block writer processDBWn. The number is set with DB_WRITER_PROCESSES
Threaded model (optional)THREADED_EXECUTION = TRUE (since 12c): runs many background processes as threads inside a few processes

Process structure

Figure. Instance processes, the SGA, and files

flowchart TB
  CL["Client process"] -->|"① Connection request"| LS["Listener<br/>separate process outside the instance"]
  LS -->|"② Create a server process and hand over the connection"| SP["Server process<br/>one per session with a dedicated server"]
  CL -->|"③ SQL and results"| SP
  subgraph SGA ["SGA (shared memory)"]
    SH["Shared pool"]
    BC["Buffer cache"]
    RB["Redo log buffer"]
  end
  subgraph BGP ["Background processes"]
    DBW["DBWn"]
    LGWR["LGWR"]
    CKPT["CKPT"]
    SMON["SMON, PMON"]
  end
  subgraph DISK ["Database (disk)"]
    DF["Data files"]
    RF["Online redo log files"]
    CF["Control files"]
  end
  SP -->|"Find and parse cursors"| SH
  SP -->|"Read and modify blocks"| BC
  SP -->|"Generate redo"| RB
  DBW -->|"Write dirty blocks"| DF
  LGWR -->|"Write redo"| RF
  CKPT -->|"Record checkpoint position"| CF
  CKPT -->|"Record checkpoint position"| DF

Diagram explanation: Read the connection flow at the upper left first, then the SGA in the middle, then the files at the bottom.

  1. The Client process requests a connection from the Listener, not from the instance (①). The listener is a separate process (tnslsnr) that does not belong to the instance. It has the instance of the requested service create a Server process, hands over the connection (②), and steps out. After that, the client and the server process communicate directly (③). If the listener dies, connections that are already established stay up.
  2. When the server process receives SQL, it looks for a cursor of the same statement in the Shared pool, and parses and stores one if none exists. It reads and modifies data blocks in the Buffer cache and generates redo into the Redo log buffer on every modification. For a block that is not in the buffer cache, the server process reads it directly from the data file.
  3. DBWn writes dirty blocks in the buffer cache to the Data files, and LGWR writes the redo log buffer to the Online redo log files. The server process does not write to data files directly.
  4. CKPT does not write blocks. It records how far changes have been reflected on disk (the checkpoint position) in the Control files and the data file headers.
  5. SMON, PMON handle recovery and cleanup. SMON performs instance recovery when the instance is reopened after an abnormal shutdown, and PMON finds dead processes and has the locks and resources held by their sessions released.

Background processes

ProcessWhat it does
PMONMonitors other processes. Starts cleanup when a server process terminates abnormally
CLMNCleans up resources (locks, transactions) of dead processes and sessions (split from PMON in 12.2)
SMONInstance recovery, cleanup of unused temporary segments
DBWnWrites dirty blocks to the data files. When free buffers run short or the checkpoint must advance
LGWRWrites the redo log buffer to the online redo log files (Redo log)
CKPTRecords the checkpoint position in the control files and data file headers
MMANAutomatically tunes the size of SGA components (buffer cache, shared pool, and others)
MMON, MMNLAWR snapshots and alert threshold checks / writes ASH samples to disk
RECOResolves failed distributed transactions
LREGRegisters the instance and services with the listener
ARCnArchives the online redo log after a log switch (in archive log mode)
CJQ0, JnnnCoordinates / runs scheduler jobs
PnnnParallel execution servers. Run the pieces of a parallel query
SMCO, WnnnSpace preallocation and reclamation
Dnnn, SnnnDispatchers / shared server processes (in a shared server configuration)
VKTM, DBRM, DIAG, PSP0, GEN0Time reference upkeep, resource manager, diagnostic dumps, process spawning, general tasks

When LGWR writes. It writes when a user commits, when the redo log buffer is one-third full, every 3 seconds, at a log switch, and before DBWn writes a dirty block (if the redo for that block is not yet in the file). The last condition is the write-ahead logging rule.

Dedicated server and shared server. With a dedicated server, one server process is attached to one session, and the process remains even while the session is idle. With a shared server, a dispatcher (Dnnn) puts requests from many clients into a request queue in the SGA, and a pool of shared server processes (Snnn) takes them from the queue and runs them. In this case the session state (UGA) must be readable by any process, so it is kept in the large pool of the SGA instead of the PGA. The connection side is covered in Connections, cursors, and SQL cache.

Memory structure

Figure. SGA and PGA

block-beta
  columns 6
  t1["SGA: shared by all processes of the instance"]:6
  bc["Buffer cache<br/>data blocks"]:3 sp["Shared pool<br/>library cache, dictionary cache"]:2 rb["Redo log buffer"]
  lp["Large pool<br/>shared server UGA, parallel execution"]:2 jp["Java pool"] st["Streams pool"] im["In-Memory area"] fx["Fixed SGA"]
  t2["PGA: separate for each process"]:6
  wa["SQL work area<br/>sort, hash join, bitmap"]:2 pa["Private SQL area<br/>bind values, execution state"]:2 ug["Session memory (UGA)<br/>session variables, package state"]:2
  class t1,t2 plain
  class bc data
  class sp slot
  class rb hot
  class lp,jp,st,im,fx meta
  class wa,pa,ug muted

Diagram explanation: The top two rows are the SGA, and the bottom row is the PGA.

  • The Buffer cache holds copies of blocks read from the data files and is usually the largest part of the SGA (Buffer cache).
  • The Shared pool holds parsed SQL and execution plans (library cache), definitions of tables, columns, and privileges (dictionary cache), and query results (server result cache). When another session sends the same SQL text, it reuses the cursor stored here.
  • The Redo log buffer holds redo not yet written to the file. It is used circularly and LGWR keeps emptying it, so it is small.
  • The Large pool is an area for allocating large chunks separately from the shared pool, and is used by the session memory of shared servers, message buffers of parallel execution, and RMAN I/O buffers. The In-Memory area exists only when the column store (INMEMORY_SIZE) is enabled. The Fixed SGA is a small fixed area that holds instance state and the locations of other areas.
  • The three cells in the PGA row are memory used by a single server process alone. The SQL work area is the part that varies the most. A sort or hash join that finishes in memory is an optimal execution, one that goes through the temporary tablespace once is one-pass, and one that goes through it several times is multi-pass. With a dedicated server, the Session memory (UGA) is inside the PGA, and with a shared server it moves to the SGA.

SGA components

AreaContentSetting
Buffer cacheData blocks. Besides the default pool, the KEEP and RECYCLE pools and pools for other block sizesDB_CACHE_SIZE, DB_KEEP_CACHE_SIZE, DB_nK_CACHE_SIZE
Shared poolLibrary cache (shared SQL areas, PL/SQL code), dictionary cache, server result cache, reserved areaSHARED_POOL_SIZE, RESULT_CACHE_MAX_SIZE
Redo log bufferChange vectorsLOG_BUFFER
Large poolShared server UGA, parallel execution buffers, RMANLARGE_POOL_SIZE
Java pool, Streams poolJVM session code and data / stream and replication queuesJAVA_POOL_SIZE, STREAMS_POOL_SIZE
In-Memory areaColumnar copies (In-Memory option)INMEMORY_SIZE (default 0)
Fixed SGAInternal instance stateNo setting

Memory management modes

ModeSettingBehavior
Automatic memory management (AMM)MEMORY_TARGETOne target for SGA and PGA together. The instance also moves memory between the two
Automatic shared memory management (ASMM)SGA_TARGET + PGA_AGGREGATE_TARGETMMAN tunes the components inside the SGA. PGA is separate
ManualDB_CACHE_SIZE, SHARED_POOL_SIZE, and othersSet each area directly. Used together with ASMM, those values act as lower bounds

PGA_AGGREGATE_TARGET is a target. The instance tries to fit the total to this value by shrinking work areas, but it can be exceeded. PGA_AGGREGATE_LIMIT is a limit. When it is exceeded, calls that use a lot of PGA are aborted, and if that is still not enough, sessions are terminated (ORA-04036).

The path of one statement

Figure. Processes that UPDATE and COMMIT go through

sequenceDiagram
  participant C as Client
  participant S as Server process
  participant G as SGA
  participant L as LGWR
  participant R as Redo log file
  participant W as DBWn
  participant D as Data file
  C->>S: UPDATE
  S->>G: Find the cursor in the shared pool, hard parse if absent
  S->>G: Modify the block in the buffer cache, modify the undo block
  S->>G: Append redo to the redo log buffer
  C->>S: COMMIT
  S->>L: Ask it to write up to the commit record
  L->>R: Write the redo log buffer
  L-->>S: Write complete
  S-->>C: Commit complete
  Note over W,D: From here on, it happens later, independent of the commit
  W->>G: Collect dirty blocks
  W->>D: Write blocks

Diagram explanation: Time flows from top to bottom.

  1. When the Server process receives the UPDATE, it looks for a cursor with the same text in the shared pool of the SGA. If one exists, it uses the execution plan as is (soft parse). If not, it goes through syntax checking and optimization and builds a new one (hard parse).
  2. It modifies the data block and the undo block in the buffer cache. Both changes are turned into redo and put into the redo log buffer. Changes to undo blocks are also protected by redo.
  3. The server process that receives COMMIT does not write to the file itself, but notifies LGWR. When LGWR has written the redo log buffer to the Redo log file and wakes the server process, the server process responds to the client. When several sessions commit at the same time, LGWR combines them into one write. With COMMIT WRITE NOWAIT, the server process does not wait.
  4. Below the Note is the later work. DBWn writes dirty blocks to the Data file, and if the instance dies before that, SMON re-applies them from the redo log file.

In the sandbox

These are the values seen in this site's Oracle sandbox (Oracle AI Database 26ai Free, version 23.26.4).

ItemValue
Memory managementASMM. sga_target = 1,536MB, memory_target = 0
Buffer cache848MB (DEFAULT buffer cache)
Shared pool432MB
Java pool / large pool128MB / 16MB
Redo log buffer4.3MB (log_buffer = 4,292,608 bytes)
Granule size16MB
pga_aggregate_target / pga_aggregate_limit512MB / 2,048MB
processes / sessions200 / 322
Server type of sessionsAll DEDICATED
Kinds of background processes50 or more names running in V$BGPROCESS (DBW0, LGWR, CKPT, SMON, PMON, CLMN, MMAN, MMON, MMNL, RECO, LREG, and others)

Even though threaded_execution is FALSE, some V$PROCESS entries have EXECUTION_TYPE set to THREAD (BG00 to BG03, SCMN, and others). This version runs some background tasks as threads inside a single process.

Settings and checks

-- Current size of SGA components
SELECT component, current_size / 1024 / 1024 AS mb
FROM v$sga_dynamic_components WHERE current_size > 0 ORDER BY current_size DESC;
SELECT name, bytes / 1024 / 1024 AS mb FROM v$sgainfo ORDER BY bytes DESC;

-- PGA totals
SELECT name, value / 1024 / 1024 AS mb FROM v$pgastat
WHERE name IN ('aggregate PGA target parameter', 'total PGA allocated', 'total PGA inuse', 'maximum PGA allocated');

-- PGA per process
SELECT pname, spid, pga_used_mem / 1024 AS used_kb, pga_alloc_mem / 1024 AS alloc_kb
FROM v$process ORDER BY pga_alloc_mem DESC FETCH FIRST 10 ROWS ONLY;

-- Running background processes
SELECT name, description FROM v$bgprocess WHERE paddr <> HEXTORAW('00') ORDER BY name;

-- Dedicated or shared server
SELECT server, COUNT(*) FROM v$session GROUP BY server;

-- Did work areas finish in memory
SELECT name, value FROM v$sysstat WHERE name LIKE 'workarea executions%';
  • V$SGA_TARGET_ADVICE, V$PGA_TARGET_ADVICE, and V$DB_CACHE_ADVICE estimate what size would be better.
  • On Linux, place a large SGA in HugePages (USE_LARGE_PAGES). AMM (MEMORY_TARGET) cannot be used together with HugePages, so on large servers use ASMM.

Comparison with other DBMSs

OraclePostgreSQLMySQLSQL ServerKDBS
One connectionServer process (dedicated server)ProcessThreadSession. A worker per requestConnection inside a per-core reactor
Who writes the log at commitLGWRThe backend process itselfLog threadsLog writerGroup commit drain or WAL writer thread
Working memory limitInstance total (PGA_AGGREGATE_TARGET)Per operation (work_mem)Per session bufferPer-query memory grantRow count limit
Execution plan sharingShared pool (all sessions)NoneNonePlan cache (all sessions)None (compiled per statement)

The full comparison is in DBMS architecture at a glance.

In the articles

NOTE The kinds and defaults of background processes vary by version, edition, and the features enabled. Oracle Database Free limits SGA and PGA together to 2GB.

Related pages