-
For OLTP
:
PGA_AGGREGATE_TARGET
= (total_mem
* 80%) * 20% -
For DSS
:
PGA_AGGREGATE_TARGET
= (total_mem
* 80%) * 50%
7.5 PGA Memory Management
The Program Global Area (PGA) is a private memory region containing data and control information for a server process. Access to it is exclusive to that server process and is read and written only by the Oracle code acting on behalf of it. An example of such information is the run-time area of a cursor. Each time a cursor is executed, a new run-time area is created for that cursor in the PGA memory region of the server process executing that cursor.
Note:
Part of the run-time area can be located in the SGA when using shared servers.
For complex queries (for example, decision support queries), a big portion of the run-time area is dedicated to work areas allocated by memory intensive operators, such as the following:
-
Sort-based operators, such as
ORDER
BY
,GROUP
BY
,ROLLUP
, and window functions -
Hash-join
-
Bitmap merge
-
Bitmap create
-
Write buffers used by bulk load operations
A sort operator uses a work area (the sort area) to perform the in-memory sort of a set of rows. Similarly, a hash-join operator uses a work area (the hash area) to build a hash table from its left input.
The size of a work area can be controlled and tuned. Generally, bigger work areas can significantly improve the performance of a particular operator at the cost of higher memory consumption. Ideally, the size of a work area is big enough that it can accommodate the input data and auxiliary memory structures allocated by its associated SQL operator. This is known as the optimal size of a work area. When the size of the work area is smaller than optimal, the response time increases, because an extra pass is performed over part of the input data. This is known as the one-pass size of the work area. Under the one-pass threshold, when the size of a work area is far too small compared to the input data size, multiple passes over the input data are needed. This could dramatically increase the response time of the operator. This is known as the multi-pass size of the work area. For example, a serial sort operation that needs to sort 10GB of data needs a little more than 10GB to run optimal and at least 40MB to run one-pass. If this sort gets less that 40MB, then it must perform several passes over the input data.
The goal is to have most work areas running with an optimal size (for example, more than 90% or even 100% for pure OLTP systems), while a smaller fraction of them are running with a one-pass size (for example, less than 10%). Multi-pass execution should be avoided. Even for DSS systems running large sorts and hash-joins, the memory requirement for the one-pass executions is relatively small. A system configured with a reasonable amount of PGA memory should not need to perform multiple passes over the input data.
Automatic PGA memory management simplifies and improves the way PGA memory is allocated. By default, PGA memory management is enabled. In this mode, Oracle dynamically adjusts the size of the portion of the PGA memory dedicated to work areas, based on 20% of the SGA memory size. The minimum value is 10MB.
Note:
For backward compatibility, automatic PGA memory management can be disabled by setting the value of the PGA_AGGREGATE_TARGET
initialization parameter to 0. When automatic PGA memory management is disabled, the maximum size of a work area can be sized with the associated _AREA_SIZE
parameter, such as the SORT_AREA_SIZE
initialization parameter.
See Oracle Database Reference for information on the PGA_AGGREGATE_TARGET
, SORT_AREA_SIZE
, HASH_AREA_SIZE
, BITMAP_MERGE_AREA_SIZE
and CREATE_BITMAP_AREA_SIZE
initialization parameters.
7.5.1 Configuring Automatic PGA Memory
When running under the automatic PGA memory management mode, sizing of work areas for all sessions becomes automatic and the *_AREA_SIZE
parameters are ignored by all sessions running in that mode. At any given time, the total amount of PGA memory available to active work areas in the instance is automatically derived from the PGA_AGGREGATE_TARGET
initialization parameter. This amount is set to the value of PGA_AGGREGATE_TARGET
minus the amount of PGA memory allocated by other components of the system (for example, PGA memory allocated by sessions). The resulting PGA memory is then assigned to individual active work areas, based on their specific memory requirements.
Under automatic PGA memory management mode, the main goal of Oracle is to honor the PGA_AGGREGATE_TARGET
limit set by the DBA, by controlling dynamically the amount of PGA memory allotted to SQL work areas. At the same time, Oracle tries to maximize the performance of all the memory-intensive SQL operations, by maximizing the number of work areas that are using an optimal amount of PGA memory (cache memory). The rest of the work areas are executed in one-pass mode, unless the PGA memory limit set by the DBA with the parameter PGA_AGGREGATE_TARGET
is so low that multi-pass execution is required to reduce even more the consumption of PGA memory and honor the PGA target limit.
When configuring a brand new instance, it is hard to know precisely the appropriate setting for PGA_AGGREGATE_TARGET
. You can determine this setting in three stages:
-
Make a first estimate for
PGA_AGGREGATE_TARGET
, based on a rule of thumb. By default, Oracle uses 20% of the SGA size. However, this initial setting may be too low for a large DSS system. -
Run a representative workload on the instance and monitor performance, using PGA statistics collected by Oracle, to see whether the maximum PGA size is under-configured or over-configured.
-
Tune
PGA_AGGREGATE_TARGET
, using Oracle PGA advice statistics.See Also:
Oracle Database Reference for information on thePGA_AGGREGATE_TARGET
initialization parameter
The following sections explain this in detail:
7.5.1.1 Setting PGA_AGGREGATE_TARGET Initially
The value of the PGA_AGGREGATE_TARGET
initialization parameter (for example 100000 KB, 2500 MB, or 50 GB) should be set based on the total amount of memory available for the Oracle instance. This value can then be tuned and dynamically modified at the instance level. Example 7-2 illustrates a typical situation.
Example 7-2 Initial Setting of PGA_AGGREGATE_TARGET
Assume that an Oracle instance is configured to run on a system with 4 GB of physical memory. Part of that memory should be left for the operating system and other non-Oracle applications running on the same hardware system. You might decide to dedicate only 80% (3.2 GB) of the available memory to the Oracle instance.
You must then divide the resulting memory between the SGA and the PGA.
-
For OLTP systems, the PGA memory typically accounts for a small fraction of the total memory available (for example, 20%), leaving 80% for the SGA.
-
For DSS systems running large, memory-intensive queries, PGA memory can typically use up to 70% of that total (up to 2.2 GB in this example).
Good initial values for the parameter PGA_AGGREGATE_TARGET
might be:
-
For OLTP
:
PGA_AGGREGATE_TARGET
= (total_mem
* 80%) * 20% -
For DSS
:
PGA_AGGREGATE_TARGET
= (total_mem
* 80%) * 50%where
total_mem
is the total amount of physical memory available on the system.
In this example, with a value of total_mem
equal to 4 GB, you can initially set PGA_AGGREGATE_TARGET
to 1600 MB for a DSS system and to 655 MB for an OLTP system.
7.5.1.2 Monitoring the Performance of the Automatic PGA Memory Management
Before starting the tuning process, you need to know how to monitor and interpret the key statistics collected by Oracle Database to help in assessing the performance of the automatic PGA memory management component. Several dynamic performance views are available for this purpose:
This view gives instance-level statistics on the PGA memory usage and the automatic PGA memory manager. For example:
SELECT * FROM V$PGASTAT;
The output of this query might look like the following:
NAME VALUE UNIT -------------------------------------------------------- ---------- ------------ aggregate PGA target parameter 41156608 bytes aggregate PGA auto target 21823488 bytes global memory bound 2057216 bytes total PGA inuse 16899072 bytes total PGA allocated 35014656 bytes maximum PGA allocated 136795136 bytes total freeable PGA memory 524288 bytes PGA memory freed back to OS 1713242112 bytes total PGA used for auto workareas 0 bytes maximum PGA used for auto workareas 2383872 bytes total PGA used for manual workareas 0 bytes maximum PGA used for manual workareas 8470528 bytes over allocation count 291 bytes processed 2124600320 bytes extra bytes read/written 39949312 bytes cache hit percentage 98.15 percent
The main statistics displayed in V$PGASTAT
are as follows:
-
aggregate PGA target parameter
: This is the current value of the initialization parameterPGA_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 can use for work areas running in automatic mode. This amount is dynamically derived from the value of the parameterPGA_AGGREGATE_TARGET
and the current work area workload. Hence, it is continuously adjusted by Oracle. If this value is small compared to the value ofPGA_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 inAUTO
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 ofPGA_AGGREGATE_TARGET
should probably be increased. -
total PGA allocated
: This gives the current amount of PGA memory allocated by the instance. Oracle tries to keep this number less than the value ofPGA_AGGREGATE_TARGET
. However, it is possible for the PGA allocated to exceed that value by a small percentage and for a short period of time, when the work area workload is increasing very rapidly or when the initialization parameterPGA_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 start-up. Over-allocating PGA memory can happen if the value ofPGA_AGGREGATE_TARGET
is too small to accommodate thePGA other
component in the previous equation plus the minimum memory required to execute the work area workload. When this happens, Oracle cannot honor the initialization parameterPGA_AGGREGATE_TARGET
, and extra PGA memory needs to be allocated. If over-allocation occurs, you should increase the value ofPGA_AGGREGATE_TARGET
using the information provided by the advice viewV$PGA_TARGET_ADVICE
. -
total bytes processed
: This is the number of bytes processed by memory-intensive SQL operators since instance start-up. For example, the number of byte processed is the input size for a sort operation. This number is used to compute thecache
hit
percentage
metric. -
extra bytes read/written
: When a work area cannot run optimally, one or more extra passes is performed over the input data.extra
bytes
read/written
represents the number of bytes processed during these extra passes since instance start-up. This number is also used to compute thecache
hit
percentage
. Ideally, it should be small compared tototal bytes processed
. -
cache hit percentage
: This metric is computed by Oracle Database to reflect the performance of the PGA memory component. It is cumulative from instance start-up. A value of 100% means that all work areas executed by the system since instance start-up have used an optimal amount of PGA memory. This is, of course, ideal but rarely happens except maybe for pure OLTP systems. In reality, some work areas run one-pass or even multi-pass, depending on the overall size of the PGA memory. When a work area cannot run optimally, one or more extra passes is performed over the input data. This reduces thecache
hit
percentage
in proportion to the size of the input data and the number of extra passes performed. Example 7-3 shows howcache
hit
percentage
is affected by extra passes.
Example 7-3 Calculating Cache Hit Percentage
Consider a simple example: Four sort operations have been executed, three were small (1 MB of input data) and one was bigger (100 MB of input data). The total number of bytes processed (BP
) by the four operations is 103 MB. If one of the small sorts runs one-pass, an extra pass over 1 MB of input data is performed. This 1 MB value is the number of extra
bytes
read/written
, or EBP
. The cache
hit
percentage
is calculated by the following formula:
BP x 100 / (BP + EBP)
The cache
hit
percentage
in this case is 99.03%, almost 100%. This value reflects the fact that only one of the small sorts had to perform an extra pass while all other sorts were able to run optimally. Hence, the cache
hit
percentage
is almost 100%, because this extra pass over 1 MB represents a tiny overhead. On the other hand, if the big sort is the one to run one-pass, then EBP is 100 MB instead of 1 MB, and the cache
hit
percentage
falls to 50.73%, because the extra pass has a much bigger impact.
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:
SELECT PROGRAM, PGA_USED_MEM, PGA_ALLOC_MEM, PGA_FREEABLE_MEM, PGA_MAX_MEM FROM V$PROCESS;
The output of this query might look like the following:
PROGRAM PGA_USED_MEM PGA_ALLOC_MEM PGA_FREEABLE_MEM PGA_MAX_MEM -------------------------------------- ------------ ------------- ---------------- ----------- PSEUDO 0 0 0 0 oracle@examp1690 (PMON) 314540 685860 0 685860 oracle@examp1690 (MMAN) 313992 685860 0 685860 oracle@examp1690 (DBW0) 696720 1063112 0 1063112 oracle@examp1690 (LGWR) 10835108 22967940 0 22967940 oracle@examp1690 (CKPT) 352716 710376 0 710376 oracle@examp1690 (SMON) 541508 948004 0 1603364 oracle@examp1690 (RECO) 323688 685860 0 816932 oracle@examp1690 (q001) 233508 585128 0 585128 oracle@examp1690 (QMNC) 314332 685860 0 685860 oracle@examp1690 (MMON) 885756 1996548 393216 1996548 oracle@examp1690 (MMNL) 315068 685860 0 685860 oracle@examp1690 (q000) 330872 716200 65536 716200 oracle@examp1690 (TNS V1-V3) 635768 928024 0 1255704 oracle@examp1690 (CJQ0) 533476 1013540 0 1144612 oracle@examp1690 (TNS V1-V3) 430648 812108 0 812108
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.
The columns CATEGORY
, ALLOCATED
, USED
, and MAX_ALLOCATED
can be used to dynamically monitor the PGA memory usage of Oracle processes for each of the six categories.
See Also:
Oracle Database Reference for more information on the V$PROCESS_MEMORY
view.
7.5.1.2.4 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 start-up. 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
.
Example 7-3 and Example 7-4 show two ways of using V$SQL_WORKAREA_HISTOGRAM
.
Example 7-4 Querying V$SQL_WORKAREA_HISTOGRAM: Non-empty Buckets
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.
The following query shows statistics for all non-empty buckets. Empty buckets are removed with the predicate where total_execution != 0
.
SELECT LOW_OPTIMAL_SIZE/1024 low_kb, (HIGH_OPTIMAL_SIZE+1)/1024 high_kb, OPTIMAL_EXECUTIONS, ONEPASS_EXECUTIONS, MULTIPASSES_EXECUTIONS FROM V$SQL_WORKAREA_HISTOGRAM WHERE TOTAL_EXECUTIONS != 0;
The result of the query might look like the following:
LOW_KB HIGH_KB OPTIMAL_EXECUTIONS ONEPASS_EXECUTIONS MULTIPASSES_EXECUTIONS ------ ------- ------------------ ------------------ ---------------------- 8 16 156255 0 0 16 32 150 0 0 32 64 89 0 0 64 128 13 0 0 128 256 60 0 0 256 512 8 0 0 512 1024 657 0 0 1024 2048 551 16 0 2048 4096 538 26 0 4096 8192 243 28 0 8192 16384 137 35 0 16384 32768 45 107 0 32768 65536 0 153 0 65536 131072 0 73 0 131072 262144 0 44 0 262144 524288 0 22 0
The query result shows that, in the 1024 KB to 2048 KB bucket, 551 work areas used an optimal amount of memory, while 16 ran in one-pass mode and none ran in multi-pass mode. It also shows that all work areas under 1 MB were able to run in optimal mode.
Example 7-5 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 start-up. 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 v$sql_workarea_histogram WHERE low_optimal_size > 64*1024);
The output of this query might look like the following:
OPTIMAL_COUNT OPTIMAL_PERC ONEPASS_COUNT ONEPASS_PERC MULTIPASS_COUNT MULTIPASS_PERC ------------- ------------ ------------- ------------ --------------- -------------- 2239 81.63 504 18.37 0 0
This result shows that 81.63% of these work areas have been able to run using an optimal amount of memory. The rest (18.37%) ran one-pass. None of them 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.
7.5.1.2.5 V$SQL_WORKAREA_ACTIVE
This view can be used 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. Example 7-6 shows a typical query of this view:
Example 7-6 Querying V$SQL_WORKAREA_ACTIVE
SELECT 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 V$SQL_WORKAREA_ACTIVE ORDER BY 1,2; The output of this query might look like the following: SID OPERATION ESIZE MEM MAX MEM PASS TSIZE --- ----------------- --------- --------- --------- ----- ------- 8 GROUP BY (SORT) 315 280 904 0 8 HASH-JOIN 2995 2377 2430 1 20000 9 GROUP BY (SORT) 34300 22688 22688 0 11 HASH-JOIN 18044 54482 54482 0 12 HASH-JOIN 18044 11406 21406 1 120000
This output shows that session 12 (column SID
) is running a hash-join having its work area running in one-pass mode (PASS
column). This work area is currently using 11406 KB of memory (MEM
column) and has used, in the past, up to 21406 KB of PGA memory (MAX
MEM
column). It has also spilled to a temporary segment of size 120000 KB. Finally, the column ESIZE
indicates the maximum amount of memory that the PGA memory manager expects this hash-join to use. This maximum is dynamically computed by the PGA memory manager according to workload.
When a work area is deallocated—that is, when the execution of its associated SQL operator is complete—the work area is automatically removed from the V$SQL_WORKAREA_ACTIVE
view.
Oracle 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.
Example 7-7 shows three typical queries on the V$SQL_WORKAREA
dynamic view:
Example 7-7 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 FROM V$SQL_WORKAREA ORDER BY estimated_optimal_size ) WHERE ROWNUM <= 10;
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 V$SQL s, V$SQL_WORKAREA wa WHERE s.address = wa.address GROUP BY sql_text HAVING sum(ONEPASS_EXECUTIONS+MULTIPASSES_EXECUTIONS)>0;
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 V$SQL WHERE sql_text LIKE '%my_pattern%';
7.5.1.3 Tuning PGA_AGGREGATE_TARGET
To help you tune the initialization parameter PGA_AGGREGATE_TARGET
, Oracle Database provides the V$PGA_TARGET_ADVICE
and V$PGA_TARGET_ADVICE_HISTOGRAM
views. By examining these views, you no longer need to use an empirical approach to tune the value of PGA_AGGREGATE_TARGET
. Instead, you can use these views to determine how key PGA statistics will be impacted if you change the value of PGA_AGGREGATE_TARGET
.
In both views, values of PGA_AGGREGATE_TARGET
used for the prediction are derived from fractions and multiples of the current value of that parameter, to assess possible higher and lower values. Values used for the prediction range from 10 MB to a maximum of 256 GB.
Oracle generates PGA advice performance views by recording the workload history and then simulating this history for different values of PGA_AGGREGATE_TARGET
. The simulation process happens in the background and continuously updates the workload history to produce the simulation result. You can view the result at any time by querying V$PGA_TARGET_ADVICE
or V$PGA_TARGET_ADVICE_HISTOGRAM
.
To enable automatic generation of PGA advice performance views, make sure the following parameters are set:
-
PGA_AGGREGATE_TARGET
, to enable automatic PGA memory management (see "Setting PGA_AGGREGATE_TARGET Initially"). -
STATISTICS_LEVEL
. Set this toTYPICAL
(the default) orALL
; setting this parameter toBASIC
turns off generation of PGA performance advice views.
The content of these PGA advice performance views is reset at instance startup or when PGA_AGGREGATE_TARGET
is altered.
Note:
Simulation cannot include all factors of real execution, so derived statistics may not exactly match up with real performance statistics. Always monitor the system after changing PGA_AGGREGATE_TARGET
to verify that the new performance is what you expect.
7.5.1.3.1 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
. Example 7-8 shows a typical query of this view.
Example 7-8 Querying V$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;
The output of this query might look like the following:
TARGET_MB CACHE_HIT_PERC ESTD_OVERALLOC_COUNT ---------- -------------- -------------------- 63 23 367 125 24 30 250 30 3 375 39 0 500 58 0 600 59 0 700 59 0 800 60 0 900 60 0 1000 61 0 1500 67 0 2000 76 0 3000 83 0 4000 85 0
The result of the this query can be plotted as shown in Figure 7-3:
Figure 7-3 Graphical Representation of V$PGA_TARGET_ADVICE
Description of "Figure 7-3 Graphical Representation of V$PGA_TARGET_ADVICE"
The curve shows how the PGA cache
hit
percentage
improves as the value of PGA_AGGREGATE_TARGET
increases. The shaded zone in the graph is the over
allocation
zone, where the value of the column ESTD_OVERALLOCATION_COUNT
is nonzero. It indicates that PGA_AGGREGATE_TARGET
is too small to even meet the minimum PGA memory needs. If PGA_AGGREGATE_TARGET
is set within the over
allocation
zone, the memory manager will over-allocate memory and actual PGA memory consumed will be more than the limit you set. It is therefore meaningless to set a value of PGA_AGGREGATE_TARGET
in that zone. In this particular example PGA_AGGREGATE_TARGET
should be set to at least 375 MB.
Note:
Although the theoretical maximum for the PGA cache
hit
percentage
is 100%, there is a practical limit on the maximum size of a work area, which may prevent this theoretical maximum from being reached, even if you further increase PGA_AGGREGATE_TARGET
. This should happen only in large DSS systems where the optimal memory requirement is large and might cause the value of the cache
hit
percentage
to taper off at a lower percentage, like 90%.
Beyond the over
allocation
zone, the value of the PGA cache
hit
percentage
increases rapidly. This is due to an increase in the number of work areas which run optimally or one-pass and a decrease in the number of multi-pass executions. At some point, around 500 MB in this example, an inflection in the curve corresponds to the point where most (probably all) work areas can run optimally or at least one-pass. After this inflection, the cache
hit
percentage
keeps increasing, though at a lower pace, up to the point where it starts to taper off and shows only slight improvement with increase in PGA_AGGREGATE_TARGET
. In Figure 7-3, this happens when PGA_AGGREGATE_TARGET
reaches 3 GB. At that point, the cache
hit
percentage
is 83% and only improves marginally (by 2%) with one extra gigabyte of PGA memory. In this example, 3 GB is probably the optimal value for PGA_AGGREGATE_TARGET
.
Ideally, PGA_AGGREGATE_TARGET
should be set at the optimal value, or at least to the maximum value possible in the region beyond the over
allocation
zone. As a rule of thumb, the PGA cache
hit
percentage
should be higher than 60%, because at 60% the system is almost processing double the number of bytes it actually needs to process in an ideal situation. Using this particular example, it makes sense to set PGA_AGGREGATE_TARGET
to at least 500 MB and as close as possible to 3 GB. But the right setting for the parameter PGA_AGGREGATE_TARGET
depends on how much memory can be dedicated to the PGA component. Generally, adding PGA memory requires reducing memory for some SGA components, like the shared pool or buffer cache, because the overall memory dedicated to the instance is often bound by the amount of physical memory available on the system. Thus, any decisions to increase PGA memory must be taken in the larger context of the available memory in the system and the performance of the various SGA components (which you monitor with shared pool advisory and buffer cache advisory statistics). If memory cannot be taken away from the SGA, consider adding physical memory to the system.
See Also:
"Shared Pool Advisory Statistics" and "Sizing the Buffer Cache"
7.5.1.3.2 How to Tune PGA_AGGREGATE_TARGET
You can use the following steps as a tuning guideline in tuning PGA_AGGREGATE_TARGET
:
-
Set
PGA_AGGREGATE_TARGET
so there is no memory over-allocation; avoid setting it in the over-allocation zone. In Example 7-8,PGA_AGGREGATE_TARGET
should be set to at least 375 MB. -
After eliminating over-allocations, aim at maximizing the PGA
cache
hit
percentage
, based on your response-time requirement and memory constraints. In Example 7-8, assume you have a limit X on memory you can allocate to PGA.-
If this limit X is beyond the optimal value, then you would set
PGA_AGGREGATE_TARGET
to the optimal value. After this point, the incremental benefit with higher memory allocation toPGA_AGGREGATE_TARGET
is very small. In Example 7-8, if you have 10 GB to dedicate to PGA, setPGA_AGGREGATE_TARGET
to 3 GB, the optimal value. The remaining 7 GB is dedicated to the SGA. -
If the limit X is less than the optimal value, then you would set
PGA_AGGREGATE_TARGET
to X. In Example 7-8, if you have only 2 GB to dedicate to PGA, setPGA_AGGREGATE_TARGET
to 2 GB and accept acache
hit
percentage
of 75%.
-
Finally, like most statistics collected by Oracle that are cumulative since instance start-up, you can take a snapshot of the view at the beginning and at the end of a time interval. You can then derive the predicted statistics for that time interval as follows:
estd_overalloc_count = (difference in estd_overalloc_count between the two snapshots)
(difference in bytes_processed between the two snapshots) estd_pga_cache_hit_percentage = ----------------------------------------------------------------- (difference in bytes_processed + extra_bytes_rw between the two snapshots )
7.5.1.3.3 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
.
Example 7-9 Querying V$PGA_TARGET_ADVICE_HISTOGRAM
The following query displays the predicted content of V$SQL_WORKAREA_HISTOGRAM
for a value of the initialization parameter PGA_AGGREGATE_TARGET
set to twice its current value.
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;
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 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.
See Also:
7.5.1.4 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:
PROFILE CNT PERCENTAGE ----------------------------------- ---------- ---------- workarea executions - optimal 5395 95 workarea executions - onepass 284 5 workarea executions - multipass 0 0
7.5.2 Configuring OLAP_PAGE_POOL_SIZE
The OLAP_PAGE_POOL_SIZE
initialization parameter specifies (in bytes) the maximum size of the paging cache to be allocated to an OLAP session.
For performance reasons, it is usually preferable to configure a small OLAP paging cache and set a larger default buffer pool with DB_CACHE_SIZE
. An OLAP paging cache of 4 MB is fairly typical, with 2 MB used for systems with limited memory.
See Also: