Sitemap

🪟Oracle Database Architecture

13 min readNov 26, 2022

--

Press enter or click to view image in full size

Oracle Database Server Architecture:

1️⃣Memory Structures: PGA and SGA

2️⃣Oracle Process Architecture:

3️⃣Database Storage Structure:

A basic Oracle Database System consists of an Oracle Database and a Database Instance. We use database & instaance words interchangle.

✔️Database is a collection of files.

✔️Instance is a collection of memory structure & background processes.

🎯Program Global Area(PGA):

It is a memory region that contains data and control information for each server process. An Oracle server process services a client’s requests. Each server process has its own private PGA that is allocated when the server process is started. Access to the PGA is exclusive to that server process, and the PGA is read and written only by the Oracle code acting on its behalf. The PGA is divided into two major areas: stack space and the user global area (UGA).
With the dynamic SGA infrastructure, the sizes of the database buffer cache, the shared pool, the large pool, the Java pool, and the Streams pool can change without shutting down the instance.
The Oracle Database server uses initialization parameters to create and manage memory structures. The simplest way to manage memory is to allow the database to automatically manage and tune it for you. To do so (on most platforms), you only have to set a target memory size initialization parameter (MEMORY_TARGET) and a maximum memory size initialization parameter (MEMORY_MAX_TARGET).

🎯System Global Area(SGA):

Group of shared memory structures, known as SGA components, that contain data and control information for one Oracle Database instance. The SGA is shared by all server and background processes. Examples of data stored in the SGA include cached data blocks and shared SQL areas.
The SGA includes the following data structures:

🟦Database Buffer Cache:

Holds blocks of data retrieved from the database. The buffer which caches copies of the data blocks read from the datafiles.
Database buffer is shared by all the concurrent users connected to database.
🎯Cache hit and Cache miss:
When a database user fires some SQL and the requested information is available in database buffer then it is called cache hit.
And when the requested information is not in the buffer but needs to be taken from datafile then it is called cache miss.
✔️ LRU (Least Resently Used) & MRU (Most Resently Used):
The data blocks in the buffer cache which are frequently accessed are called as the MRU blocks.
And the blocks which are not accessd are called as the LRU blocks.
When the buffer is full and a new request came from the DB user, the LRU list written to the data files to free up the buffer space. The new requested data block will come to the MRU end.
🟦Database Buffer Cache divided into two parts:
1. Least recently used (LRU)-
LRU list consists of following buffer info ..
🔵Dirty Buffer: Which holds changed data but not sent to write list.
🔵Free Buffer: blocks having no data and available to use.
🔵Pinned Buffer: buffers which are currently in use.
2. Write List :
Write list consists of modified data blocks which are not written to the disk.

✔️️To display db_block_size of DB instance
SYS@testDB> show parameter db_block_size
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
db_block_size integer 8192

✔️️Suppose you are supporting Oracle Instance testDB

SYS@testDB> show parameter db_cache_size

NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
db_cache_size big integer 208M

✔️️ In case of Oracle Hexadata Instance exaDB

SYS@exaDB> show parameter db_cache_size
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
db_cache_size big integer 10G

✔️PFB list of DB Cache and Buffer related parameters:

We can set cache size from db_2k.. to db_32k depending on application requirement.
You can check above examples for the same.

db_2k_cache_size big integer 0
db_4k_cache_size big integer 0
db_8k_cache_size big integer 0
db_16k_cache_size big integer 0
db_32k_cache_size big integer 0

db_block_size integer 8192
db_cache_advice string ON
db_block_buffers integer 0
db_block_checking string false
db_block_checksum string typical

🎯 How to change db_block_size ?

By default db_block_size is 8K. You can set standard db_block_size size from 2048 to 32768(2K to 32K) depending application requirement. Like in case datawarehousing application can be increased. This will increase application performance and reading of more data from disk.

✔️ To change a block size of existing database you need to recreate DB and change db_block_size parameter in init.ora file
and move existing tablespaces to newly created tablespaces with new block size.

✔️ When you are creating new database only need to set db_block_size parameter in init.ora file.

🟦Redo Log Buffer :

