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
| Item | Value |
|---|---|
| Execution model | Unix and Linux: process model (default). Windows: threads inside a single process |
| Sessions and processes | Dedicated server (one server process per session, default) or shared server (dispatchers and a shared server pool) |
| Process count limit | PROCESSES. Number of operating system processes, including background processes. Changing it requires a restart |
| Session count limit | SESSIONS, 1.5 × PROCESSES + 22 by default |
| Shared memory | SGA. If you give the total size with SGA_TARGET, component sizes are tuned automatically (ASMM) |
| SGA sizing unit | Granule. 4MB or more depending on the SGA size |
| Process memory | PGA. PGA_AGGREGATE_TARGET (target for the total), PGA_AGGREGATE_LIMIT (limit for the total) |
| Fully automatic management | MEMORY_TARGET (AMM): manages SGA and PGA together under a single target |
| Redo log buffer | LOG_BUFFER. Fixed at startup and cannot be changed at runtime |
| Dirty block writer process | DBWn. 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.
- The
Client processrequests a connection from theListener, 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 aServer 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. - 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 theBuffer cacheand generates redo into theRedo log bufferon every modification. For a block that is not in the buffer cache, the server process reads it directly from the data file. DBWnwrites dirty blocks in the buffer cache to theData files, andLGWRwrites the redo log buffer to theOnline redo log files. The server process does not write to data files directly.CKPTdoes not write blocks. It records how far changes have been reflected on disk (the checkpoint position) in theControl filesand the data file headers.SMON, PMONhandle 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
| Process | What it does |
|---|---|
| PMON | Monitors other processes. Starts cleanup when a server process terminates abnormally |
| CLMN | Cleans up resources (locks, transactions) of dead processes and sessions (split from PMON in 12.2) |
| SMON | Instance recovery, cleanup of unused temporary segments |
| DBWn | Writes dirty blocks to the data files. When free buffers run short or the checkpoint must advance |
| LGWR | Writes the redo log buffer to the online redo log files (Redo log) |
| CKPT | Records the checkpoint position in the control files and data file headers |
| MMAN | Automatically tunes the size of SGA components (buffer cache, shared pool, and others) |
| MMON, MMNL | AWR snapshots and alert threshold checks / writes ASH samples to disk |
| RECO | Resolves failed distributed transactions |
| LREG | Registers the instance and services with the listener |
| ARCn | Archives the online redo log after a log switch (in archive log mode) |
| CJQ0, Jnnn | Coordinates / runs scheduler jobs |
| Pnnn | Parallel execution servers. Run the pieces of a parallel query |
| SMCO, Wnnn | Space preallocation and reclamation |
| Dnnn, Snnn | Dispatchers / shared server processes (in a shared server configuration) |
| VKTM, DBRM, DIAG, PSP0, GEN0 | Time 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 cacheholds copies of blocks read from the data files and is usually the largest part of the SGA (Buffer cache). - The
Shared poolholds 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 bufferholds redo not yet written to the file. It is used circularly and LGWR keeps emptying it, so it is small. - The
Large poolis 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. TheIn-Memory areaexists only when the column store (INMEMORY_SIZE) is enabled. TheFixed SGAis 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 areais 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, theSession memory (UGA)is inside the PGA, and with a shared server it moves to the SGA.
SGA components
| Area | Content | Setting |
|---|---|---|
| Buffer cache | Data blocks. Besides the default pool, the KEEP and RECYCLE pools and pools for other block sizes | DB_CACHE_SIZE, DB_KEEP_CACHE_SIZE, DB_nK_CACHE_SIZE |
| Shared pool | Library cache (shared SQL areas, PL/SQL code), dictionary cache, server result cache, reserved area | SHARED_POOL_SIZE, RESULT_CACHE_MAX_SIZE |
| Redo log buffer | Change vectors | LOG_BUFFER |
| Large pool | Shared server UGA, parallel execution buffers, RMAN | LARGE_POOL_SIZE |
| Java pool, Streams pool | JVM session code and data / stream and replication queues | JAVA_POOL_SIZE, STREAMS_POOL_SIZE |
| In-Memory area | Columnar copies (In-Memory option) | INMEMORY_SIZE (default 0) |
| Fixed SGA | Internal instance state | No setting |
Memory management modes
| Mode | Setting | Behavior |
|---|---|---|
| Automatic memory management (AMM) | MEMORY_TARGET | One target for SGA and PGA together. The instance also moves memory between the two |
| Automatic shared memory management (ASMM) | SGA_TARGET + PGA_AGGREGATE_TARGET | MMAN tunes the components inside the SGA. PGA is separate |
| Manual | DB_CACHE_SIZE, SHARED_POOL_SIZE, and others | Set 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.
- When the
Server processreceives theUPDATE, it looks for a cursor with the same text in the shared pool of theSGA. 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). - 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.
- The server process that receives
COMMITdoes not write to the file itself, but notifiesLGWR. When LGWR has written the redo log buffer to theRedo log fileand 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. WithCOMMIT WRITE NOWAIT, the server process does not wait. - Below the
Noteis the later work.DBWnwrites dirty blocks to theData 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).
| Item | Value |
|---|---|
| Memory management | ASMM. sga_target = 1,536MB, memory_target = 0 |
| Buffer cache | 848MB (DEFAULT buffer cache) |
| Shared pool | 432MB |
| Java pool / large pool | 128MB / 16MB |
| Redo log buffer | 4.3MB (log_buffer = 4,292,608 bytes) |
| Granule size | 16MB |
pga_aggregate_target / pga_aggregate_limit | 512MB / 2,048MB |
processes / sessions | 200 / 322 |
| Server type of sessions | All DEDICATED |
| Kinds of background processes | 50 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, andV$DB_CACHE_ADVICEestimate 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
| Oracle | PostgreSQL | MySQL | SQL Server | KDBS | |
|---|---|---|---|---|---|
| One connection | Server process (dedicated server) | Process | Thread | Session. A worker per request | Connection inside a per-core reactor |
| Who writes the log at commit | LGWR | The backend process itself | Log threads | Log writer | Group commit drain or WAL writer thread |
| Working memory limit | Instance total (PGA_AGGREGATE_TARGET) | Per operation (work_mem) | Per session buffer | Per-query memory grant | Row count limit |
| Execution plan sharing | Shared pool (all sessions) | None | None | Plan 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.