Oracle内存结构(之三)
【深入解析--eygle】 学习笔记
1.2.3 PGA的管理:
sys@felix SQL>show parameter area_size NAME TYPE VALUE ------------------------------------ ---------------------------------------------------- bitmap_merge_area_size integer 1048576 create_bitmap_area_size integer 8388608 hash_area_size integer 131072 sort_area_size integer 65536 workarea_size_policy string AUTO
自己主动化SQL运行内存管理(Automated SQL Execution Memory Management),也称为自己主动PGA管理,使用这个新特性,Oracle能够在一个整体PGA使用限制下自己主动管理和调整SQL内存区,从而大大简化了DBA的工作,同一时候也ᨀ高了数据库的性能。
为实现自己主动的PGA管理,Oracle引入了几个新的初始化參数:
(1)PGA_AGGREGATE_TARGET 此參数用来指定全部session 总计能够使用最大PGA内存。这个參数能够被动态的更改,取值范围从10M ~(4096G-1 )bytes。
(2)WORKAREA_SIZE_POLICY此參数用于开关PGA内存自己主动管理功能,该參数有两个选项:AUTO 和 MANUAL,当 设 置为AUTO时,数据库使用自己主动PGA管理功能,当设置为MANUAL时,则仍然使用之前手工管理的方式。
缺省的,WORKAREA_SIZE_POLICY參数被设置为AUTO。
sys@felix SQL>show parameterWORKAREA_SIZE_POLIC NAME TYPE VALUE ---------------------------------------------------------- -------- workarea_size_policy string AUTO
此外须要注意的是,在不同版本号中,自己主动PGA管理的范畴不同:
(1)在Oracle9i中,PGA_AGGREGATE_TARGET參数仅对专用server模式下(DedicatedServer)的专属连接有效,可是对共享server(Shared Server)连接无效
(2)从Oracle10g開始PGA_AGGREGATE_TARGET对专用server连接和共享server连接同一时候生效。
1.2.4 參数的设置与内存分配
工作区性能期望实现例如以下目标:
workarea execution - optimal >= 90%
workarea execution - multipass = 0%
生产系统的PGA性能指标脚本:
SELECT NAME, VALUE, 100 * (VALUE / DECODE((SELECT SUM(VALUE) FROM v$sysstat WHERE NAME LIKE'workarea executions%'), 0, NULL, (SELECT SUM(VALUE) FROM v$sysstat WHERE NAME LIKE'workarea executions%'))) pct FROMv$sysstat WHERE NAMELIKE 'workarea executions%';
<strong>sys@felix SQL>select description,dest fromx$messages where description like 'SQL Memory%'; DESCRIPTION DEST -------------------------------------------------- ---------- SQL Memory Management Calculation CKPT 15:26:04 sys@felix SQL></strong>
sys@felix SQL>select * from v$pgastat; NAME VALUE UNIT ---------------------------------------- ---------- ------------------------ aggregate PGA target parameter 146800640 bytes aggregate PGA auto target 22099968 bytes global memory bound 29360128 bytes total PGA inuse 122360832 bytes total PGA allocated 144107520 bytes maximum PGA allocated 163160064 bytes total freeable PGA memory 11141120 bytes process count 32 max processes count 36 PGA memory freed back to OS 374669312 bytes total PGA used for auto workareas 0 bytes maximum PGA used for auto workareas 6313984 bytes total PGA used for manual workareas 0 bytes maximum PGA used for manual workareas 0 bytes over allocation count 0 bytes processed 232915968 bytes extra bytes read/written 0 bytes cache hit percentage 100 percent recompute count (total) 6004 19 rows selected.
1.2.6 PGA调整建议
伴随自己主动PGA调整功能的引入,Oracle同一时候引入对应的动态性能视图用于优化建议,PGA的优化建议通过v$pga_target_advice 和 v$pga_target_advice_histogra提供。v$pga_target_advice视图通过对不同PGA设置进行评估,给出在不同设置下的PGA命中率和OverAlloc等信息。
15:32:23 sys@felix SQL>select PGA_TARGET_FOR_ESTIMATE/1024/1024 PGAMB, PGA_TARGET_FACTOR, 15:37:08 2 ESTD_PGA_CACHE_HIT_PERCENTAGE, ESTD_OVERALLOC_COUNT 15:37:08 3 from v$pga_target_advice; PGAMB PGA_TARGET_FACTOR ESTD_PGA_CACHE_HIT_PERCENTAGE ESTD_OVERALLOC_COUNT ---------- ----------------- ----------------------------- -------------------- 17.5 .125 85 4 35 .25 85 4 70 .5 85 4 105 .75 85 4 140 1 100 0 168 1.2 100 0 196 1.4 100 0 224 1.6 100 0 252 1.8 100 0 280 2 100 0 420 3 100 0 560 4 100 0 840 6 100 0 1120 8 100 0
v$pga_target_advice_histogram 视图能够通过对不同工作区大小的採样评估ᨀ供统计信息
供分析使用。当中几个重要字段有:
(1)LOW_OPTIMAL_SIZE-Histogram评估区间内Optimal下限 (bytes)
(2)HIGH_OPTIMAL_SIZE-Histogram评估区间内Optimal上限 (bytes)
(3)ESTD_OPTIMAL_EXECUTIONS-Histogram评估区间内预计optimal运行次数
(4)ESTD_ONEPASS_EXECUTIONS-Histogram评估区间内预计onepass运行次数
(5)ESTD_MULTIPASSES_EXECUTIONS-Histogram评估区间内预计multipass运行次数
(6)ESTD_TOTAL_EXECUTIONS-Histogram评估区间内预计运行总次数
SELECT pga_target_factor factor, low_optimal_size / 1024 low, ROUND(high_optimal_size / 1024) high, estd_optimal_executions estd_opt, estd_onepass_executions estd_op, estd_multipasses_executions estd_mp, estd_total_executions estd_exec FROM v$pga_target_advice_histogram WHERE pga_target_factor = 0.25 AND estd_total_executions > 0;
</pre><pre name="code" class="html"><img src="//img-blog.csdn.net/20140727143007260?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGFuZmVsaXg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
<span style="font-family: Arial, Helvetica, sans-serif;"> </span>
<span style="font-family: Arial, Helvetica, sans-serif;"> heap name="pga heap" desc=0xbaf3ca0 --注意这里</span></strong></span>
extentsz=0x20c0 alt=216 het=32767 rec=0 flg=3 opc=2 parent=(nil)owner=(nil) nex=(nil) xsz=0xfff0 heap=(nil) fl2=0x60,nex=(nil), dsxvers=1, dsxflg=0x0 dsx firstext=0xf7fa7720 EXTENT 0 addr=0x7fadf7c72010 Chunk 7fadf7c72020 sz= 65504 free " " EXTENT 1 addr=0x7fadf7d00010 Chunk 7fadf7d00020 sz= 28920 perm "perm " alo=9384 Chunk 7fadf7d07118 sz= 7656 free " " Chunk 7fadf7d08f00 sz= 4224 freeable "diag pga " ds=0x7fadf82157e0 Chunk 7fadf7d09f80 sz= 4224 freeable "diag pga " ds=0x7fadf82157e0 /heap Chunk 7fadf7fd28d0 sz= 7608 perm "perm " alo=7608 Chunk 7fadf7fd4688 sz= 40 free " " Chunk 7fadf7fd46b0 sz= 80 freeable "dbgdInitEventGr" Chunk 7fadf7fd4700 sz= 184 freeable "sdbgrf: iosb " Chunk 7fadf7fd47b8 sz= 80 freeable "skgfzctx " Chunk 7fadf7fd4808 sz= 376 freeable "PLS cca hpdesc" EXTENT 18 addr=0x7fadf7fcd860 Chunk 7fadf7fcd870 sz= 20512 perm "perm " alo=20512 EXTENT 19 addr=0x7fadf7fc9958 Chunk 7fadf7fc9968 sz= 16072 perm "perm " alo=16072 EXTENT 20 addr=0x7fadf7fc7868 Chunk 7fadf7fc7878 sz= 3240 perm "perm " alo=3240 Chunk 7fadf7fc8520 sz= 3184 perm "perm " alo=3184 Chunk 7fadf7fc9190 sz= 1088 perm "perm " alo=1088 Chunk 7fadf7fc95d0 sz= 168 perm "perm " alo=168 Chunk 7fadf7fc9678 sz= 48 free " " Chunk 7fadf7fc96a8 sz= 72 freeable "koh-kghu callh" Chunk 7fadf7fc96f0 sz= 568 freeable "joxp heap " EXTENT 21 addr=0x7fadf7fc5778 Chunk 7fadf7fc5788 sz= 4848 perm "perm " alo=4848 Chunk 7fadf7fc6a78 sz= 440 freeable "krbabrPgaRespMs" Chunk 7fadf7fc6c30 sz= 56 freeable "krbabrPgaReqCtx" Chunk 7fadf7fc6c68 sz= 424 freeable "krbabrPgaReqMsg" Chunk 7fadf7fc6e10 sz= 2600 freeable "kjztprq struct" EXTENT 22 addr=0x7fadf7fc3688 Chunk 7fadf7fc3698 sz= 7720 perm "perm " alo=7720 Chunk 7fadf7fc54c0 sz= 160 freeable "regheapd_kdlwpg" Chunk 7fadf7fc5560 sz= 88 freeable "KCFIS GCTX " Chunk 7fadf7fc55b8 sz= 400 freeable "krbabrPgaStbyRe" EXTENT 23 addr=0x7fadf7fb5e28 Chunk 7fadf7fb5e38 sz= 55328 perm "perm " alo=55328 EXTENT 24 addr=0x7fadf7fb3d38 Chunk 7fadf7fb3d48 sz= 4888 perm "perm " alo=4888 Chunk 7fadf7fb5060 sz= 2992 recreate "KSFQ heap " latch=(nil)
进一步的,能够将某个详细的数据存储结构转储出来(DS),如 以 上 的ds dcd00c0其空间使用的大小为 sz= 14036,首先对空间地址进行一下转换:
select to_number('baf3ca0','xxxxxxxxxx') from dual 15:50:33 sys@felix SQL>/ TO_NUMBER('BAF3CA0','XXXXXXXXXX') --------------------------------- 196033696 15:50:33 sys@felix SQL>
使用例如以下命令转储固定地址空间的内容:
alter session set events'immediate trace name heapdump_addr level 1, addr n';
以上计算的地址空间能够通过例如以下命令转储:
SQL> ALTER SESSIONSET EVENTS 'immediate trace name heapdump_addr level 1, addr 196033696';
Session altered.
获取转储文件的脚本:
SELECT a.VALUE || b.symbol || c.instance_name || '_ora_' || d.spid || '.trc' trace_file FROM (SELECT VALUE FROM v$parameter WHERE NAME = 'user_dump_dest') a, (SELECT SUBSTR(VALUE, -6, 1) symbol FROM v$parameter WHERE NAME = 'user_dump_dest') b, (SELECT instance_name FROM v$instance) c, (SELECT spid FROM v$session s, v$process p, v$mystat m WHERE s.paddr = p.addr AND s.SID = m.SID AND m.statistic# = 0) d;
检查这个进程转储文件,能够发现例如以下Heap地址信息及空间分配:
[oracle@felix ~]$grep heap /u01/app/oracle/diag/rdbms/felix/felix/trace/felix_ora_6443.trc <strong><span style="color:#ff0000;">HEAP DUMP heap name="pga heap" desc=0xbaf3ca0</span></strong> parent=(nil) owner=(nil) nex=(nil) xsz=0xfff0 heap=(nil) Chunk 7fadf7fc96f0 sz= 568 freeable "joxp heap " Chunk 7fadf7fc54c0 sz= 160 freeable "regheapd_kdlwpg" Chunk 7fadf7fb5060 sz= 2992 recreate "KSFQ heap " latch=(nil) Chunk 7fadf7fb5c10 sz= 160 freeable "KSFQ heap descr" Chunk 7fadf7fb0790 sz= 232 freeable "iovecheapd_kdlw" Chunk 7fadf7fb0878 sz= 304 freeable "bcheapd_kdlwpga" Chunk 7fadf7fb09a8 sz= 208 freeable "sioheapd_kdlwpg" Chunk 7fadf7fb0ad8 sz= 160 freeable "KSZ pga subheap" Total heap size = 499952 <strong><span style="color:#ff0000;">HEAP DUMP heap name="top call heap" desc=0xbaf94e0</span></strong> parent=(nil) owner=(nil) nex=(nil) xsz=0xfff8 heap=(nil) Chunk 7fadf7ccb7d8 sz= 1032 recreate "callheap " latch=(nil) Chunk 7fadf7cceb78 sz= 4224 freeable "callheap " ds=0xbaf85c0 Chunk 7fadf7ccfbf8 sz= 1032 recreate "callheap " latch=(nil) Total heap size = 524096
<strong><span style="color:#ff0000;">HEAP DUMP heap name="top uga heap" desc=0xbaf9700</span></strong> parent=(nil) owner=(nil) nex=(nil) xsz=0xfff8 heap=(nil) Chunk 7fadf7c62018 sz= 65512 freeable "session heap " ds=0x7fadf7cd5be0 Chunk 7fadf7d10018 sz= 65512 freeable "session heap " ds=0x7fadf7cd5be0 Chunk 7fadf7cf0018 sz= 65512 freeable "session heap " ds=0x7fadf7cd5be0 Chunk 7fadf7ce0068 sz= 65432 recreate "session heap " latch=(nil) Total heap size = 262048 <strong><span style="color:#ff0000;">HEAP DUMP heap name="pga heap" desc=0xbaf3ca0</span></strong> parent=(nil) owner=(nil) nex=(nil) xsz=0x1fff0 heap=(nil) Chunk 7fadf7fc96f0 sz= 568 freeable "joxp heap " Chunk 7fadf7fc54c0 sz= 160 freeable "regheapd_kdlwpg" Chunk 7fadf7fb5060 sz= 2992 recreate "KSFQ heap " latch=(nil) Chunk 7fadf7fb5c10 sz= 160 freeable "KSFQ heap descr" Chunk 7fadf7fb0790 sz= 232 freeable "iovecheapd_kdlw" Chunk 7fadf7fb0878 sz= 304 freeable "bcheapd_kdlwpga" Chunk 7fadf7fb09a8 sz= 208 freeable "sioheapd_kdlwpg" Chunk 7fadf7fb0ad8 sz= 160 freeable "KSZ pga subheap" Total heap size = 827504
由上面红色字体可见,在自己主动管理模式下,PGA,CGA,UGA都是独立分配的。