The basic memory structures associated with Oracle Database include:
The below figure illustrates the relationships among these memory structures:
Memory management has evolved with each database release:
Automatic Memory Management keeps the same behaviour as in 11g.
The most important SGA components are the following:
| Component | Description | Parameter |
|---|---|---|
| Database Buffer Cache | The database buffer cache is the portion of the SGA that holds copies of data blocks read from datafiles. All users concurrently connected to the instance share access to the database buffer cache. |
DB_CACHE_SIZE DB_KEEP_CACHE_SIZE DB_RECYCLE_CACHE_SIZE DB_nK_CACHE_SIZE |
| Redo Log Buffer | The redo log buffer is a circular buffer in the SGA that holds information about changes made to the database. This information is stored in redo entries. Redo entries contain the information necessary to reconstruct, or redo, changes made to the database by INSERT, UPDATE, DELETE, CREATE, ALTER, or DROP operations. Redo entries are used for database recovery, if necessary. | LOG_BUFFER |
| Shared Pool | The shared pool portion of the SGA contains the library cache, the dictionary cache, the result cache, buffers for parallel execution messages, and control structures. |
SHARED_POOL_SIZE SHARED_POOL_RESERVED_SIZE RESULT_CACHE_MAX_SIZE * |
| Large Pool | Used for allocating session memory for shared server, Oracle XA, or parallel query buffers or for RMAN. | LARGE_POOL_SIZE |
| Java Pool | Java pool memory is used in server memory for all session-specific Java code and data within the JVM. | JAVA_POOL_SIZE |
| Streams Pool | The streams pool is used exclusively by Oracle Streams. The Streams pool stores buffered queue messages, and it provides memory for Oracle Streams capture processes and apply processes. | STREAMS_POOL_SIZE |
Oracle Database 11g supports various memory management methods, which are chosen by initialization parameter settings. Oracle recommends that you enable the automatic memory management method.
Beginning with Oracle Database 11g, Oracle Database can manage the SGA memory and instance PGA memory completely automatically. You designate only the total memory size to be used by the instance, and Oracle Database dynamically exchanges memory between the SGA and the instance PGA as needed to meet processing demands. This capability is referred to as automatic memory management. With this memory management method, the database also dynamically tunes the sizes of the individual SGA components and the sizes of the individual PGAs.
To achieve this, two new parameters have been introduced named MEMORY_MAX_TARGET and MEMORY_TARGET. To do so (on most platforms), you set only a target memory size initialization parameter (MEMORY_TARGET) and optionally a maximum memory size initialization parameter (MEMORY_MAX_TARGET).
The preceding steps instruct you to set SGA_TARGET and PGA_AGGREGATE_TARGET to zero so that the sizes of the SGA and instance PGA are tuned up and down as required, without restrictions. You can omit the statements that set these parameter values to zero and leave either or both of the values as positive numbers. In this case, the values act as minimum values for the sizes of the SGA or instance PGA.
The dynamic performance view V$MEMORY_DYNAMIC_COMPONENTS shows the current sizes of all dynamically tuned memory components, including the total sizes of the SGA and instance PGA. The view V$MEMORY_TARGET_ADVICE provides tuning advice for the MEMORY_TARGET initialization parameter:
You can also use V$MEMORY_RESIZE_OPS which has a circular history buffer of the last 800 memory resize requests.
If MEMORY_TARGET is set to a non-zero value:
If MEMORY_MAX_TARGET has not been explicitly set, but MEMORY_TARGET has, the instance automatically sets MEMORY_MAX_TARGET to the same value as MEMORY_TARGET. If MEMORY_TARGET has not been explicitly set, but MEMORY_MAX_TARGET has, then MEMORY_TARGET defaults to 0. After instance startup, it then is possible to dynamically change MEMORY_TARGET to a non-zero value, provided that it does not exceed the value of MEMORY_MAX_TARGET.
If MEMORY_TARGET is not set or set to set to 0 explicitly (default value is 0 for 11g):
If you want to exercise more direct control over the size of the SGA, you can disable automatic memory management and enable automatic shared memory management. This feature was introduced in 10g with a parameter known as SGA_TARGET. When automatic SGA memory management is enabled, the sizes of the different SGA components are flexible and can adapt to the needs of current workload without requiring any additional configuration.
Please refer to following document for setting SGA_TARGET:
Document 295626.1 - How To Use Automatic Shared Memory Management (ASMM) In Oracle10g & 11g
In case you have enabled Automatic Memory Management and wish to switch to Automatic Shared Memory Management, then follow the below procedure:
If you want complete control of individual SGA component sizes, you can disable both automatic memory management and automatic shared memory management. In this mode, you need to set the sizes of several individual SGA components, thereby determining the overall SGA size. You then manually tune these individual SGA components on an ongoing basis.
In this case you set SGA_TARGET and MEMORY_TARGET to 0 and set value for other SGA components upto the total value of SGA_MAX_SIZE.
Please refer to Document 148495.1 - Dynamic SGA.
Please note that SGA re-sizes can occur after upgrade to 11.2 despite the fact that automatic memory management
(AMM/ASMM) is disabled via the MEMORY_TARGET and SGA_TARGET parameters being set to zero. This typically appears as
growth in the __SHARED_POOL_SIZE value and a reduction in the __DB_CACHE_SIZE value being used in the instance, such that
__DB_CACHE_SIZE may be shrunk below the DB_CACHE_SIZE value specified in the init.ora/spfile.
This is expected behavior in 11.2 for immediate memory allocation requests, which added this as a new feature when
automatic memory management was disabled.
You can set the parameter _MEMORY_IMM_MODE_WITHOUT_AUTOSGA=false in the instance to disable this feature with the
consequence that in future an ORA-4031 error would be raised, e.g.:
connect / as sysdba
alter system set "_memory_imm_mode_without_autosga"=FALSE scope=both;
exit
Parameter: _MEMORY_IMM_MODE_WITHOUT_AUTOSGA
Default value: 0 (SGA autotuning is disabled for DEFERRED mode autotuning requests, but allowed for IMMEDIATE mode autotuning requests)
While using Automatic memory management, PGA memory is allocated based upon the value of MEMORY_TARGET. In case you enable automatic shared memory management or manual shared memory management, you also implicitly enable automatic PGA memory management. For more information, see Document 1392549.1 - SGA and PGA Management in 11g's Automatic Memory Management (AMM).
With automatic PGA memory management, you set a target size for the instance PGA by defining value for parameter named PGA_AGGREGATE_TARGET and sizing of SQL work areas is automatic and all *_AREA_SIZE initialization parameters are ignored for these sessions. This feature is available from 9i.
At any given time, the total amount of PGA memory available to active work areas on the instance is automatically derived from the parameter PGA_AGGREGATE_TARGET. This amount is set to the value of PGA_AGGREGATE_TARGET minus the PGA memory allocated for other purposes (for example, session memory). The resulting PGA memory is then allotted to individual active work areas based on their specific memory requirements.
Please refer to following document for more details on Automatic PGA Memory Management:
Document 223730.1 - Automatic PGA Memory Management
In case you wish to manually specify the maximum work area size for each type of SQL operator (such as sort or hash-join) then you can enable Manual PGA Memory management.
Set WORKAREA_SIZE_POLICY value to MANUAL and also specify values for *_AREA_SIZE such as SORT_AREA_SIZE, HASH_AREA_SIZE, BITMAP_MERGE_AREA_SIZE, and CREATE_BITMAP_AREA_SIZE, etc.
Although the Oracle Database 11g supports this manual PGA memory management method, Oracle strongly recommends that you leave automatic PGA memory management enabled.
The table below summarizes the various memory management methods:
| Memory Management Mode | For | You Set | Oracle Database Automatically Tunes |
|---|---|---|---|
| Automatic memory management (AMM) | SGA and PGA |
|
|
|
Automatic shared memory management (ASMM) (AMM disabled) |
SGA |
|
SGA component sizes |
|
Manual shared memory management (AMM and ASMM disabled) |
SGA |
|
None |
| Automatic PGA memory management | PGA | Instance PGA target size (PGA_AGGREGATE_TARGET) | Individual PGA sizes |
|
Manual PGA memory management (Not recommended) |
PGA | Maximum work area size for each type of SQL operator | None |
The Automatic Memory Management (AMM) feature uses the Memory Manager (MMAN) background process. This process was introduced in 10g which assisted in Automatic Shared Memory Management (ASMM) using SGA_TARGET. MMAN serves as the SGA Memory Broker and coordinates the sizing of the memory components. The SGA Memory Broker keeps track of the sizes of the components and pending resize operations.
Configuring AMM or ASMM on Solaris OS will cause the OS to use a feature called Dynamic Intimate Shared Memory (DISM). This allows for shared memory segments to be dynamically resizable. Oracle uses DISM for its dynamic System Global Area (SGA) capability when AMM or ASMM is configured. With Oracle 9i and higher, if SGA_MAX_SIZE > SGA_TARGET (or sum of sga compenents), then DISM is used. On 11g, DISM is also used if MEMORY_TARGET or MEMORY_MAX_TARGET is set. Otherwise, ISM is used if DISM is not enabled.
DISM (unlike ISM), requires a swap reservation for all pages, whether or not they're allocated. This basically means you will need to configure at least as much swap space as the SGA size for instances that are using DISM. Otherwise, memory errors could occur when trying to run the instance with inadequate swap space.
To determine if DISM is being used for an Oracle instance, you can look on the OS side with ps utility:
If DISM is being used it will show as a process in format ora_dism_$ORACLE_SID.
The only way to avoid the use of DISM and the swap space requirement would be to use manual memory management.
The realfree allocator will be used when PGA_AGGREGATE_TARGET > 0.
On Linux systems, a process can reach a 4G limit due to default settings and error with ORA-4030. These errors show up because running out of map entries. By default there are only 65536 memory map entries per process.
Although not necessary to diagnose, an OS trace using strace/truss of Oracle process may show using mmap() instead of malloc() for memory allocation.
There are two ways to allow the process to access more memory than 4G:
No quantitative data available regarding performance for either setting. May want to test both settings to determine if either provides better performance.
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/20747382/viewspace-2135893/ ,如需转载,请注明出处,否则将追究法律责任。