首頁  >  文章  >  資料庫  >  oracle PGA管理(算法)

oracle PGA管理(算法)

WBOY
WBOY原創
2016-06-07 15:50:331366瀏覽

主要总结下pga分配算法,详细概念单总结 简单理解pga,pga就是一个操作系统进程,或线程(WIN上)的专用内存 pmon,smon这些后台进程都有自己的pga pga早期手动 管理 组成由sort_area_size,hash_area_size,bitmap_merge_size,create_bitmap_area_size(这些都叫工作

主要总结下pga分配算法,详细概念单总结

简单理解pga,pga就是一个操作系统进程,或线程(WIN上)的专用内存
pmon,smon这些后台进程都有自己的pga


pga早期手动管理组成由sort_area_size,hash_area_size,bitmap_merge_size,create_bitmap_area_size(这些都叫工作区)
手动缺点,不好回收和共享,会造成PGA内存过度消耗

PAG自动(9i开始支持)
1.pga_aggregate_target来指定所有session总计可以使用的最大pga内存(10M-4096G)
2.workarea_size_policy控制pag自动管理功能开启或关闭,auto表示开启(default), manual表示关闭,9i auto只支持专用连接,共享连接不支持
10g都支持

_pga_max_size:控制pga最大大小
9i-10r1中,单个sql操作内存使用现在
1.对于串行操作,单sql操作pga分配原则,min(5%*pga_aggregate_target,100mb)
########5%*pga_aggregate_targe实际由_smm_max_size控制]
2.并行操作使用pga按 30%*pga_aggregate_target/dop(dop=并行度)

 


9I _pga_max_size与_smm_max_size
_pga_max_size>5%*pga_aggregate_target,_smm_max_size=5%*pga_aggregate_target'
_pga_max_size

used_pga_mb=min(5%*pga_aggregate_target,50*_pga_max_size,_smm_max_size)

10r2,11g原则
1.串行操作
pga_aggregate_targetpga_aggregate_target between 500m and 1000M ,_smm_max_size=100M
pga_aggregate_target between 1001m and 2.5g,_smm_max_size=10%*pga_aggregate_target
pga_aggregate_target >2.5g,_smm_max_size=0.25GB
2.并行操作
50*pag_aggregate_target/dop
dopdop>5时,_smm_px_max_size生效

 

 

_newsort_enabled  控制算法规则,true用10g新算法,false用9i算法
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: newsort
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%newsort%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_newsort_enabled               TRUE
controls whether new sorts can be used as system sort

设置建议
1.oltp系统 pag_aggregate_target=*80%*20%
2.dss系统  pag_aggregate_target=*80%*50%
分析:留20%给os,其他80%给pga+sga,oltp ,pga占 80%中20%,dss占80%中50%

#查看某个process使用情况
select pid,spid,username ,pga_used_mem,pga_alloc_mem,pga_freeable_mem,pga_max_mem,program from v$process where spid=&spid

SQL> select pid,spid,username ,pga_used_mem,pga_alloc_mem,pga_freeable_mem,pga_max_mem,program from v$process where spid=&spid;
Enter value for spid: 25510
old   1: select pid,spid,username ,pga_used_mem,pga_alloc_mem,pga_freeable_mem,pga_max_mem,program from v$process where spid=&spid
new   1: select pid,spid,username ,pga_used_mem,pga_alloc_mem,pga_freeable_mem,pga_max_mem,program from v$process where spid=25510

       PID SPID                     USERNAME        PGA_USED_MEM PGA_ALLOC_MEM
---------- ------------------------ --------------- ------------ -------------
PGA_FREEABLE_MEM PGA_MAX_MEM PROGRAM
---------------- ----------- ------------------------------------------------
        33 25510                    oracle                     0       2664666
          983040     8431834oracle@dmk01(PZ98)

pga_used_mem:进程使用的pga
pga_alloc_mem:分配给进程的pga
pga_freeable_mem:空闲
pga_max_mem:进程使用pga内存的最大

 


#查看pga消耗到哪些项目上了
col program for a20
set linesize 1000
select p.program,p.pid,pm.category,pm.allocated,pm.used,pm.max_allocated from v$process p,v$process_memory pm where p.pid=pm.pid and p.spid=&spid;


SQL> col program for a20
SQL> set linesize 1000
SQL> select p.program,p.pid,pm.category,pm.allocated,pm.used,pm.max_allocated from v$process p,v$process_memory pm where p.pid=pm.pid and p.spid=&spid;
Enter value for spid: 25510
old   1: select p.program,p.pid,pm.category,pm.allocated,pm.used,pm.max_allocated from v$process p,v$process_memory pm where p.pid=pm.pid and p.spid=&spid
new   1: select p.program,p.pid,pm.category,pm.allocated,pm.used,pm.max_allocated from v$process p,v$process_memory pm where p.pid=pm.pid and p.spid=25510

PROGRAM                     PID CATEGORY         ALLOCATED       USED MAX_ALLOCATED
-------------------- ---------- --------------- ---------- ---------- -------------
oracle@dmk01(PZ98)          33 SQL                      0          0       2424808
oracle@dmk01(PZ98)          33 PL/SQL               24840      17104         26928
oracle@dmk01(PZ98)          33 Freeable            983040          0
oracle@dmk01(PZ98)          33 Other              1656786                  4997058

 

sql在workare中有3种方式
1.optimal:最优方式,所有处理可以在内存中完成
2.onepass:大部分操作可以在内存中完成,但交换到临时表一次
3.multipass:多变交互临时表,产生大量disk sort之类,性能最差
 
oracle建议
workarea execution_optimal>=90%
workarea execution_multipass=0%
#查看系统中性能指标
select name,value,100*(value/decode((select sum(value) from v$sysstat where name like 'workarea execution%'),0,null,(select sum(value) from v$sysstat where name like 'workarea execution%')))pct from v$sysstat where name like 'workarea executions%';


SQL> select name,value,100*(value/decode((select sum(value) from v$sysstat where name like 'workarea execution%'),0,null,(select sum(value) from v$sysstat where name like 'workarea execution%')))pct from v$sysstat where name like 'workarea executions%';

NAME                                                                  VALUE        PCT
---------------------------------------------------------------- ---------- ----------
workarea executions - optimal                                        567832 99.9954214
workarea executions - onepass                                            24 .004226409
workarea executions - multipass                                           0          0

 

#查单个sql语句workarea使用情况
SELECT
b.sql_text,
a.operation_type,
a.policy,
a.last_memory_used/(1024*1024) as "Used MB" ,
a.estimated_optimal_size/(1024*1024) as "Est Opt MB",
a.estimated_onepass_size/(1024*1024) as "Est OnePass MB",
a.last_execution,
a.last_tempseg_size
FROM v$sql_workarea a,v$sql b
WHERE a.hash_value = b.hash_value
  and a.hash_value = &hashvalue
/

#查session 使用pga
select a.name, b.value
from v$statname a, v$sesstat b
where a.statistic# = b.statistic#
and b.sid = &sid
and a.name like '%ga %'
order by a.name
/

#program 使用pga情况
SELECT
   a.pga_used_mem "PGA Used",
   a.pga_alloc_mem "PGA Alloc",
   a.pga_max_mem "PGA Max"
  FROM v$process a,v$session b
where a.addr = b.paddr
  and b.sid= &sid
/

 

 

关于pga自动管理算法:
oracle 采用的feedback loop实现的,当一个process执行sql语句时,先用local memory manager注册一个active workarea profile,workarea profile是与内存管理器之间唯一的通信接口
(既sql语句和内存管理器之间唯一接口),当sql语句执行完成对应的workarea profile删除
,profile含这个workarea很多属性(例如sql类型是hash join还是什么之类,执行one pass,optimal操作内存大小等的元数据)
workarea active profile集,通过local memory manager维护,存sga中,profile常常被更新(要求及时反映sql语句当前已消耗内存,及是否被交换到temp tablespace等信息),
所以active profile基本上就是pga内存需要和当前正在使用的pga内存,通过这些profile信息
,global memory manager会计算出一个既可以限制内存使用又可以提高较好性能的global memory bound,这个值用于限制单个进程pga的上限,global memory manager每3S更新一次memory
bound,local memory manager得到memory bound后会计算每个active statement所需要分配的pga内存大小(execute size),然后每个active statement将会在自己所分配到的execute size
中计算

 


路线(一个环路)
active statement--->注册workarea profile-->local memory manager(存sga中)-->set of active workarea profiles-->global memory manager--->计算出memory bound--->local memory manager
--->获取workarea size--->active statement

其实原理很简单,就是每个sql语句拿出信息做成profile,然后交给local memory manager 然后做成profile集(大量profile),然后global memory manager通过profile集计算出memory bound
,把这个memory bound给  local memory manager,local memory manager 用memory bound计算出每个active statement的 execute size,然后每个active statement在自己分到的execute
size中计算


global memeory bound将影响 所有进程pga分配(限制单个进程pga的上限)

 


由ckpt实现,global memory manager 3s更新一次memory bound

SQL> select description ,dest from x$messages where lower(description) like 'sql memory%';

DESCRIPTION
----------------------------------------------------------------
DEST
----------------------------------------------------------------
SQL Memory Management Calculation
CKPT

 

SQL> select time,data from x$trace where lower(data) like '%sql memory%' order by seq#;

      TIME
----------
DATA
--------------------------------------------------------------------------------
1.2688E+15
KSBCTI: (CKPT) : (timeout action)   : acnum=[178] comment=[SQL Memory Management
 Calculation]

1.2688E+15
KSBCTI: (CKPT) : (timeout action)   : acnum=[178] comment=[SQL Memory Management
 Calculation]

1.2688E+15

      TIME
----------
DATA
--------------------------------------------------------------------------------
KSBCTI: (CKPT) : (timeout action)   : acnum=[178] comment=[SQL Memory Management
 Calculation]

 


10g r2,11g中,workarea管理内存分配,存在shared pool中(local memory manager)
SQL> select * from v$sgastat where name like 'work area%';

POOL         NAME                            BYTES
------------ -------------------------- ----------
shared pool  work area tab                  265320

 

 

 


10g  测试

 

SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

 

SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  209715200
Maximum size of the PGA memory for one process

可以看到当pga_aggreate_target小于1g,_pga_max_size 默认为200MB

SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  26214
maximum work area size in auto mode (serial)

pga_aggregate_target


SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 128M
SQL>


SQL> select 26214/1024 from dual;

26214/1024
----------
25.5996094

SQL> select 0.2*128 from dual;

   0.2*128
----------
      25.6

_smm_max_size = 20%*pga_aggregate_target

 


修改_pga_max_size=10MB  pga_aggregate_target =128M

SQL> alter system set "_pga_max_size"=10m;

System altered.

SQL> startup force    重起下库,让内存重新计算
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> drop table t;

Table dropped.

SQL> create table t as select * from dba_objects;

Table created.

SQL> insert into t select * from dba_objects;

50067 rows created.

SQL> insert into t select * from dba_objects;

50067 rows created.

SQL> commit;

Commit complete.

SQL> select distinct sid from v$mystat;

       SID
----------
       159

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_pga_max_size                        big integer 10M
pga_aggregate_target                 big integer 128M
SQL> set linesize 132
column name format a30
SQL> SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  10485760       
Maximum size of the PGA memory for one process
可以看到已经生效,单位字节=10M

SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  5120
maximum work area size in auto mode (serial)

可以看到 _smm_max_size  此时并不等于 20%*pga_aggregate_target而是 =5m 既50%_pga_max_size

 


SQL> select 10485760/1024/1024 from dual;

10485760/1024/1024
------------------
                10


SQL> select 5120/1024 from dual;

 5120/1024
----------
         5
        
       

 

SQL> set autotrace traceonly stat
SQL> select * from t where rownum

49999 rows selected.


Statistics
----------------------------------------------------------
         37  recursive calls
          8  db block gets
        835  consistent gets
       1382  physical reads
          0  redo size
    2837037  bytes sent via SQL*Net to client
      37063  bytes received via SQL*Net from client
       3335  SQL*Net roundtrips to/from client
          0  sorts (memory)
          1  sorts (disk)
      49999  rows processed

 

 


SQL> select hash_value from v$sql where sql_text='select * from t where rownum  2  ;

HASH_VALUE
----------
1281487883

SQL> SELECT
b.sql_text,
  2    3  a.operation_type,
  4  a.policy,
  5  a.last_memory_used/(1024*1024) as "Used MB" ,
  6  a.estimated_optimal_size/(1024*1024) as "Est Opt MB",
  7  a.estimated_onepass_size/(1024*1024) as "Est OnePass MB",
  8  a.last_execution,
  9  a.last_tempseg_size
 10  FROM v$sql_workarea a,v$sql b
 11  WHERE a.hash_value = b.hash_value
 12    and a.hash_value = &hashvalue
 13  /
Enter value for hashvalue: 1281487883
old  12:   and a.hash_value = &hashvalue
new  12:   and a.hash_value = 1281487883

SQL_TEXT
--------------------------------------------------------------------------------
OPERATION_TYPE       POLICY        Used MB Est Opt MB Est OnePass MB LAST_EXECU
-------------------- ---------- ---------- ---------- -------------- ----------
LAST_TEMPSEG_SIZE
-----------------
select * from t where rownumSORT (v2)            AUTO       5.02832031 6.09960938      .98828125 1 PASS
          6291456

可以看到内存被限制在5M内,现在操作是1 pass,如果 最优操作(全在内存里 需要6M)
所以_smm_max_size就可以限制一个process pga内存 最大使用


此时_smm_max_size=5m是如下计算
1._pga_max_size2._pga_max_size>40%*pga_aggregate_siz,此时_smm_max_size按下面方式计算

pga_aggregate_targetpga_aggregate_target between 500m and 1000M ,_smm_max_size=100M
pga_aggregate_target between 1001m and 2.5g,_smm_max_size=10%*pga_aggregate_target
pga_aggregate_target >2.5g,_smm_max_size=0.25GB

 


修改pga_aggregate_target超过500m
SQL> alter system set pga_aggregate_target=501m;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_pga_max_size                        big integer 10M  ~~~~~~~~~还未10MB
pga_aggregate_target                 big integer 501M
SQL>

 


SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
SQL>   2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  10485760
Maximum size of the PGA memory for one process


SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  5120 ~~~~~~~~~~~~~~~还为5M 单位kb
maximum work area size in auto mode (serial)

通过这个可以发现 影响_smm_max_size调整最直接相关的参数为_pga_max_size,由于_pga_max_size未调整. _smm_max_size没变
所以可以得出结论pga_aggreate_target影响_pga_max_size,_pga_max_size影响_smm_max_size

可以看到 虽然pga_aggregate_target设置了501M,_PGA_MAX_SIZE应该为200M 自动调整为,但由于_pga_max_size手动调整的,所以要手动reset下 让它自动默认(这样就自动计算了)
SQL> alter system reset "_pga_max_size" scope=spfile sid='*' ;

System altered.

SQL> startup force
ORACLE instance started

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  209715200    ~~~~~~~~~
Maximum size of the PGA memory for one process

按算发pga_aggreate_target

SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  102400
maximum work area size in auto mode (serial)


SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 501M
SQL>

102400/1024=100MB正好100MB
可以看到_pga_max_size=200M(pga_aggreate_target500M  _smm_max_size   为100MB
而实际内部因为
_pga_max_size=200M(pga_aggreate_target影响_pga_max_size,_pga_max_size影响_smm_max_size)
有时候 手动修改_pga_max_size后 ,如果要让算法继续执行,需要reset下,否则不使用算法了.

 

改 pga_aggregate_targetSQL> alter system set pga_aggregate_target=499m;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  209715200
Maximum size of the PGA memory for one process


SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  102195
maximum work area size in auto mode (serial)


SQL> select 102195/1024 from dual;

102195/1024
-----------
 99.7998047  _smm_max_size=99.8m,_pga_max_size  =200M

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 499M
SQL> select 499*0.2 from dual;

   499*0.2
----------
      99.8
     
SQL> select 0.4*499 from dual;

   0.4*499
----------
     199.6

分析  _pga_max_size >40%pga_aggregate_target ,所以_smm_max_size=20%*pga_aggregate_target =99.8M

 

手动改_pga_max_size为300M,pga_aggregate_target=501M
SQL> alter system set "_pga_max_size"=300M SCOPE=SPFILE;

System altered.

SQL> startup force;
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  314572800
Maximum size of the PGA memory for one process


SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  102604
maximum work area size in auto mode (serial)

 

SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_pga_max_size                        big integer 300M
pga_aggregate_target                 big integer 501M
SQL>
SQL> select  102604/1024 from dual;

102604/1024
-----------
 100.199219


SQL> select 0.2*501 from dual;

   0.2*501
----------
     100.2


分析
_pga_max_size>40%*pga_aggregate_target,
按算法 pga_aggregate_target>500M_pga_max_size>40%*pga_aggregate_target,_smm_max_size=20%*pga_aggregate_target =100.2m


做一个极端的,_pga_max_size=600M,pga_aggregate_target=700M,如果按 pga_aggregate_target between 500m and 1000M 那么_smm_max_size=100M,实际会是这样吗?


SQL> alter system set "_pga_max_size"=600m;

System altered.

SQL> alter system set pga_aggregate_target=700m;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_pga_max_size                        big integer 600M
pga_aggregate_target                 big integer 700M
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL>
SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  143360
maximum work area size in auto mode (serial)


可以看到_smm_max_size=140G没有按,pga_aggregate_target>500M40%*pga_aggregate_target,而是按20%*pga_aggreget_target算的=140G了

 

 

 

 

 

 


设置_pga_max_size=199g,pga_aggregate_target=501g
SQL> alter system set "_pga_max_size"=199M SCOPE=SPFILE;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
_pga_max_size                        big integer 199M
pga_aggregate_target                 big integer 501M
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  101888
maximum work area size in auto mode (serial)


SQL> select 101888/1024 from dual;

101888/1024
-----------
       99.5~~~~~~~~~~~~~~~

分析_pga_max_size

SQL> alter system set "_pga_max_size"=99M SCOPE=SPFILE;

System altered.

SQL> startup force
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  103809024
Maximum size of the PGA memory for one process


SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  50688             
maximum work area size in auto mode (serial)


SQL> select 103809024/1024/1024 from dual
  2  ;

103809024/1024/1024
-------------------
                 99

SQL> select  50688 /1024 from dual;

50688/1024
----------
      49.5
_smm_max_size =      49.5

分析_pga_max_size

 


有文挡说_smm_max_size最大0.25GB,实际是这样吗
SQL> alter system set pga_aggregate_target=2g; 修改为2g

System altered.

SQL> startup force;
ORACLE instance started.

Total System Global Area  268435456 bytes
Fixed Size                  1266944 bytes
Variable Size             100666112 bytes
Database Buffers          159383552 bytes
Redo Buffers                7118848 bytes
Database mounted.
Database opened.
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  419430400
Maximum size of the PGA memory for one process


_pga_max_size  =20%*pga_aggreaget_target=400m
SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  204800
maximum work area size in auto mode (serial)

_pga_max_size

文档中当pga_aggrgate_target >1G情况时,其实还是按上面的 计算方式
_pga_max_size=20%*pga_aggregate_target
_smm_max_size=10%*pga_aggregate_target

一套负责的生产库中pga (11g,11.1.0.7)
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  **********************没开
SQL> show parameter pga

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
pga_aggregate_target                 big integer 30G
SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL>
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_pga_max_size                  2147483648
Maximum size of the PGA memory for one process


SQL> /
Enter value for par: smm_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%smm_max%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
_smm_max_size                  1048576

可以看到 _smm_max_size早就超过了250M 到达了1G,这个数是根据_pga_max_size决定
当pga_aggreate_size>1g时候,_pga_max_size=20%*pga_aggreate_size(pga_aggreate_size>10g时,_pga_max_size不变)
_pga_max_size=20%*10g

总结10g r2

PGA_AGGREATE_TARGET与_smm_max_size
pga_aggregate_targetpga_aggregate_target between 500m and 1000M ,_smm_max_size=100M
pga_aggregate_target between 1001m and 2.5g,_smm_max_size=10%*pga_aggregate_target

 

 

pga_aggregate_target,_pga_max_size 关系
_pga_max_size如果pga_aggregate_target_pga_max_size如果pga_aggregate_target>1g,_pga_max_size=20%*pga_aggregate_target(>5G不再变化)

 实际到内部
_smm_max_size为实际控制单个process使用pga上限,唯一可以相关他的参数是_pga_max_size,_pga_max_size被pga_aggregate_target相关
_pga_max_size其他时候(_pga_max_size>40%*pga_aggregate_target) _smm_max_size=20%PGA_AGGREGATe_TARGET

 


具体process可以使用的pga就是由_smm_max_size控制


> "_pga_max_size" is 200M by default.

That was true up to Oracle 10.1. Since 10.2 it is a dynamic parameter.

In 10.2 it is limited to 200M as long as pga_aggregate_target is smaller as 1GB.
When pga_aggregate_target is set to a larger value as 1GB then _pga_max_size= 20% of pga_aggregate_target .

> Is 350M of "pga_aggregate_target" effective even when "_pga_max_size" is 200M?
Yes it is still effective. The size of one work area (hash area, sort area) is not directly limited by _pga_max_size but by _smm_max_size (unit of this parameter is KBytes!). When you set pga_aggregate_target to 350M _smm_max_size should have a value like 71680 (71680KB => 70MB).

 

 

 

随着版本的变化内存管理也发生变化

11g内存管理更加简单了
只要设置memory_target=PGA+SGA这叫做amm特性,automatic memory management
设置后取代了pga_aggregate_target,sga_target,原理跟设置sga_target一样,_pga_aggregate_target,_sga_target表示数据库上次正常关闭时候内存分配的样子

oracle启动时候 会用 pga_aggregate_target,sga_target与_pga_aggregate_target,_sga_target,谁的值大用谁


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 476M
memory_target                        big integer 476M   ****************************
pga_aggregate_target                 big integer 60M
sga_target                           big integer 0

 

SQL> set linesize 132
SQL> column name format a30
SQL> column value format a25
SQL> SELECT x.ksppinm NAME, y.ksppstvl VALUE, x.ksppdesc describ
  2     FROM SYS.x$ksppi x, SYS.x$ksppcv y
  3      WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
  4 
SQL>
SQL> /
Enter value for par: pga_aggrega
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_aggrega%'

NAME                           VALUE
------------------------------ -------------------------
DESCRIB
------------------------------------------------------------------------------------------------------------------------------------
pga_aggregate_target           62914560
Target size for the aggregate PGA memory consumed by the instance

__pga_aggregate_target         150994944
Current target size for the aggregate PGA memory consumed

可以看到实际pga为150M
SQL> /
Enter value for par: pga_max
old   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%&par%'
new   3:     WHERE x.indx = y.indx AND x.ksppinm LIKE '%pga_max%'

NAME                

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn