签到成功

知道了

CNDBA社区CNDBA社区

Orcle 12c 新特性---PGA Size Limit

2017-08-02 15:27 3639 0 原创 Oracle 12C
作者: Expect-乐

说明

This feature limits the total amount of Program Global Area (PGA) that an instance can allocate, using a parameter called PGA_AGGREGATE_LIMIT. When the instance has allocated the PGA_AGGREGATE_LIMIT amount of PGA, sessions with the highest amount of allocated PGA are stopped until the limit is complied with.

该特性是为了限制一个实例可以使用的总PGA大小。通过参数PGA_AGGREGATE_LIMIT控制可使用的PGA大小,当实例已经使用了PGA_AGGREGATE_LIMIT所设置的PGA大小,那么Oracle会停止使用最多PGA的会话,直到有更多的空闲PGA

This feature is important for consolidation because, without a hard limit, the instance can become unstable due to excessive paging. Excessive paging is one of the leading causes of instance eviction in an Oracle RAC database and can cause a multitude of performance and stability problems.

这个特性对于整体稳定很重要,因为如果没有硬限制,实例就会因为过度分页而变得不稳定。在Oracle RAC数据库中,过度分页是导致实例被驱逐的主要原因之一,并可能导致很多的性能和稳定性问题。

在自动PGA内存管理模式,Oracle尝试通过动态给PGA_AGGREGATE_TARGET赋值,来限制PGA使用大小。但是由于下面两个原因,还是可能会超过PGA_AGGREGATE_TARGET限制的大小:

The PGA_AGGREGATE_TARGET setting acts as a target, and not a limit. 

PGA_AGGREGATE_TARGET only controls allocations of tunable memory.  --只控制可调的内存

如果使用的PGA超过PGA_AGGREGATE_LIMIT限制的大小,那么Oracle会按以下顺序中止或终止使用不可调整PGA内存最多的会话或进程:

Calls for sessions that are consuming the most untunable PGA memory are aborted.

If PGA memory usage is still over the PGA_AGGREGATE_LIMIT, then the sessions and processes that are consuming the most untunable PGA memory are terminated.http://www.cndba.cn/Expect-le/article/2040http://www.cndba.cn/Expect-le/article/2040

注意:在处理会话,进程时候,Oracle会把并行执行的查询作为一个单元处理。

1.1   PGA_AGGREGATE_LIMIT建议大小

默认情况,PGA_AGGREGATE_LIMIT设置大于2GB,是PGA_AGGREGATE_TARGET的两倍大小,或者是PROCESSES参数大小的3MB倍大小。但是不能超过实际物理内存减去SGA后的120%大小。http://www.cndba.cn/Expect-le/article/2040

1.2   设置PGA_AGGREGATE_LIMIT

PGA_AGGREGATE_LIMIT是可以动态修改的,不需要重启数据库。自动内存管理时,也可以设置该参数。

语法:

http://www.cndba.cn/Expect-le/article/2040

alter system set PGA_AGGREGATE_LIMIT=3G;

注意:这里是区分PDB的,该参数可以再PDB级别进行设置。默认情况,PDB继承CDB的大小。

实验

2.1   查看当前值(CDB)

SQL> show parameter pga


NAME	     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_limit	     big integer 3264M
pga_aggregate_target	     big integer 0

--改小点,方便实验,cndba_pdb的大小http://www.cndba.cn/Expect-le/article/2040

SQL> alter system set PGA_AGGREGATE_LIMIT=10M;

alter system set PGA_AGGREGATE_LIMIT=10M

*

ERROR at line 1:

ORA-02097: parameter cannot be modified because specified value is invalid

ORA-00093: pga_aggregate_limit must be between 256M and 100000G

可以看到大小必须是: 256M and 100000G


SQL> alter system set PGA_AGGREGATE_LIMIT=256M;

System altered.

 

SQL> show parameter pga

NAME	     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_limit	     big integer 256M
pga_aggregate_target	     big integer 0
SQL>

http://www.cndba.cn/Expect-le/article/2040

2.2   创建实验例子

--创建一个包

create or replace package demo_pkg
 as
         type array is table of char(2000) index by binary_integer;
         g_data array;
 end;
 /

--循环执行该包

begin
        for i in 1 .. 200000
        loop
                demo_pkg.g_data(i) := 'x';
        end loop;
end;
/

--查看当前用户使用的PGA使用大小

http://www.cndba.cn/Expect-le/article/2040

SQL> select a.name, to_char(b.value, '999,999,999') bytes,

        to_char(round(b.value/1024/1024,1), '99,999.9' ) mbytes

    from v$statname a, v$mystat b

  where a.statistic# = b.statistic#

    and a.name like '%ga memory%';   2    3    4    5  


NAME	       BYTES	    MBYTES
------------------------------ ------------ ---------
session uga memory	472,303,088	450.4

session uga memory max	472,303,088	450.4

session pga memory	475,612,696	453.6

session pga memory max	475,612,696	453.6

http://www.cndba.cn/Expect-le/article/2040http://www.cndba.cn/Expect-le/article/2040

可以看到,已经超过256M大小了,但是还是没有报错。PDB级别的pga_aggregate_limit大小是256MCDB级别是3256M

--把循环次数增加8倍,就会超过3256M

SQL> begin

        for i in 1 .. 1600000

        loop

                demo_pkg.g_data(i) := 'x';

        end loop;

end;

/

  2    3    4    5    6    7  

begin

*

ERROR at line 1:

ORA-00028: your session has been killed 

 --可以看到已经被Oracle干掉了。

查看告警日志:

Process m000 died, see its trace file

2017-08-02T15:18:14.492622+08:00

PGA memory used by the instance exceeds PGA_AGGREGATE_LIMIT of 3264 MB

KILL SESSION for sid=(65, 36910):

  Reason = pga_aggregate_limit

  Mode = KILL HARD SAFE -/-/-

  Requestor = DBRM (orapid = 14, ospid = 2808, inst = 1)

  Owner = Process: USER (orapid = 25, ospid = 9482)

  Result = ORA-31

2017-08-02T15:18:21.360285+08:00

可以很清楚的看到,为了保护资源的合理使用,和数据库的稳定性,该会话被Oracle kill了。

总结

1.  PGA_AGGREGATE_LIMIT大小只有在CDB级别设置才生效,PDB级别设置无效。

2.  如果会话查过PGA_AGGREGATE_LIMIT大小就会被Oracle Kill

3.  PGA_AGGREGATE_LIMIT支持动态修改http://www.cndba.cn/Expect-le/article/2040

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

PGA_AGGREGATE_LIMIT

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
Expect-乐

Expect-乐

关注

Without the continuous bitter cold, there can be no fragrant plum blossom

  • 336
    原创
  • 6
    翻译
  • 100
    转载
  • 41
    评论
  • 访问:1570997次
  • 积分:1957
  • 等级:核心会员
  • 排名:第4名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