Oracle 11g的内存管理模式:AMM Automatic Memory Management
Oracle 10g的内存管理模式:ASMM Automatic Shared Memory Management
********************************************************************
SGA:System Global Area(系统全局区)
1.database buffer cache
2.redo log buffer
3.shared pool
4.java pool
5.large pool
6.stream pool
7.fixed sga
***********************
数据库启动,能够查看的sga的信息:
SYS@orcl11g> startup;
ORACLE instance started.
Total System Global Area 422670336 bytes
Fixed Size 1345380 bytes
Variable Size 318769308 bytes
Database Buffers 96468992 bytes
Redo Buffers 6086656 bytes
Database mounted.
Database opened.
SYS@orcl11g>
1.Database Buffer Cache
数据库缓冲区
The database buffer cache, also called the buffer cache, is the memory area that stores
copies of data blocks read from data files。
数据库缓冲区存储来自数据库文件的数据块的副本;
buffer:数据库缓冲区中内存块的大小,和数据库数据文件的块的大小完全一致;
数据库缓冲区存在的目的:
优化物理 I/O
能够缓存经常被访问的数据块,提高数据处理的效率
Buffer States:
unused: 未被使用的
Clean: 干净的(说明buffer里面的数据信息和数据文件对应的数据块的存储内容是一致的);
dirty: 脏块(说明buffer里面的数据信息和数据文件对应的数据块的存储内容不一致);
每个buffer的访问模式:
Every buffer has an access mode: pinned or free (unpinned)
pinned:就是这个buffer正在被读或者写;
free:空闲状态
Buffer Modes:
Current mode:当前模式。(update)
A current mode get, also called a db block get, is a retrieval of a block as it currently appears in the buffer cache
Consistent mode:一致性模式。(read)
A consistent read get is a retrieval of a read-consistent version of a block. This
retrieval may use undo data.
buffer pool的分类:
default:默认的buffer pool;如果没有做任何特殊配置,那么数据块默认被cacahe到default buffer pool;
This pool is the location where blocks are normally cached。
Keep pool:将一些频繁被访问的表,固定在数据库缓冲当中,不会因为缓冲区不足,而被置换出内存;
Recycle pool:缓存某些不被经常访问的表,被cache,access之后,马上置换出内存;
nK:非标准块的缓冲区大小;
SYS@orcl11g> show parameter block_size
NAME TYPE VALUE
------------------------------------ ----------- -------
db_block_size integer 8192
目的:保证数据文件的数据块的大小要和buffer的大小保持一致;
2.Redo Log Buffer
重做日志文件缓冲区
The redo log buffer is a circular buffer in the SGA that stores redo entries describing
changes made to the database。
redo log buffer是SGA当中的一个循环使用的buffer,存放描述数据块变化的redo entries;
Redo entries contain the information necessary to
reconstruct, or redo, changes made to the database by DML or DDL operations.
redo entries:包含用于重建,重做dml或者ddl语句,所造成的数据库的变化的信息;
redo log buffer的参数:
SYS@orcl11g> show parameter log_buffer
NAME TYPE VALUE
------------------------------------ ----------- --------
log_buffer integer 5890048
3.Shared Pool
共享池
The shared pool caches various types of program data.
For example, the shared pool stores parsed SQL, PL/SQL code,
system parameters, and data dictionary information.
Library Cache:
The library cache is a shared pool memory structure
that stores executable SQL and PL/SQL code.
库缓存,缓存了可执行的sql和pl/sql代码;
数据库趋向于使用已经解析过,存放在库缓存中的sql 代码,如果能够重用这个库缓存中的sql code,
这个行为称之为soft parse(软解析);反之,不能重用library cache中的sql code,那么,称之为
hard parse(硬解析);
解析:
sql语句的执行过程,来描述解析的概念:
1.查看sql的语法,语义部分;
select employee_id,salary from hr.employees;
2.会将这个sql做hash运算,变成一段hash代码
3.会用这个hash值,去shared pool里面的library cache找,
看看这个hash是否存在;
如果存在,说明这条语句被执行过,直接重用这个执行代码就好了;
如果不存在,需要解析这条语句:
oracle server需要根据这条语句的具体相关信息,
找出一个最优化的执行计划;
Data Dictionary Cache:
The data dictionary is a collection of database tables and views containing reference
information about the database, its structures, and its users.
This cache holds information about database objects. The cache is also known as
the row cache because it holds data as rows instead of buffers.
Server Result Cache:服务器结果缓存
the server result cache holds result sets;
Reserved Pool:shared pool的里面的保留pool
The reserved pool is a memory area in the shared pool that Oracle Database
can use to allocate large contiguous chunks of memory.
4.Large Pool
大池
The large pool is an optional memory area intended for memory allocations
that are larger than is appropriate for the shared pool
应用场景:
UGA
并行执行的sql
rman的slaves
5.Java Pool
The Java pool is an area of memory that stores all session-specific Java code
and data within the Java Virtual Machine (JVM).
6.Streams Pool
流池
The Streams pool stores buffered queue messages and provides memory for Oracle
Streams capture processes and apply processes
7.fixed sga
The fixed SGA is an internal housekeeping area。
General information about the state of the database and the instance,
which the background processes need to access;
Information communicated between processes, such as information about locks;
***************************************************************************************
PGA: Program Global Area
The PGA is a memory heap that contains session-dependent variables required by a
dedicated or shared server process
pga包含的内容:
Private SQL Area:
A private SQL area holds information about a parsed SQL statement and other
session-specific information for processing
SQL Work Areas:
sql工作区
Sort Area:order by会在这个区域进行
Hash Area:多表连接的时候,hash连接做hash运算
Bitmap Merge Area:位图合并区域
UGA: User Global Area
The UGA is session memory, which is memory allocated for session variables, such as
logon information, and other information required by a database session;
如果是dedicated server,那么,uga和pga在一起;
如果是shared server,那么UGA,会在shared pool当中;
而且如果配置了large pool,那么UGA,会在large pool当中;