Holdes redo information (used for instance recovery) until it can be written to the physical redo log files stored on the disk. The Redo log buffer holds all changes made to the database. It records of all the DML and DDL statements fired by the user. This information will be written to a Redo logfile by background process called log writer, When user performs commit or after specific interval or When redo log buffer is 1/3 full. DML-Data Manipulation Language(DML): Insert/Delete/Update
Data Definiation Language(DDL): Create -Table/Index … Objects…
It uses the circular mechanism and group of the buffers.
The Redo log buffer plays very important role when DB instances crashes/fails(during recovery phase).
✔️To display log_buffer size of DB instance
SQL> show parameter log_buffer
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
log_buffer integer 5586944

✔️ Suppose you are supporting Oracle Instance testDB
SQL> show parameter log_buffer
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
log_buffer integer 16760832
✔️In case of Oracle Exadata Instance exaDB
SQL> show parameter log_buffer
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
log_buffer integer 134217728

✔️How to change log_buffer size
SQL> alter system set log_buffer=5242880 scope=spfile;
System altered.
✔️ Once you change log_buffer parameter fire commands shutdown immediate and startup to apply this changes.
✔️ Oracle release 10.2 and beyond, Oracle will automatically size the log_buffer on your behalf and
log_buffer cannot be changed dynamically.
✔️ Granules : It is the contiguous block of memory allocated at the time of startup.
column name format a25
column value format a25
column description format a25
select
a.ksppinm name,
b.ksppstvl value,
a.ksppdesc description
from
x$ksppi a,
x$ksppcv b
where
a.indx = b.indx
and
a.ksppinm = ‘_ksmg_granule_size’;

NAME VALUE DESCRIPTION
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —_ksmg_granule_size 67108864 granule size in bytes

✔️ To check size of all buffers/pools of SGA You can query V$SGAINFO
SQL> select NAME,round((BYTES/1024/1024),2) BYTES_MB,RESIZEABLE from V$SGAINFO;
NAME BYTES_MB RES
— — — — — — — — — — — — — — — — — — — -
Fixed SGA Size 2.13 No
Redo Buffers 162.43 No
Buffer Cache Size 11200 Yes
Shared Pool Size 8192 Yes
Large Pool Size 512 Yes
Java Pool Size 128 Yes
Streams Pool Size 192 Yes
Shared IO Pool Size 0 Yes
Granule Size 64 No
Maximum SGA Size 20388.56 No
Startup overhead in Share 935.72 No
d Pool
Free SGA Memory Available 0

12 rows selected.

✔️ To display datafile info
select name, CREATION_TIME, BYTES/1024/1024 from v$datafile;

✔️ To display redo file info
select * from V$logfile;

SQL> show parameter pga

NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — —
pga_aggregate_limit big integer 4760M
pga_aggregate_target big integer 2380M

SQL> show parameter sga

NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — —
allow_group_access_to_sga boolean FALSE
lock_sga boolean FALSE
pre_page_sga boolean TRUE
sga_max_size big integer 7152M
sga_min_size big integer 0
sga_target big integer 7152M
unified_audit_sga_queue_size integer 1048576

🟦Shared Pool:

Caches various constructs that can be shared among users. It is a part of SGA and using LRU algorithm in order to free space for new information. Similar like DB buffer.
You can set the size of the shared pool with the shared_pool_size initialzation parameter.
The default is 8,386,608 bytes(8 MB)
SQL>show parameter shared_pool_size
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
shared_pool_size big integer 224M

ASM is very popular these days. To calculate size of database which is using ASM use belwo queries.
SELECT SUM(BYTES)/(1024*1024*1024) FROM V$DATAFILE;
SELECT SUM(BYTES)/(1024*1024*1024) FROM V$LOGFILE a, V$LOG b
WHERE a.group#=b.group#;
SELECT SUM(BYTES)/(1024*1024*1024) FROM V$TEMPFILE
WHERE status=’ONLINE’;

Get Cloud Evolving Data’s stories in your inbox

Join Medium for free to get updates from this writer.

