欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ORACLE ASMM与AMM的总结

程序员文章站 2022-07-02 16:10:11
概念对比介绍 相信有些人会对ORACLE当中的AMM(Automatic Memory Management)与ASMM(Automatic Shared Memory Management)有些迷惑或混淆,不清楚两者的异同,本文会从几个方面来总结一下两者的异同。如有不足或疏漏之处,敬请指正! 从O... ......

 

概念对比介绍

 

相信有些人会对ORACLE当中的AMM(Automatic Memory Management)与ASMM(Automatic Shared Memory Management)有些迷惑或混淆,不清楚两者的异同,本文会从几个方面来总结一下两者的异同。如有不足或疏漏之处,敬请指正!

 

从ORACLE发布的版本历史(时间轴)来看,ORACLE的内存管理的大致历程如下:

 

ORACLE  9i       PGA自动管理,SGA手动管理

ORACLE 10g      PGA自动管理,SGA自动管理(ASMM,自动共享内存管理)

ORACLE 11g      PGA,SGA统一自动管理(AMM,自动内存管理)

ORACLE 12c      跟11g一样,没有变化

 

 

官方文档的介绍资料如下:

 

·         Oracle 9i

 

·         Beginning with Oracle9i, the dynamic SGA infrastructure allowed for the sizing of the Buffer Cache, Shared Pool and the Large Pool without having to shut down the database. Key features being:

o   Dynamic Memory resizing

o   DB_CACHE_SIZE instead of DB_BLOCK_BUFFERS

o   DB_nK_CACHE_SIZE for multiple block sizes

o   PGA_AGGREGATE_TARGET Introduction of Automatic PGA Memory management

 

·         Oracle Database 10g

 

·         Automatic Shared Memory Management (ASMM) was introduced in 10g. You enable the automatic shared memory management feature by setting the SGA_TARGET parameter to a non-zero value.

 

·         Oracle Database 11g

 

·         Automatic Memory Management is being introduced in 11g. This enables automatic tuning of PGA and SGA with use of two new parameters named MEMORY_MAX_TARGET and MEMORY_TARGET

·         Oracle Database 12c

            Automatic Memory Management keeps the same behaviour as in 11g.

 

 

自动共享内存管理(Automatic Shared Memory Management ASMM)是ORACLE 10g开始引入的的新技术,ASMM用来实现SGA的自动管理。。当启用自动共享内存管理后,不再需要为每个内存组件设定值,当然如果你设置SGA_TARGET的同时,设置了db_cache_size、shared_pool_size这些参数,那么db_cache_size、shared_pool_size这些参数值会作为最小值要求。官方关于Automatic Shared Memory Management的介绍如下:

 

Automatic Shared Memory Management

 

In previous database releases, a database administrator (DBA) was required to manually specify different SGA component sizes by setting a number of initialization parameters, including the SHARED_POOL_SIZE, DB_CACHE_SIZE, JAVA_POOL_SIZE, and LARGE_POOL_SIZE parameters. Oracle Database 10g includes the Automatic Shared Memory Management feature which simplifies the SGA memory management significantly. In Oracle Database 10g, a DBA can simply specify the total amount of SGA memory available to an instance using the SGA_TARGET initialization parameter and the Oracle Database will automatically distribute this memory among various subcomponents to ensure most effective memory utilization.

 

When automatic SGA memory management is enabled, the sizes of the different SGA components are flexible and can adapt to the needs of a workload without requiring any additional configuration. The database automatically distributes the available memory among the various components as required, allowing the system to maximize the use of all available SGA memory.

 

ORACLE 10G版本开始推出了ASMM,自动SGA管理,它的出现一定程度上帮助DBA解决了管理SGA的问题,通过设置参数SGA_TARGET来控制ASMM,其中SGA_TARGET为零表示禁用ASMM,非零值表示启用ASMM。但是在10G R1等早期版本,ASMM还不够成熟,而且存在比较多的BUG,导致了比较多的问题。在ORACLE 10g R2后续版本中,ASMM才逐渐完善并成熟。

 

到了11g之后,ORACLE又实现了PGA和SGA的统一自动管理 ,这个称之为自动化内存管理(Automatic Memory Management,AMM)。从这些演化历程来看,ORACLE从最开始的手动配置各个组件参数,慢慢逐渐向智能化、傻瓜化、自动化的方向稳步前进。这个是一个必然的历史趋势。关于AMM的官方文档介绍如下:

 

