首页 » ORACLE 9i-23ai » PGA 一点认识

PGA 一点认识

pga program global area 又名process global area

操作已加载到内存中的数据时所需要的工作区域,这块内存区对于每个服务器进程都是私有的,不允许其它进程或线程的访问,PGA 一般是通过C 语言在运行时调用malloc() 和memmap() 来分配的,运行时可以动态的扩大,在8i后甚至可以动态的收缩,如果使用的是专用服务器模式,PGA 中除了进程内存区还会包含UGA(MTS时UGA是在SGA中)

专用服务器

PGA----FIXED PGA
   |
   |---Variable PGA(x$ksmpp)
           |--base table perm
           |
           |--CALL GLOBAL AREA
           |--UGA---FIXED UGA
                 |
                 |--variable UGA(X$KSMUP)  
                      |
                      |--session info
                      |--private sql area
                               |
                               |--永久内存区(绑定变量就在次)
                               |--运行时区域

从9ir1 开始ORACLE 提供了两种管理PGA中除了UGA的内存区域,受初始化参数workarea_size_policy的值manual和auto影响,9IR2版本后AUTO成为默认值,10GR1以前MTS只能MANUAL,从10G开始才没有了这个限制。

通常pga_aggregate_target越大越好,但是调整正在运行的系统时要小心,因为改变pga_aggregate_target会影响查询优化器的评估结果从而改变现有执行计划,所以要先测试。理想情况下,workarea 应该可以容纳SQL执行过程中所涉及到的所有输入数据和控制信息,但有时往往sql workarea 无法满足sql 执行所需要的内存空间,所以超出部分就被写入TEMP 表空间,oracle 用三种状态来表示sql WORKAREA大小:
optimal:SQL语句能够完全在所分配的SQL工作区内完成所有的操作。
onepass:SQL语句需要与磁盘上的临时表空间交互一次才能够在所分配的SQL工作区中完成所有的操作。
multipass:由于SQL工作区过小,从而导致SQL语句需要与磁盘上的临时表空间交互多次才能完成所有的操作。

非并行模式下,按照通常的说法是“期望尺寸”不能超过min(5%*pga_aggregate_target,100MB)。100M=_pga_max_size(默认都是200m)/2,但实际上,这是在不修改_pga_max_size和_smm_max_size这两个隐藏参数的前提下,可以简单的这么认为。严格说来,应该是不能超过min(5%*pga_aggregate_target,50%*_pga_max_size,_smm_max_size)。对于并行的情况,就更加复杂,可以简单认为不超过30%*pga_aggregate_target。(10gr1及之前版本)

当你修改参数pga_aggregate_target的值时,Oracle系统会根据pga_aggregate_target和_pga_max_size这两个值来自动修改参数_smm_max_size。具体修改的规则是:
如果_pga_max_size大于5%*pga_aggregate_target,则_smm_max_size为5%*pga_aggregate_target。
如果_pga_max_size小于等于5%*pga_aggregate_target,则_smm_max_size为50%*_pga_max_size。
注意_smm_max_size单位是K,_pga_max_size是Byte

SQL> alter system set pga_aggregate_target=500m;

系统已更改。

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 524288000
SQL> select ksppinm, ksppstvl, ksppdesc from x$ksppi x, x$ksppcv y where x.indx = y.indx and ksppinm in ('_pga_max_size','_smm_max_size');

KSPPINM              KSPPSTVL             KSPPDESC
-------------------- -------------------- --------------------------------------------------
_pga_max_size        209715200            Maximum size of the PGA memory for one process
_smm_max_size        25600                maximum work area size in auto mode (serial)

SQL> select 25600/1024 from dual;

25600/1024
----------
        25
--500M的5%
SQL> alter system set pga_aggregate_target=1500m;

系统已更改。

SQL> select ksppinm, ksppstvl, ksppdesc from x$ksppi x, x$ksppcv y where x.indx = y.indx and ksppinm in ('_pga_max_size','_smm_max_size');

KSPPINM              KSPPSTVL             KSPPDESC
-------------------- -------------------- --------------------------------------------------
_pga_max_size        209715200            Maximum size of the PGA memory for one process
_smm_max_size        76800                maximum work area size in auto mode (serial)

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 1572864000

SQL> select 76800/1024 from dual;

76800/1024
----------
        75

SQL> select 1572864000*5/100/1024/1024 from dual;

1572864000*5/100/1024/1024
--------------------------
                        75
SQL> alter system set pga_aggregate_target=15m;

