Explain Oracle Database architecture: instance, database, SGA, PGA and background processes.
An Oracle database is the set of files on disk; an instance is the memory and processes that open and serve it. One database is usually served by one instance; Real Application Clusters (RAC) run several instances on different servers against the same shared database.
Files
- Datafiles grouped into tablespaces (SYSTEM, SYSAUX, USERS, TEMP, UNDO, application tablespaces).
- Redo log files: record every change, for crash recovery; archived as archive logs for point-in-time recovery and standby databases.
- Control file: the database's map (datafiles, redo logs, checkpoints).
Memory
- SGA (System Global Area, shared): buffer cache (data blocks), shared pool (parsed SQL and execution plans, data dictionary cache), redo log buffer, large and Java pools.
- PGA (Program Global Area, per server process): sort and hash areas, session variables.
Key background processes
DBWn writes dirty buffers to datafiles; LGWR writes the redo buffer to the online redo log at commit (this is what makes a commit durable); CKPT records checkpoints; SMON performs instance recovery; PMON cleans up failed sessions; ARCn archives redo logs.
Multitenant
Since 12c, a container database (CDB) holds many pluggable databases (PDBs); from 21c onward, multitenant is the only architecture. Each application usually connects to its own PDB through a service name.
Example
-- Which PDB am I in, and what instance and version?
SELECT sys_context('USERENV', 'CON_NAME') AS pdb,
instance_name, version_full
FROM v$instance;
-- SGA components
SELECT name, ROUND(bytes / 1024 / 1024) AS mb FROM v$sgainfo ORDER BY bytes DESC;
-- Tablespace usage
SELECT tablespace_name, ROUND(SUM(bytes) / 1024 / 1024) AS mb
FROM dba_data_files GROUP BY tablespace_name;# JDBC URL for a PDB service (thin driver)
jdbc:oracle:thin:@//db-host:1521/ORDERS_PDBFollow-up questions interviewers ask
Try answering each one before you open it.
What happens when you COMMIT in Oracle?
The server process generates redo for the changes as it works; at commit, LGWR writes the redo (including the commit record) from the log buffer to the online redo log and the commit returns. Modified data blocks are written to datafiles later by DBWn. After a crash, SMON replays redo to recover committed changes and uses undo to roll back uncommitted ones.