Wednesday, August 31, 2005
More PGA Memory management
Presumably its intended as yet more support for the Undocumented Secrets article on SearchOracle - though perhaps its a replacement for the various comments on Burleson Consulting related websites on the subject that have disappeared after being criticised.
Whatever its intention, I'm a little bemused by the whole disussion now. The current thrust of Don's arguments seems to be that you can increase the memory actually available to Oracle for sorts (presumably to avoid disk sorts) by setting some documented and undocumented parameters so that you can use really large sort areas, that is sort areas in the hundreds of megabytes or gigabytes. To me this begs the question as to whether you really wouldn't be better off concentrating on tuning the queries that create the requirements for these monster sorts. Typically you will see these in two situations.
First when the developer has missed, or wrongly coded, joins. Tuning wrong code is rather pointless here.
Second in large datawarehouse environments - in these I can't help but wonder if looking at materialized views, bitmap indexes and star transformations might be of more use. However as I don't do proper datawarehouses I could be off beam here.
In other words, whatever the merits of the various parameters, wouldn't it be better to ask why I think I need such large sorts in the first place.
Finally I attach some interesting output from a production 9206 database. You'll see that the pga_aggregate_target is set to 120m and the undocumented parameter untouched. There are no parallel queries (its OLTP as well). Somehow I still managed 16 optimal work area operations in the 256-512mb range. I don't have an explanation for this, but just wanted to add observation to all the words.
SQL> SELECT LOW_OPTIMAL_SIZE/1024 low_kb,
2 (HIGH_OPTIMAL_SIZE+1)/1024 high_kb,
3 optimal_executions, onepass_executions, multipasses_executions
4 FROM v$sql_workarea_histogram
5 WHERE total_executions != 0;
LOW_KB HIGH_KB OPTIMAL_EXECUTIONS ONEPASS_EXECUTIONS MULTIPASSES_EXECUTIONS
---------- ---------- ------------------ ------------------ ----------------------
16 32 9077203 0 0
32 64 81237 0 0
64 128 14718 48 0
128 256 9252 0 0
256 512 8479 24 0
512 1024 34921 40 0
1024 2048 18942 48 0
2048 4096 65558 120 0
4096 8192 2715 478 0
8192 16384 153 1061 0
16384 32768 88 758 0
32768 65536 32 362 0
65536 131072 88 345 16
131072 262144 12 24 16
262144 524288 16 0 0
524288 1048576 0 0 1
16 rows selected.
SQL> SELECT
2 a.ksppinm parameter,
3 a.ksppdesc description,
4 b.ksppstvl session_value,
5 c.ksppstvl instance_value
6 FROM
7 x$ksppi a,
8 x$ksppcv b,
9 x$ksppsv c
10 WHERE
11 a.indx = b.indx
12 AND a.indx = c.indx
13 AND substr(a.ksppinm,1,1) = '_'
14 and a.ksppinm like '%pga%'
15 /
PARAMETER DESCRIPTION
---------------------------------------------------------------- -------------------------------------------------------
---------
SESSION_VALUE
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
INSTANCE_VALUE
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
_pga_max_size Maximum size of the PGA memory for one process
209715200
209715200
1 row selected.
SQL> select name,value
2 from v$parameter
3 where name like '%pga%';
NAME
------------------------------
VALUE
------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------
pga_aggregate_target
125829120
1 row selected.
SQL>
alter session set workarea_size_policy = manual;
alter session set sort_area_size = 536870912;
This might be the sensible choice for (e.g.) recreating an index that had been dropped for a batch load.
Jonathan Lewis
Materialized views and query re-write can do to wonders to query performance, however COMPLETE refresh of materialized views (at least under Oracle 9.2) can produce the sort from hell as the whole table is rebuilt as a single select!
That's the most likely explanation, but
1. I can't remember doing this in any of the reports I 'tuned'. Doesn't mean I didn't mind.
2. The app is a database neutral app (which is to say developed for SQL*Server). Whilst this does mean CONNECT was granted - alter session seems all too specific.
3. It might imply I had competent users or developers. Some things ought never be admitted to :)
i'm very curious now though.
I always thought it was all sales for all time, except for those to inhabitants of the isle of man, ordered by inside leg measurement.
Niall
I should go to bed now right?
Maybe these undocumented parameters are just "suggestions" and the process is allowed to steal from the instance pga total?
A quote from Metalink Note: 223730.1
Oracle92 only:
(d) over allocation count: Over-allocating PGA memory can happen if the value of
PGA_AGGREGATE_TARGET is too small to accommodate the untunable PGA memory part plus
the minimum memory required to execute the work area workload. When this happens,
Oracle cannot honor the initialization parameter PGA_AGGREGATE_TARGET, and extra
PGA memory needs to be allocated. over allocation count is the number of time the
system was detected in this state since database startup. This count should ideally be
equal to zero.
From another metalink discussion an Oracle Employee says that:
PGA_AGGREGATE_TARGET represents the amount of private memory that Oracle *attempts* to stay below
I think that these can explain this behavior.
I am very interested to read more suggestions.
maximum PGA used for manual workareas
probably in the range of the 256M to 512M of your unexpected optimal workarea operation.
Jonathan Lewis
I was surprised to see a reprint on Don Burleson's site for one of my dba-village contribution...
Just to comment, I've seen such big sorts on datawarehouse environment when creating aggregated data.
Anyway, touching undocumented parameters is not required even in such cases, as disk sorts are not evil (if tempfiles are well implemented) and workarea policy can still be manual in those operations.
Note: a good paper about auto memory management:
>http://www.vldb.org/conf/2002/S29P03.pdf
Regards,
Franck Pachot