oracle内存结构包括两个区域:SGA和PGA.
SGA(system global area):
SGA有叫共享全局区域(shared global area)。在instance启动时被分配,用来存储数据库进程共享信息,包括数据和控制信息。主要组成包括:
– Shared Pool
– Database Buffer Cache
– Redo Log Buffer
– Other structures (for example, lock and latch management, statistical data)
还有两个可选项: Large Pool, Java Pool。
下面语句可以查看SGA的分配情况:
SQL> SHOW SGA;
Total System Global Area 36437964 bytes
Fixed Size 6543794 bytes
Variable Size 19521536 bytes
Database Buffers 16777216 bytes
Redo Buffers 73728 bytes
从9i开始,可以在不关闭instance的情况下动态调整SGA的大小,这样Database Buffer Cache, Shared Pool, 和Large Pool可以动态的调整而不需要关闭instance。
SGA的大小主要由以下几个参数决定:
SGA_MAX_SIZE:规定了SGA的最大值。
DB_CACHE_SIZE:cache标准的块大小,默认Unix 48M,NT 52M。
LOGG_BUFFER:redo log buffer的大小,单位Byte。
SHARED_POOL_SIZE, LARGE_POOL_SIZE, JAVA_POOL_SIZE。
SGA有一个分配粒度称为granule,默认大小为 4 MB如果 SGA_MAX_SIZE< 128 MB,其他情况则为 16 MB 。
The minimum SGA configuration is three granules (one granule for fixed SGA
[includes redo buffers]; one granule for Database Buffer Cache; one granule for Shared Pool).
各组件介绍:
shared pool
包括library cache和data dictionary cache,分别用于存储最近执行过的编译解释后的SQL语句和最近用到的数据信息(数据字典)。
可以通过这条命令ALTER SYSTEM SET SHARED_POOL_SIZE = 64M;动态修改SHARED_POOL_SIZE的值。
Database Buffer Cache
最大的一块内存,用于缓存从数据文件里读出的数据和被更新的数据,能有效地增强数据库服务器的性能。
可以通过下面的命令动态改变它的大小:ALTER SYSTEM SET DB_CACHE_SIZE = 96M;
Buffer Cache Advisory功能,收集统计对于不同大小的Database Buffer Cache所表现出来的性能的信息,并在V$DB_CACHE_ADVICE这个视图中列出。
The Buffer Cache Advisory is enabled via the DB_CACHE_ADVICE initialization
parameter. It is a dynamic parameter, and can be altered using ALTER SYSTEM. Three values (OFF, ON, READY) are available.
DB_CACHE_ADVICE Parameter Values
OFF: Advisory is turned off and the memory for the advisory is not allocated.
ON: Advisory is turned on and both cpu and memory overhead is incurred.
Attempting to set the parameter to the ON state when it is in the OFF state may lead to the following error: ORA-4031 Inability to allocate from the Shared Pool when the parameter is switched to ON. If the parameter is in a READY state it can be set to ON without error because the memory is already allocated.
READY: Advisory is turned off but the memory for the advisory remains allocated. Allocating the memory before the advisory is actually turned on will avoid the risk of ORA-4031. If the parameter is switched to this state from OFF, it is possible that an ORA-4031 will be raised.
Redo Log Buffer
记录所有的数据库数据块的改变记录,主要目的用于恢复。
每条记录被称为重做条目,重做条目包含恢复信息或改变信息(information to econstruct or redo changes)。
Large Pool
可选项,缓解shared pool的负担,用于
– Session memory (UGA) for the Shared Server
– I/O server processes
– Backup and restore operations or RMAN(Recovery Manager)
– Parallel execution(并行处理) message buffers
PARALLEL_AUTOMATIC_TUNING set to TRUE
Java Pool
对Java的支持,如解释执行Java编写的存储过程。
Program Global Area(PGA)
PGA是一块内存区域,包含了单个server process或单个background process信息的数据和控制信息。当进程开始运行时PGA被分配,当进程结束时PGA被回收。与共享方式的SGA相对比,PGA是一个进程一块内存。注意:oracle的server process和background process是严格区分的。