Oracle 11g 内存管理方式切换

357 阅读3分钟

这是我参与8月更文挑战的第21天,活动详情查看:8月更文挑战

介绍

  在 10g 时,Oracle 推出了ASMM(Automatic Shared Memory Management),实现了Oracle SGA 和 PGA 内部结构的自调节。进入 11g 之后,AMM(Automatic Memory Management)实现了参数 MEMORY_TARGET,将 SGA 和 PGA 的规划全部统筹起来对待。

  默认情况下,Oracle 11g 是使用 AMM 的。我们在安装过程中,指定 Oracle 使用内存的百分比,这个取值就作为 MEMORY_TARGET 和 MEMORY_MAX_TARGET 的初始取值使用。如果这两个参数设置为非零取值,那么 Oracle 就是采用 AMM 管理策略的。

  同时,如果我们设置这两个参数为0,则AMM自动关闭。对应的 SGA_TARGET、PGA_AGGREGATE_TARGET 参数取值非零之后,Oracle 自动退化使用 ASMM 特性。

环境

我们选择11.2.0.3进行试验,当前状态为ASMM。

SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE        11.2.0.3.0         Production

SQL> show parameter target
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
db_flashback_retention_target        integer     1440
fast_start_io_target                 integer     0
fast_start_mttr_target               integer     0
memory_max_target                    big integer 0
memory_target                        big integer 0
parallel_servers_target              integer     16
pga_aggregate_target                 big integer 108M
sga_target                           big integer 252M

当前 MEMORY_TARGET 设置为零,AMM 没有启用。

从 ASMM 切换到 AMM

--备份参数文件
SQL> create pfile='/home/oracle/pfile20210821.ora' from spfile;
File created.

--参数调整
SQL> alter system set memory_max_target=360m scope=spfile;
System altered
SQL> alter system set memory_target=360m scope=spfile;
System altered
SQL> alter system set sga_target=0m scope=spfile;
System altered
SQL> alter system set sga_max_size=0 scope=spfile;
System altered
SQL> alter system set pga_aggregate_target=0 scope=spfile;
System altered

--重启数据库生效参数
SQL> conn / as sysdba
Connected.
SQL> startup force
ORACLE instance started.
 
Total System Global Area  263651328 bytes
Fixed Size                  1344284 bytes
Variable Size             176164068 bytes
Database Buffers           83886080 bytes
Redo Buffers                2256896 bytes
Database mounted.
Database opened.
 
SQL> show parameter target
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
db_flashback_retention_target        integer     1440
fast_start_io_target                 integer     0
fast_start_mttr_target               integer     0
memory_max_target                    big integer 360M
memory_target                        big integer 360M
parallel_servers_target              integer     16
pga_aggregate_target                 big integer 0
sga_target                           big integer 0

从 AMM 切换到 ASMM

--备份参数文件
SQL> create pfile='/home/oracle/pfile20210821.ora' from spfile;
File created.

--参数调整
SQL> alter system set memory_max_target=0 scope=spfile;
System altered
SQL> alter system set memory_target=0 scope=spfile;
System altered
SQL> alter system set pga_aggregate_target=100m scope=spfile;
System altered
SQL> alter system set sga_target=260m scope=spfile;
System altered
SQL> alter system set sga_max_size=260m scope=spfile;
System altered

--修改 pfile 文件,并以修改后的文件启动数据库
(这一步骤的原因为 MEMORY_MAX_TARGET 被“显示”的赋值,与 SGA_TARGET 赋值相冲突,启动数据库会报错。)
SQL> create pfile from spfile;
File created.

修改前
*.db_recovery_file_dest='/u01/app/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/u01/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11gXDB)'
*.log_checkpoints_to_alert=TRUE
*.memory_max_target=0
*.memory_target=0
*.open_cursors=300
*.pga_aggregate_target=104857600
*.processes=150
 
修改后(去掉了 memory_max_target、memory_target 参数)
*.db_recovery_file_dest='/u01/app/fast_recovery_area'
*.db_recovery_file_dest_size=10737418240
*.diagnostic_dest='/u01/app'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora11gXDB)'
*.log_checkpoints_to_alert=TRUE
*.open_cursors=300
*.pga_aggregate_target=104857600
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'

使用pfile启动数据库,并重建spfile。
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup pfile=/u01/app/oracle/dbs/initora11g.ora
ORACLE instance started.
Total System Global Area  272011264 bytes
Fixed Size                  1344372 bytes
Variable Size             176163980 bytes
Database Buffers           88080384 bytes
Redo Buffers                6422528 bytes
Database mounted.
Database opened.

SQL> show parameter target
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
archive_lag_target                   integer     0
db_flashback_retention_target        integer     1440
fast_start_io_target                 integer     0
fast_start_mttr_target               integer     0
memory_max_target                    big integer 0
memory_target                        big integer 0
parallel_servers_target              integer     16
pga_aggregate_target                 big integer 100M
sga_target                           big integer 260M

--重建 spfile,正常启动数据库。
SQL> create spfile from pfile;
File created.
SQL> startup force
ORACLE instance started.
Total System Global Area  272011264 bytes
Fixed Size                  1344372 bytes
Variable Size             176163980 bytes
Database Buffers           88080384 bytes
Redo Buffers                6422528 bytes
Database mounted.
Database opened.