系统已更改。

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 15728640
SQL> select ksppinm, ksppstvl, ksppdesc from x$ksppi x, x$ksppcv y where x.indx = y.indx and ksppinm in ('_pga_max_size','_smm_max_size');

KSPPINM              KSPPSTVL             KSPPDESC
-------------------- -------------------- --------------------------------------------------
_pga_max_size        209715200            Maximum size of the PGA memory for one process
_smm_max_size        768                  maximum work area size in auto mode (serial)

SQL> select 15728640*5/100/1024/1024 from dual;

15728640*5/100/1024/1024
------------------------
                     .75

SQL> select 768/1024 from dual;

  768/1024
----------
       .75

10GR1前因为_pga_max_size 在10GR1前总是200M,所以单个sql操作最大总是100M,如果突破这个限制,如只能修改_PGA_MAX _size 这个隐藏参数,这是不被推荐的,但是到了10GR2以后这个限制也不再存在,可以参考METAlink 147806.110gr2后单个sql workarea 的限制5%*pga_aggregate_target,根据系统资源的大小来动态调整_PGA_MAX_SIZE,下面是10204的查询

SQL> l
  1* select ksppinm, ksppstvl, ksppdesc from x$ksppi x, x$ksppcv y where x.indx = y.indx and ksppinm in ('_pga_max_size','_smm_max_size')
SQL> /

KSPPINM              KSPPSTVL             KSPPDESC
-------------------- -------------------- --------------------------------------------------
_pga_max_size        503316480            Maximum size of the PGA memory for one process
_smm_max_size        245760               maximum work area size in auto mode (serial)

查看指定SESSION 的PGA,:sid为V$MYSTAT里的SID,下面是10G的写法,9I对临时表空间是‘%physical%direct%’,session uga memory max只是一个峰值,用完会回收到session uga memory

SQL> l
  1  select a.name,b.value
  2  from v$statname a,v$sesstat b
  3* where a.statistic#=b.statistic# and( a.name like '%ga%' or a.name like '%direct temp%') and sid=:SID
SQL> /

NAME                                                                VALUE
---------------------------------------------------------------------- ----------
session uga memory                                                 221720
session uga memory max                                             730588
session pga memory                                                 912980
session pga memory max                                            1175124
physical reads direct temporary tablespace                              0
physical writes direct temporary tablespace                             0
calls to kcmgas                                                         0

7 rows selected.

pga_aggregate_target 只是理想大小,并不是硬性限制,如果分配了1G,有时PGA可以用到1.5G甚至更多,可以通过V$PGASTAT观察, 12c后引入PGA_AGGREGATE_LIMIT <Know more about PGA_AGGREGATE_LIMIT 12c 19c>

SQL> select * from v$pgastat;

NAME                                                                  VALUE UNIT
---------------------------------------------------------------- ---------- ------------
aggregate PGA target parameter                                   2516582400 bytes
aggregate PGA auto target                                        2208356352 bytes
global memory bound                                               251658240 bytes
total PGA inuse                                                    62938112 bytes
total PGA allocated                                               139757568 bytes
maximum PGA allocated                                            2653119488 bytes
total freeable PGA memory                                          25952256 bytes
process count                                                            62
max processes count                                                     276
PGA memory freed back to OS                                      4.6186E+12 bytes
total PGA used for auto workareas                                         0 bytes
maximum PGA used for auto workareas                              1421077504 bytes
total PGA used for manual workareas                                       0 bytes
maximum PGA used for manual workareas                                531456 bytes
over allocation count                                                     0
bytes processed                                                  3.9880E+12 bytes
extra bytes read/written                                         8.1270E+11 bytes
cache hit percentage                                                  83.07 percent
recompute count (total)                                             1290275

19 rows selected.

PGA Cache Hit Ratio = bytes processed / (bytes processed + extra bytes read/written)

对于数据仓库建议加大_pga_max_size, 可以提升较大的效率,如有人测试近50%.  对于 _SMM_(PX)_MAX_SIZE参数不建议手动调整,在配置_pga_max_size会级联的自动修改。

打赏

目前这篇文章有1条评论(Rss)评论关闭。

  1. Chelsea Zick | #1
    2011-12-21 at 06:56

    hello there and thank you for your info – I’ve certainly picked up anything new from right here. I did however expertise a few technical points using this site, as I experienced to reload the site many times previous to I could get it to load properly. I had been wondering if your web host is OK? Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and could damage your high quality score if ads and marketing with Adwords. Anyway I am adding this RSS to my email and can look out for much more of your respective fascinating content. Make sure you update this again soon..