I have been using the below script for Active PGA usage in a Database as I have had lot of issues at Customers with Massive Parallelism blowing out PGA (Direct path reads)
and so the script gets me the real time PGA Usage
##########
script
##########
———————————————–
select to_char(sysdate,’DD-MM-YYYY HH24:MI:SS’) from dual;
prompt =================================================
prompt ==== v$pgastat info ====
prompt =================================================
column name format a40
column value format 99999999999999999999
select name, value from v$pgastat;
set lines 200
prompt =================================================
prompt ==== V$PROCESS real time data ====
prompt =================================================
SELECT PROGRAM, PGA_USED_MEM/(1024*1024) “PGA_USED_MEM”, PGA_ALLOC_MEM/(1024*1024) “PGA_ALLOC_MEM”, PGA_FREEABLE_MEM/(1024*1024) “PGA_FREEABLE_MEM”,
PGA_MAX_MEM/(1024*1024) “PGA_MAX_MEM”
FROM
V$PROCESS
where PGA_MAX_MEM/(1024*1024) > 50
order by PGA_MAX_MEM desc ;
prompt =================================================
prompt ==== GV$PROCESS_MEMORY real time data ====
prompt =================================================
select INST_ID,PID,SERIAL#,CATEGORY, ALLOCATED, USED/(1024*1024) “Used_MB”, MAX_ALLOCATED/(1024*1024) “MAX_ALLOCATED_MB”
from
GV$PROCESS_MEMORY
where
Used is not null and MAX_ALLOCATED/(1024*1024) > 50
order by MAX_ALLOCATED_MB desc;
prompt =================================================
prompt ==== workload execution profile ====
prompt =================================================
col c1 heading ‘Workarea|Profile’ format a35
col c2 heading ‘Count’ format 999999999
col c3 heading ‘Percentage’ format 99999
select name c1,count c2,decode(total, 0, 0, round(count*100/total)) c3
from
(
select name,value count,(sum(value) over ()) total
from
v$sysstat
where
name like ‘workarea exec%’
);
prompt =================================================
prompt ==== V$SQL_WORKAREA real time info ====
prompt =================================================
SELECT *
FROM (SELECT workarea_address, operation_type, policy, estimated_optimal_size/(1024*1024*1024) estimated_optimal_size_gb
FROM V$SQL_WORKAREA
ORDER BY estimated_optimal_size DESC)
WHERE ROWNUM <= 10;
prompt =================================================
prompt ==== Gv$sql_workarea_histogram info on passes ====
prompt =================================================
SELECT optimal_count, round(optimal_count*100/total, 2) optimal_perc, onepass_count, round(onepass_count*100/total, 2) onepass_perc, multipass_count, round(multipass_count*100/total, 2) multipass_perc
FROM
(
SELECT decode(sum(total_executions), 0, 1, sum(total_executions)) total,
sum(OPTIMAL_EXECUTIONS) optimal_count,
sum(ONEPASS_EXECUTIONS) onepass_count,
sum(MULTIPASSES_EXECUTIONS) multipass_count
FROM
Gv$sql_workarea_histogram
WHERE low_optimal_size >= 64*1024);
—————————————————————————————-
#################
DETAILS on the Views used above to Monitor the Performance of the Automatic PGA Memory Management
#################
SQL> col VALUE for 99999999999999999999999999999999999999
SQL> set lines 200
SQL> SELECT * FROM V$PGASTAT;
NAME VALUE UNIT
—————————————————————- ————————————— ————
aggregate PGA target parameter 6442450944 bytes
aggregate PGA auto target 2236879872 bytes
global memory bound 644239360 bytes
total PGA inuse 4643407872 bytes
total PGA allocated 5441014784 bytes
maximum PGA allocated 13053722624 bytes
total freeable PGA memory 277413888 bytes
process count 270
max processes count 626
PGA memory freed back to OS 11167367626752 bytes
total PGA used for auto workareas 681655296 bytes
NAME VALUE UNIT
—————————————————————- ————————————— ————
maximum PGA used for auto workareas 8055233536 bytes
total PGA used for manual workareas 0 bytes
maximum PGA used for manual workareas 1223434240 bytes
over allocation count 1534477
bytes processed 15883374120960 bytes
extra bytes read/written 18453620585472 bytes
cache hit percentage 46 percent >>>> PGA Small ???
recompute count (total) 3501785
19 rows selected.
The main statistics displayed in V$PGASTAT are as follows:
¦ aggregate PGA target parameter: This is the current value of the initialization
parameter PGA_AGGREGATE_TARGET. The default value is 20% of the SGA size. If you
set this parameter to 0, automatic management of the PGA memory is disabled.
¦ aggregate PGA auto target: This gives the amount of PGA memory Oracle Database can use for work areas running in automatic mode. This amount is
dynamically derived from the value of the parameter PGA_AGGREGATE_TARGET and
the current work area workload. Hence, it is continuously adjusted by Oracle. If this value is small compared to the value of PGA_AGGREGATE_TARGET, then a lot of
PGA memory is used by other components of the system (for example, PL/SQL or
Java memory) and little is left for sort work areas. You must ensure that enough
PGA memory is left for work areas running in automatic mode.
¦ global memory bound: This gives the maximum size of a work area executed in
AUTO mode. This value is continuously adjusted by Oracle Database to reflect the
current state of the work area workload. The global memory bound generally
decreases when the number of active work areas is increasing in the system. As a rule of thumb, the value of the global bound should not decrease to less than one
megabyte. If it does, then the value of PGA_AGGREGATE_TARGET should probably be
increased.
¦ total PGA allocated: This gives the current amount of PGA memory allocated
by the instance. Oracle Database tries to keep this number less than the value of
PGA_AGGREGATE_TARGET. However, it is possible for the PGA allocated to exceed
that value by a small percentage and for a short period, when the work area
workload is increasing very rapidly or when the initialization parameter PGA_
AGGREGATE_TARGET is set to a too small value.
¦ total freeable PGA memory: This indicates how much allocated PGA memory
which can be freed.
¦ total PGA used for auto workareas: This indicates how much PGA memory is
currently consumed by work areas running under automatic memory
management mode. This number can be used to determine how much memory is
consumed by other consumers of the PGA memory (for example, PL/SQL or
Java): PGA other = total PGA allocated – total PGA used for auto workareas
¦ over allocation count: This statistic is cumulative from instance startup. Over-allocating PGA memory can happen if the value of PGA_AGGREGATE_TARGET is
too small to accommodate the PGA other component in the previous equation plus
the minimum memory required to execute the work area workload. When this
happens, Oracle Database cannot honor the initialization parameter PGA_AGGREGATE_TARGET, and extra PGA memory must be allocated. If over-allocation
occurs, you should increase the value of PGA_AGGREGATE_TARGET using the
information provided by the advice view V$PGA_TARGET_ADVICE.
V$PROCESS This view has one row for each Oracle process connected to the instance.
The columns PGA_USED_MEM, PGA_ALLOC_MEM, PGA_FREEABLE_MEM and PGA_MAX_MEM can
be used to monitor the PGA memory usage of these processes. For example:
SQL> SELECT PROGRAM, PGA_USED_MEM, PGA_ALLOC_MEM, PGA_FREEABLE_MEM, PGA_MAX_MEM FROM V$PROCESS;
V$PROCESS_MEMORY This view displays dynamic PGA memory usage by named component categories for each Oracle process. This view will contain up to six rows
for each Oracle process, one row for:
¦ Each named component category: Java, PL/SQL, OLAP, and SQL.
¦ Freeable: memory that has been allocated to the process by the operating system,
but not to a specific category.
¦ Other: memory that has been allocated to a category, but not to one of the named
categories.
You can use the columns CATEGORY, ALLOCATED, USED, and MAX_ALLOCATED to
dynamically monitor the PGA memory usage of Oracle processes for each of the six
categories.
select INST_ID,CATEGORY, ALLOCATED, USED, MAX_ALLOCATED from GV$PROCESS_MEMORY
select INST_ID,PID,SERIAL#,CATEGORY, ALLOCATED, USED/(1024*1024) “Used_MB”, MAX_ALLOCATED/(1024*1024) “MAX_ALLOCATED_MB” from GV$PROCESS_MEMORY where Used is not null order by USED desc
2 126 180 JAVA 3856688 3.6542510986328125 4.40497589111328125
2 166 233 JAVA 3554592 3.3853912353515625 4.09759521484375
1 133 4 JAVA 3551608 3.385162353515625 4.62749481201171875
2 117 174 JAVA 3555920 3.384368896484375 4.631622314453125
1 148 238 JAVA 3304680 3.14263916015625 4.417755126953125
1 36 210 JAVA 3020944 2.8735809326171875 3.77861785888671875
3 113 152 JAVA 3013184 2.87197113037109375 3.77121734619140625
2 126 180 PL/SQL 4304744 2.55957794189453125 4.6701507568359375
1 36 210 PL/SQL 3409464 2.04129791259765625 3.32293701171875
1 140 28 JAVA 2775056 1.697906494140625 3.4982452392578125
3 113 152 PL/SQL 3379832 1.6282196044921875 3.33892822265625
V$SQL_WORKAREA_HISTOGRAM This view shows the number of work areas executed with optimal memory size, one-pass memory size, and multi-pass memory size since
instance startup. Statistics in this view are subdivided into buckets that are defined by
the optimal memory requirement of the work area. Each bucket is identified by a
range of optimal memory requirements specified by the values of the columns LOW_
OPTIMAL_SIZE and HIGH_OPTIMAL_SIZE
Consider a sort operation that requires 3 MB of memory to run optimally (cached).
Statistics about the work area used by this sort are placed in the bucket defined by
LOW_OPTIMAL_SIZE = 2097152 (2 MB) and HIGH_OPTIMAL_SIZE = 4194303 (4 MB
minus 1 byte), because 3 MB falls within that range of optimal sizes. Statistics are
segmented by work area size, because the performance impact of running a work area
in optimal, one-pass or multi-pass mode depends mainly on the size of that work area.
SELECT LOW_OPTIMAL_SIZE/1024 low_kb,
(HIGH_OPTIMAL_SIZE+1)/1024 high_kb,
OPTIMAL_EXECUTIONS, ONEPASS_EXECUTIONS, MULTIPASSES_EXECUTIONS
FROM GV$SQL_WORKAREA_HISTOGRAM
WHERE TOTAL_EXECUTIONS != 0
“LOW_KB” “HIGH_KB” “OPTIMAL_EXECUTIONS” “ONEPASS_EXECUTIONS” “MULTIPASSES_EXECUTIONS”
“2″ “4″ “7654062″ “0″ “0″
“64″ “128″ “411311″ “0″ “0″
“128″ “256″ “1545021″ “2″ “0″
“256″ “512″ “746672″ “20″ “0″
“512″ “1024″ “2396131″ “2588″ “0″
“1024″ “2048″ “380986″ “11313″ “104″
“2048″ “4096″ “80924″ “14659″ “2113″
“4096″ “8192″ “47235″ “18510″ “9951″
“8192″ “16384″ “26254″ “19324″ “10765″
“16384″ “32768″ “11238″ “13712″ “16807″
“32768″ “65536″ “6724″ “5606″ “7701″
“65536″ “131072″ “3590″ “9058″ “3688″
“131072″ “262144″ “2006″ “9863″ “1929″
“262144″ “524288″ “914″ “4161″ “1443″
“524288″ “1048576″ “81″ “1481″ “30″
“1048576″ “2097152″ “3″ “284″ “191″
“2097152″ “4194304″ “0″ “78″ “48″
“4194304″ “8388608″ “94″ “54″ “0″
“8388608″ “16777216″ “0″ “36″ “1″ >> seems to be bad as it needs more 16GB for work area where PGA was 6 GB
“16777216″ “33554432″ “0″ “4″ “0″
“33554432″ “67108864″ “0″ “0″ “1″ >> seems to be bad as it needs more 33GB for work area where PGA was 6 GB
“2″ “4″ “6979357″ “0″ “0″
“64″ “128″ “112252″ “0″ “0″
“128″ “256″ “33750″ “0″ “0″
“256″ “512″ “37511″ “0″ “0″
“512″ “1024″ “243631″ “2″ “0″
“1024″ “2048″ “126156″ “19″ “0″
“2048″ “4096″ “7061″ “63″ “0″
“4096″ “8192″ “7780″ “316″ “4″
“8192″ “16384″ “1466″ “148″ “2″
“16384″ “32768″ “1010″ “14″ “0″
“32768″ “65536″ “99″ “39″ “0″
“65536″ “131072″ “69″ “37″ “0″
“131072″ “262144″ “47″ “53″ “0″
“262144″ “524288″ “911″ “532″ “0″
“524288″ “1048576″ “0″ “37″ “0″
“1048576″ “2097152″ “0″ “18″ “0″
“2097152″ “4194304″ “0″ “2″ “0″
“4194304″ “8388608″ “0″ “129″ “0″
“8388608″ “16777216″ “0″ “86″ “0″
“2″ “4″ “7773737″ “0″ “0″
“64″ “128″ “405278″ “0″ “0″
“128″ “256″ “2073511″ “9″ “0″
“256″ “512″ “1075082″ “35″ “0″
“512″ “1024″ “2772341″ “5114″ “0″
“1024″ “2048″ “398772″ “9882″ “4″
“2048″ “4096″ “79350″ “17464″ “3944″
“4096″ “8192″ “45323″ “21829″ “8454″
“8192″ “16384″ “26425″ “30496″ “12207″
“16384″ “32768″ “10896″ “26602″ “21948″
“32768″ “65536″ “2960″ “6686″ “8028″
“65536″ “131072″ “2267″ “11674″ “3139″
“131072″ “262144″ “1913″ “10035″ “1012″
“262144″ “524288″ “522″ “6495″ “2379″
“524288″ “1048576″ “2″ “1567″ “68″
“1048576″ “2097152″ “0″ “285″ “58″
“2097152″ “4194304″ “0″ “81″ “0″
“4194304″ “8388608″ “0″ “7″ “0″
“8388608″ “16777216″ “0″ “40″ “0″
“33554432″ “67108864″ “0″ “1″ “0″
“2″ “4″ “5383694″ “0″ “0″
“64″ “128″ “114682″ “0″ “0″
“128″ “256″ “40738″ “1″ “0″
“256″ “512″ “51120″ “5″ “0″
“512″ “1024″ “314845″ “5″ “0″
“1024″ “2048″ “109685″ “63″ “0″
“2048″ “4096″ “7385″ “59″ “0″
“4096″ “8192″ “8773″ “169″ “2″
“8192″ “16384″ “2146″ “165″ “0″
“16384″ “32768″ “2594″ “34″ “0″
“32768″ “65536″ “468″ “62″ “0″
“65536″ “131072″ “77″ “36″ “0″
“131072″ “262144″ “46″ “37″ “0″
“262144″ “524288″ “1043″ “352″ “0″
“524288″ “1048576″ “0″ “12″ “6″
“1048576″ “2097152″ “0″ “5″ “25″
“2097152″ “4194304″ “0″ “2″ “0″
>>> Querying V$SQL_WORKAREA_HISTOGRAM: Percent Optimal
You can also use V$SQL_WORKAREA_HISTOGRAM to find the percentage of times work
areas were executed in optimal, one-pass, or multi-pass mode since startup. This query
only considers work areas of a certain size, with an optimal memory requirement of at least 64 KB.
SELECT optimal_count, round(optimal_count*100/total, 2) optimal_perc, onepass_count, round(onepass_count*100/total, 2) onepass_perc,
multipass_count, round(multipass_count*100/total, 2) multipass_perc
FROM
(SELECT decode(sum(total_executions), 0, 1, sum(total_executions)) total,
sum(OPTIMAL_EXECUTIONS) optimal_count,
sum(ONEPASS_EXECUTIONS) onepass_count,
sum(MULTIPASSES_EXECUTIONS) multipass_count
FROM Gv$sql_workarea_histogram
WHERE low_optimal_size >= 64*1024);
“OPTIMAL_COUNT” “OPTIMAL_PERC” “ONEPASS_COUNT” “ONEPASS_PERC” “MULTIPASS_COUNT” “MULTIPASS_PERC”
“13779324″ “97.33″ “261887″ “1.85″ “116077″ “0.82″
This result shows that 97.33% of these work areas have been able to run using an
optimal amount of memory. The rest (1.85%) ran one-pass AND 0.82% ran multi-pass. Such behavior is preferable, for the following reasons:
¦ Multi-pass mode can severely degrade performance. A high number of multi-pass work areas has an exponentially adverse effect on the response time of its
associated SQL operator.
¦ Running one-pass does not require a large amount of memory; only 22 MB is required to sort 1 GB of data in one-pass mode.
>>> V$SQL_WORKAREA_ACTIVE You can use this view to display the work areas that are
active (or executing) in the instance. Small active sorts (under 64 KB) are excluded
from the view. Use this view to precisely monitor the size of all active work areas and
to determine if these active work areas spill to a temporary segment
SELECT INST_ID,to_number(decode(SID, 65535, NULL, SID)) sid,
operation_type OPERATION,
trunc(EXPECTED_SIZE/1024) ESIZE,
trunc(ACTUAL_MEM_USED/1024) MEM,
trunc(MAX_MEM_USED/1024) “MAX MEM”,
NUMBER_PASSES PASS,
trunc(TEMPSEG_SIZE/1024) TSIZE
FROM GV$SQL_WORKAREA_ACTIVE
ORDER BY 1,2;
Column ESIZE indicates the maximum amount of memory that the PGA memory manager expects the operation to use
V$SQL_WORKAREA Oracle Database maintains cumulative work area statistics for each
loaded cursor whose execution plan uses one or more work areas. Every time a work area is deallocated, the V$SQL_WORKAREA table is updated with execution statistics for
that work area.
V$SQL_WORKAREA can be joined with V$SQL to relate a work area to a cursor. It can even be joined to V$SQL_PLAN to precisely determine which operator in the plan uses a work
area.
———-
Querying V$SQL_WORKAREA
———-
The following query finds the top 10 work areas requiring most cache memory:
SELECT *
FROM (SELECT workarea_address, operation_type, policy, estimated_optimal_size/(1024*1024*1024) estimated_optimal_size_gb
FROM V$SQL_WORKAREA
ORDER BY estimated_optimal_size DESC)
WHERE ROWNUM <= 10;
“WORKAREA_ADDRESS” “OPERATION_TYPE” “POLICY” “ESTIMATED_OPTIMAL_SIZE_GB”
“000000074B5675F8″ “SORT (v2)” “AUTO” “408.9348907470703125″
“0000000724978D70″ “SORT (v2)” “AUTO” “291.12615966796875″
“000000031E5445E8″ “SORT (v2)” “AUTO” “6.77559947967529296875″
“000000074113D3B8″ “GROUP BY (HASH)” “AUTO” “1.99999904632568359375″
“00000005E2ED0998″ “GROUP BY (HASH)” “AUTO” “1.99999904632568359375″
“0000000347ECF5C8″ “HASH-JOIN” “AUTO” “1.99999904632568359375″
“0000000347ECF630″ “GROUP BY (HASH)” “AUTO” “1.99999904632568359375″
“0000000347ECF698″ “GROUP BY (HASH)” “AUTO” “1.99999904632568359375″
“00000007488A3560″ “GROUP BY (HASH)” “AUTO” “1.99999904632568359375″
“000000031E544310″ “HASH-JOIN” “AUTO” “1.99999904632568359375″
>> WHERE > ESTIMATED_OPTIMAL_SIZE > Estimated size (in bytes) required by this work area to execute the operation completely in memory (optimal execution). Derived from either optimizer statistics or previous executions.
The following query finds the cursors with one or more work areas that have been executed in one or even multiple passes:
col sql_text format A80 wrap
SELECT sql_text, sum(ONEPASS_EXECUTIONS) onepass_cnt,
sum(MULTIPASSES_EXECUTIONS) mpass_cnt
FROM GV$SQL s, GV$SQL_WORKAREA wa
WHERE s.address = wa.address
GROUP BY sql_text
HAVING sum(ONEPASS_EXECUTIONS+MULTIPASSES_EXECUTIONS)>0
ORDER BY mpass_cnt DESC
Using the hash value and address of a particular cursor, the following query displays the cursor execution plan, including information about the associated work areas.
col “O/1/M” format a10
col name format a20
SELECT operation, options, object_name name, trunc(bytes/1024/1024) “input(MB)”,
trunc(last_memory_used/1024) last_mem,
trunc(estimated_optimal_size/1024) optimal_mem,
trunc(estimated_onepass_size/1024) onepass_mem,
decode(optimal_executions, null, null,
optimal_executions||’/'||onepass_executions||’/'||
multipasses_executions) “O/1/M”
FROM V$SQL_PLAN p, V$SQL_WORKAREA w WHERE p.address=w.address(+)
AND p.hash_value=w.hash_value(+)
AND p.id=w.operation_id(+)
AND p.address=’88BB460C’
AND p.hash_value=3738161960;
OPERATION OPTIONS NAME input(MB) LAST_MEM OPTIMAL_ME ONEPASS_ME O/1/M
———— ——– ——– ——— ——– ———- ———- ——
SELECT STATE HASH GROUP BY 4582 8 16 16 16/0/0
HASH JOIN SEMI 4582 5976 5194 2187 16/0/0
TABLE ACCESS FULL ORDERS 51 TABLE ACCESS FUL LINEITEM 1000
You can get the address and hash value from the V$SQL view by specifying a pattern in the query. For example:
SELECT address, hash_value FROM GV$SQL
WHERE sql_text LIKE ‘%insert /*+ parallel(ROS_INSTRUMENT,24) parallel(ROS_INSTRUMENT,24) APPEND NOLOGGING */ FIRST WHEN SK_ROS_INSTRUMENT_ID <= 4435937885%’;
———————
V$PGA_TARGET_ADVICE This view predicts how the statistics cache hit percentage
and over allocation count in V$PGASTAT will be impacted if you change the value of the initialization parameter PGA_AGGREGATE_TARGET
>>> DBA_HIST_PGA_TARGET_ADVICE
———————
SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024) target_mb,
ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
ESTD_OVERALLOC_COUNT
FROM V$PGA_TARGET_ADVICE;
SQL> SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024) target_mb,
ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
ESTD_OVERALLOC_COUNT
FROM V$PGA_TARGET_ADVICE;
2 3 4
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
———- ————– ——————–
768 46 37610
1536 46 37610
3072 47 24077
4608 63 7592
6144 77 1704 >>> where we are >>>
7373 84 105
8602 86 52
9830 88 6
11059 89 2
12288 90 0
18432 92 0
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
———- ————– ——————–
24576 92 0
36864 92 0
49152 92 0
14 rows selected.
SQL> alter system set pga_aggregate_target=8G scope=both;
System altered.
SQL> SELECT round(PGA_TARGET_FOR_ESTIMATE/1024/1024) target_mb,
ESTD_PGA_CACHE_HIT_PERCENTAGE cache_hit_perc,
ESTD_OVERALLOC_COUNT
FROM V$PGA_TARGET_ADVICE;
2 3 4
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
———- ————– ——————–
1024 100 0
2048 100 0
4096 100 0
6144 100 0
8192 100 0
9830 100 0
11469 100 0
13107 100 0
14746 100 0
16384 100 0
24576 100 0
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT
———- ————– ——————–
32768 100 0
49152 100 0
65536 100 0
14 rows selected.
——————-
V$PGA_TARGET_ADVICE_HISTOGRAM
——————-
This view predicts how the statistics displayed by
the performance view V$SQL_WORKAREA_HISTOGRAM will be impacted if you change the
value of the initialization parameter PGA_AGGREGATE_TARGET. You can use the dynamic
view V$PGA_TARGET_ADVICE_HISTOGRAM to view detailed information on the predicted number of optimal, one-pass and multi-pass work area executions for the set of PGA_
AGGREGATE_TARGET values you use for the prediction. The V$PGA_TARGET_ADVICE_HISTOGRAM view is identical to the V$SQL_WORKAREA_
HISTOGRAM view, with two additional columns to represent the PGA_AGGREGATE_TARGET
values used for the prediction. Therefore, any query executed against the V$SQL_
WORKAREA_HISTOGRAM view can be used on this view, with an additional predicate to
select the desired value of PGA_AGGREGATE_TARGET
SELECT LOW_OPTIMAL_SIZE/1024 low_kb, (HIGH_OPTIMAL_SIZE+1)/1024 high_kb,
estd_optimal_executions estd_opt_cnt,
estd_onepass_executions estd_onepass_cnt,
estd_multipasses_executions estd_mpass_cnt
FROM v$pga_target_advice_histogram
WHERE pga_target_factor = 2
AND estd_total_executions != 0
ORDER BY 1;
LOW_KB HIGH_KB ESTD_OPT_CNT ESTD_ONEPASS_CNT ESTD_MPASS_CNT
———- ———- ———— —————- ————–
2 4 946 0 0
64 128 419 0 0
128 256 364 0 0
256 512 8641 0 0
512 1024 23 0 0
1024 2048 235 0 0
4096 8192 1 0 0
7 rows selected.
Ex:
The output of this query might look like the following.
LOW_KB HIGH_KB ESTD_OPTIMAL_CNT ESTD_ONEPASS_CNT ESTD_MPASS_CNT
—— ——- —————- —————- ————–
8 16 156107 0 0
16 32 148 0 0
32 64 89 0 0
64 128 13 0 0
128 256 58 0 0
256 512 10 0 0
512 1024 653 0 0
1024 2048 530 0 0
2048 4096 509 0 0
4096 8192 227 0 0
8192 16384 176 0 0
16384 32768 133 16 0
32768 65536 66 103 0
65536 131072 15 47 0
131072 262144 0 48 0 >>> all optimal
262144 524288 0 23 0
The output shows that increasing PGA_AGGREGATE_TARGET by a factor of 2 will allow all work areas under 16 MB to execute in optimal mode.
V$SYSSTAT and V$SESSTAT
Statistics in the V$SYSSTAT and V$SESSTAT views show the total number of work areas
executed with optimal memory size, one-pass memory size, and multi-pass memory size. These statistics are cumulative since the instance or the session was started.
The following query gives the total number and the percentage of times work areas
were executed in these three modes since the instance was started:
SELECT name profile, cnt, decode(total, 0, 0, round(cnt*100/total)) percentage
FROM (SELECT name, value cnt, (sum(value) over ()) total
FROM V$SYSSTAT WHERE name like ‘workarea exec%’);
The output of this query might look like the following:
SQL> SELECT name profile, cnt, decode(total, 0, 0, round(cnt*100/total)) percentage
FROM (SELECT name, value cnt, (sum(value) over ()) total
FROM V$SYSSTAT WHERE name like ‘workarea exec%’); 2 3
PROFILE CNT
—————————————————————- ———-
PERCENTAGE
———-
workarea executions – optimal 13345463
99
workarea executions – onepass 112545
1
workarea executions – multipass 55374
0
——————
DBA_HIST_SQL_WORKAREA_HSTGRM
——————
SELECT optimal_count, round(optimal_count*100/total, 2) optimal_perc, onepass_count, round(onepass_count*100/total, 2) onepass_perc,
multipass_count, round(multipass_count*100/total, 2) multipass_perc
FROM
(SELECT decode(sum(total_executions), 0, 1, sum(total_executions)) total,
sum(OPTIMAL_EXECUTIONS) optimal_count,
sum(ONEPASS_EXECUTIONS) onepass_count,
sum(MULTIPASSES_EXECUTIONS) multipass_count
FROM DBA_HIST_SQL_WORKAREA_HSTGRM
WHERE low_optimal_size >= 64*1024);
—————
PGA usage statistics:
—————
select * from v$pgastat;
—————
Determine a good setting for pga_aggregate_target:
—————
select * from v$pga_target_advice order by pga_target_for_estimate;
—————
Show the maximum PGA usage per process:
—————
select max(pga_used_mem), max(pga_alloc_mem), max(pga_max_mem) from v$process