About Automatic Memory Management

 

The simplest way to manage instance memory is to allow the Oracle Database instance to automatically manage and tune it for you. 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 instance then tunes to the target memory size, redistributing memory as needed between the system global area (SGA) and the instance program global area (instance PGA). Because the target memory initialization parameter is dynamic, you can change the target memory size at any time without restarting the database. The maximum memory size serves as an upper limit so that you cannot accidentally set the target memory size too high, and so that enough memory is set aside for the Oracle Database instance in case you do want to increase total instance memory in the future. Because certain SGA components either cannot easily shrink or must remain at a minimum size, the instance also prevents you from setting the target memory size too low.

 

If you create your database with Database Configuration Assistant (DBCA) and choose the basic installation option, automatic memory management is enabled. If you choose advanced installation, Database Configuration Assistant (DBCA) enables you to select automatic memory management.

 

 

 

ORACLE 11g AMM 的引入, 组合出来有 5 种内存管理形式.

 

    自动内存管理(AMM)   : memory_target=非0,是自动内存管理,如果初始化参数 LOCK_SGA=TRUE,则 AMM 是不可用的。

    自动共享内存管理(ASMM): 在memory_target=0 and sga_target为非0的情形下是自动内存管理

    手工共享内存管理      : memory_target=0 and sga_target=0  指定 share_pool_size 、db_cache_size 等 sga 参数

    自动 PGA 管理         : memory_target=0 and workarea_size_policy=auto  and PGA_AGGREGATE_TARGET=值

    手动 PGA 管理         : memory_target=0 and workarea_size_policy=manal  然后指定 SORT_AREA_SIZE 等 PGA 参数,一般不使用手动管理PGA。

 

 

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.

 

 

Automatic Memory Management – For Both the SGA and Instance PGA Automatic Shared Memory Management – For the SGA Manual Shared Memory Management – For the SGA Automatic PGA Memory Management –For the Instance PGA Manual PGA Memory Management – For the Instance PGA

 

 

 

 

 

ASMM切换到AMM

 

如下所示,当前实验环境下自动内存管理已被禁用(memory_target=0)

 

SQL> select * from v$version;
 
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
 
SQL> show parameter memory_target ;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_target                        big integer 0
SQL> show parameter memory_max_target;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 0
SQL> 
SQL> show parameter sga;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
lock_sga                             boolean     FALSE
pre_page_sga                         boolean     FALSE
sga_max_size                         big integer 1G
sga_target                           big integer 1G
 

 

在11g中,如果使用ASMM,对应的内存共享段是真实的共享段。

 

SQL> !
[oracle@DB-Server ~]$ ipcs -m
 
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x00000000 4128770    root      644        80         2                       
0x00000000 4161540    root      644        16384      2                       
0x00000000 4194309    root      644        280        2                       
0xfc5d1940 7012369    oracle    660        1075838976 49     
 

 

如下所示,首先检查参数文件类型,然后修改参数sga_target、memory_max_target、memory_target。因为当中有些参数为静态参数,所以在修改参数后,需要重启数据库。

 

 

 

SQL> show parameter spfile;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.1.0
                                                 /dbhome_1/dbs/spfilegsp.ora
SQL> alter system set sga_max_size=0 scope=spfile;
 
System altered.
 
SQL> alter system set sga_target=0 scope=spfile;
 
System altered.
 
SQL> alter system set pga_aggregate_target=0 scope=spfile;
 
 
SQL> alter system set memory_max_target=1G scope=spfile;
 
System altered.
 
SQL> alter system set memory_target=1G scope=spfile;
 
System altered.
 
SQL> 
 

重启数据库后,检查对应参数。

 

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
 
Total System Global Area  517816320 bytes
Fixed Size                  2214776 bytes
Variable Size             159384712 bytes
Database Buffers          348127232 bytes
Redo Buffers                8089600 bytes
Database mounted.
SQL> show parameter memory
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
hi_shared_memory_address             integer     0
memory_max_target                    big integer 1G
memory_target                        big integer 1G
shared_memory_address                integer     0
SQL> 

 

自动内存管理(AMM)启动之后,