阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Oracle 12C 新特性:限制PGA使用内存的大小

122次阅读
没有评论

共计 3865 个字符,预计需要花费 10 分钟才能阅读完成。

我们都知道,在 12C 之前,对于 PGA 内存的管理是使用 PGA_AGGREGATE_TARGET 参数来控制的,但这个参数也只是一个参考值,Oracle 实例只是尽量保证总的 PGA 使用量在这个值范围内,当会话使用的 PGA 内存超过这个限制时,Oracle 也不能做出什么强制措施来限制使用内存的大小。
12.1.0.1 版本中引入了新特性:使用 PGA_AGGREGATE_LIMIT 参数来限制 Oracle 实例 PGA 使用内存的上限。后台进程 ckpt 每三秒检查一次 PGA 使用的内存总量,如果超过限制就采取终止会话的方式来降低 PGA 内存的使用量,对于 SYS 用户进程和后台进程不包括 job 队列不会被终止掉。有了这个限制,不会造成 PGA 内存疯涨,导致内存耗尽。
官方文档:http://docs.oracle.com/database/121/TGDBA/tune_pga.htm#TGDBA95344
默认地 PGA_AGGREGATE_LIMIT 参数为 2G 或 200% 的 PGA_AGGREGATE_TARGET 值或 PROCESSES 参数值 *3M
测试数据库版本 12.1.0.2

SQL> select * from v$version;
 
BANNER                                          CON_ID
——————————————————————————– ———-
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production        0
PL/SQL Release 12.1.0.2.0 – Production                            0
CORE    12.1.0.2.0  Production                                0
TNS for Linux: Version 12.1.0.2.0 – Production                          0
NLSRTL Version 12.1.0.2.0 – Production                            0

查看 PGA_AGGREGATE_LIMIT 参数值大小为 2G
SQL> show parameter pga
 
NAME                    TYPE  VALUE
———————————— ———– ——————————
pga_aggregate_limit          big integer 2G
pga_aggregate_target            big integer 250M

创建测试用户

SQL> alter session set container=pdb_orcl;
 
Session altered.
 
SQL> create user zx identified by zx;
 
User created.
 
SQL> grant dba to zx;
 
Grant succeeded.
 
SQL> conn zx/zx@pdb_orcl
Connected.

创建一个包用于演示占用 PGA
SQL> create or replace package demo_pkg
  2  as
  3          type array is table of char(2000) index by binary_integer;
  4          g_data array;
  5  end;
  6  /
 
Package created.

查看当前会话 sid 和使用 PGA 内存情况
SQL> select userenv(‘sid’) from dual;
 
USERENV(‘SID’)
————–
            22
– 当前会话 sid 为 22
SQL> select a.name, to_char(b.value, ‘999,999,999’) bytes,
  2        to_char(round(b.value/1024/1024,1), ‘99,999.9’ ) mbytes
  3    from v$statname a, v$mystat b
  4  where a.statistic# = b.statistic#
  5    and a.name like ‘%ga memory%’;
 
NAME                                                            BYTES        MBYTES
—————————————————————- ———— ———
session uga memory                                                  2,301,312      2.2
session uga memory max                                              2,424,824      2.3
session pga memory                                                  3,715,176      3.5
session pga memory max                                              3,715,176      3.5
– 当前会话使用 PGA 内存为 3.5MB

执行前面创建的包,查看 PGA 内存使用情况
– 循环执行 200000 次查看 PGA 内存使用情况
SQL> begin
  2          for i in 1 .. 200000
  3          loop
  4                  demo_pkg.g_data(i) := ‘x’;
  5          end loop;
  6  end;
  7  /
 
PL/SQL procedure successfully completed.
 
SQL> select a.name, to_char(b.value, ‘999,999,999’) bytes,
  2        to_char(round(b.value/1024/1024,1), ‘99,999.9’ ) mbytes
  3    from v$statname a, v$mystat b
  4  where a.statistic# = b.statistic#
  5    and a.name like ‘%ga memory%’;
 
NAME                                                            BYTES        MBYTES
—————————————————————- ———— ———
session uga memory                                                470,213,072    448.4
session uga memory max                                            470,213,072    448.4
session pga memory                                                471,773,288    449.9
session pga memory max                                            471,773,288    449.9
– 共使用 449MB 内存,可以算出循环执行 200000* 5 次占用的 PGA 就会超过设置的 2G
SQL> begin
  2          for i in 1 .. 1000000
  3          loop
  4                  demo_pkg.g_data(i) := ‘x’;
  5          end loop;
  6  end;
  7  /
begin
*
ERROR at line 1:
ORA-04036: PGA memory used by the instance exceeds PGA_AGGREGATE_LIMIT
– 报错 ORA-4036 超过了 PGA_AGGREGATE_LIMIT 设置的 2G

调整 PGA_AGGREGATE_LIMIT 为 4G 后再次执行报错的过程,就没有问题了
SQL> conn / as sysdba
Connected.
SQL> alter system set PGA_AGGREGATE_LIMIT=4G;
 
System altered.
 
SQL> conn zx/zx@pdb_orcl
Connected.
SQL> begin
  2          for i in 1 .. 1000000
  3          loop
  4                  demo_pkg.g_data(i) := ‘x’;
  5          end loop;
  6  end;
  7  /
 
PL/SQL procedure successfully completed.
 
SQL> show parameter pga
 
NAME                                TYPE        VALUE
———————————— ———– ——————————
pga_aggregate_limit                  big integer 4G
pga_aggregate_target                big integer 250M

取消 PGA 限制,设置 pga_aggregate_limit= 0 即可。
alter system set PGA_AGGREGATE_LIMIT=0;

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-01/139046.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计3865字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中