🟦 Shared pool contains following structures:
✔️1.3.1 Library Cache:
Which stores shared SQL and PL-SQL code.
Means the fully parsed or compiled representation of PL-SQL blocks and SQL statements. PL-SQL blocks includes Procedure and Function, Packages, Triggers and ananymous PL-SQL blocks and SQL Statements.
✔️1.3.2 Data Dictionary Cache:
which keeps information about dictionary objects.
It holds definitions of dictionary objects.
1.3.3 Server Result Cache
The result cache is composed of the SQL query result cache and PL/SQL function result cache, which share the same infrastructure.
The DBMS_RESULT_CACHE package provides administration subprograms, which, for example, flush all cached results and turn result-caching on or off systemwide. The dynamic performance views V$RESULT_CACHE_* allow the developer and DBA to determine, for example, the cache-hit success for a certain SQL query or PL/SQL function.
Similar to the result cache, the client result cache also caches results, except that the caching is done on the client side
✔️1.3.4 Reserved Pool:
Oracle internally reserves a small memory area in the shared pool that can be used if the shared pool does not have enough space. This reserved pool makes allocation of large chunks more efficient.
The default minimum reserved pool allocation is 4,400 bytes.
The default value for SHARED_POOL_RESERVED_SIZE is 5% of the SHARED_POOL_SIZE
The reserved pool size can be changed by setting the SHARED_POOL_RESERVED_SIZE initialization parameter
SQL> show parameter SHARED_POOL_RESERVED_SIZE
NAME TYPE VALUE
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —
shared_pool_reserved_size big integer 10905190

🟦Large Pool:

Optional area that provides large memory allocations for certain large processes, such as Oracle backup and recovery operations, and I/O server processes. Which holds information about shared server, Oracle XA, or parallel query buffers. Session memory for the shared server and the Oracle XA interface which is used where transactions interact with more than one database.
✔️ I/O server processes.
✔️ Oracle backup and restore operations.

🟦Java Pool:

Used for all session-specific Java code and data in the Java Virtual Machine (JVM). Which holds session information about Java code and data.
Java Pool Advisor statistics provide information about library cache memory used for Java.
This will used to change Java pool resizing and in turn changing parse rate.
When statistics_level is set to TYPICAL or higher Java Pool Advisor automatically turned on.

🟦Streams Pool:

Which holds Oracle Streams information like buffered queue messages, capture processes and apply processes.
By default size of stream pool is zero. When you are using streams, size will grow dynamicaly.

🟦Fixed SGA:

An internal housekeeping area containing general information about the state of the database and the instance, and information communicated between processes When you start the instance, the amount of memory allocated for the SGA is displayed. Which holds general information about the state of the database and the instance, which the background processes need to access. It also contains locking information about processes

🟦Keep Pool:

which holds oracle frequently used object pinned into memory.Ex: Table Keep pool is separate cache area. It is initialized by DB_KEEP_CACHE_SIZE
Unless and until I set the above parameter the warm/frequently accessed blocks which are not always at the MRU end of LRU list, will be wiped out from the default cache. If now I set the above parameter (DB_KEEP_CACHE_SIZE) to some value then the blocks will be wiped out from default cache and get into the keep pool where again LRU algorithm is used and the blocks stays in the keep pool for some more time.

🟦Recycle Pool:

which holds segments frequently accessed and data will be always available in buffer cache so that we can avoid physical reads.
Recycle Pool is initialized with DB_RECYCLE_CACHE_SIZE parameter.
Unless and until the above parameter is not set then the undesired blocks will hold extra blocks which we don’t want at all.

🎯Oracle Process Architecture :

The processes in an Oracle Database system can be divided into three major groups:
🔵User Processes that run the application or Oracle tool code
🔵Oracle Database Processes that run the Oracle Database server code (including server processes and background processes)
🔵Oracle Daemons & Application Processes not specific to a single database
When a user runs an application program or an Oracle tool such as SQL*Plus, the term user process is used to refer to the user’s application. The user process may or may not be on the database server machine. Oracle Database also creates a server process to execute the commands issued by the user process. In addition, the Oracle server also has a set of background processes for an instance that interact with each other and with the operating system to manage the memory structures, asynchronously perform I/O to write data to disk, and perform other required tasks. The process structure varies for different Oracle Database configurations, depending on the operating system and the choice of Oracle Database options. The code for connected users can be configured as a dedicated server or a shared server.
✔️ Dedicated Server:
For each session, the database application is run by a user process that is served by a dedicated server process that executes Oracle database server code.
✔️ Shared Server:nn
Eliminates the need for a dedicated server process for each connection. A dispatcher directs multiple incoming network session requests to a pool of shared server processes. A shared server process serves any client request.

🟦Background Processes :

The background processes of the Oracle instance manage memory structures, asynchronously perform I/O to write data to a file on a disk, and perform general maintenance tasks. An Oracle database system consists of an Oracle database and an Oracle instance. The database consists of a set of disk files that store user data and metadata, while the Oracle/database instance contains the set of Oracle Database background processes that operate on the stored data and the shared allocated memory that those processes use to do their work.

Each background process has a separate task but works with the other processes. For example, the LGWR process writes data from the redo log buffer to the online redo log. When a filled log file is ready to be archived, LGWR signals another process to archive the file. Oracle Database creates background processes automatically when a database instance starts. The background processes that are present depend on the features and options that are being used in the database. The startup and shutdown of background processes are normally seen logged in the database alert.log.

✔️ The following query can be used to list the background processes running on your database:

SQL> SELECT PNAME FROM V$PROCESS WHERE PNAME IS NOT NULL ORDER BY PNAME;

✔️ Following query could be used in 12c as all the shared BG process belongs ti con_id=0

SQL> select PNAME,con_id,spid from V$process where con_id=0;

🟦Types of Background Processes

✔️Mandatory Background Processes
✔️Optional Background Processes
✔️Slave Processes

🎯Mandatory Background Processes-

🔵Database Writer process (DBWn):

The server process records changes to undo data block & data blocks in the database buffer cache. DBWn writes the dirty buffer from the database buffer cache to the datafiles. DBWm BG Process writes when …
1) Check Point occures
2) Dirty Buffer reached threshold
3) There are no free buffers
4) Timeout occurs RAC Ping request is made
5) Tablespace offline
6) Tablespace read only
7) Tablespace Drop or Truncate
8) Tablespace Begin Backup

🔵 Log Writer process (LGWR):

The redo log buffer uses circular alogorithm while writing to redo log group. LGWR writing the redo log buffer entries to a redo log file on disk. LGWR BG Process writes when …
1) Commits a Transaction
2) Redo Log Buffer is 1/3 full
3) Before DBWn writes to disk
4) When there is 1 MB of redo
5) Every 3 seconds

🔵Checkpoint process (CKPT):

Every 3 seconds the checkpoint process write information to control file to identify that the place in the redo log file where
recovery is to begin this being called a checkpoint.

🔵System Monitor Process (SMON):

SMON performs recovery at instannce startup if required.
Clean up temporary segment which are unused.
Relase lock table

🔵Process monitor process (PMON):

PMON performs process recovery when a user process fails.
PMON is responsible for clean up the database buffer cahe and freeing resources that the user process was using.
When database expect PMON process dynamically register database with listener.
PMON periodically checks the status of dispatcher and server process & restart any that have stopped running.

🔵Recoverer process (RECO):

Resolves distributed transactions that are pending because of a network or system failure

🔵 Manageability monitor process (MMON):

Performs many tasks related to manageability, including taking Automatic.

🔵 Manageability monitor lite process (MMNL):

Performs tasks relating to manageability, including active session history sampling.

🔵Process Manager Process (PMAN):

Process Manager Process (PMAN) is a background process that monitors, spawns, and stops the Dispatcher and shared server processes, Connection broker and pooled server processes for database resident connection pools, Job queue processes, and Restartable background processes.

🔵 Listener registration process (LREG):

Registers the instance with the listeners.

🎯Optional Background Processes-

🔵 Archiver processes (ARCn):

Copies the redo log files to archival storage when they are full or an online redo log switch occurs.

🔵 Job queue coordinator (CJQ0):

Selects jobs that need to be run from the data dictionary and spawns job.

🔵 SMCO:

Coordinates the execution of various space management tasks.

🎯Slave Background Processes-

🔵 Innn: Disk and Tape I/O Slave Process.

Serves as an I/O slave process spawned on behalf of DBWR, LGWR, or an RMAN backup session.

🔵 Pnnn: Parallel Query Slave Process.

Perform parallel execution of a SQL statement (query, DML, or DDL)

🔵 Jnnn: Job Queue Slave Process

Executes jobs assigned by the job coordinator

⚫⚫⚫

--

--