Skip to Main Content
  • Questions
  • PGA:sortarea and temporary tablespace.

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: April 29, 2007 - 8:56 pm UTC

Last updated: July 02, 2007 - 9:18 am UTC

Version: 10.2.0.2

Viewed 1000+ times

You Asked

Greetings ,Mr. Tom.

I love your site and you .....
A question ,please
I know when I set pga_aggregate_target to not 0,oracle will auto adjust the pga memory......,my question is:
Say my db server: RAM =16G SGA=6G pga_aggregate_target =4G
As these is some big sort using alot of space of sort_area......
I want to know when pga_aggregate_target reach 4G,and sorting continued.. what will
oracle do? does it get more memory from OS?and till to geting all of rest 6G memory for sorting ?if the memory still not enogh ,then use temporay tablespace for sorting? yes?
If not,when will oracle using temporay tablespace instead of extend sort_area size from RAM.
Thanks a lot!
Best Regards!
Alan



and Tom said...

https://www.oracle.com/technetwork/issue-archive/2007/07-mar/o27asktom-084983.html

see last article there for a bit of information.


the pga aggregate target is used to set a "soft" (exceedable) limit for dynamic memory allocated by processes (sort areas, hash area, program variables and the like).


It is a system wide setting, and this quote from Expert Oracle Database Architecture describes it:

<quote>
Automatic PGA Memory Management

Starting with Oracle9i, Release 1, a new way to manage PGA memory was introduced that avoids using the SORT_AREA_SIZE, BITMAP_MERGE_AREA_SIZE, and HASH_AREA_SIZE Parameters. It was introduced to attempt to address a few issues:

* Ease of use: Much confusion surrounded how to set the proper *_AREA_SIZE parameters. There was also much confusion over how those parameters actually worked and how memory was allocated.

* Manual allocation was a ¿one-size-fits-all¿ method: Typically as the number of users running similar applications against a database went up, the amount of memory used for sorting/hashing went up linearly as well. If 10 concurrent users with a sort area size of 1MB used 10MB of memory, 100 concurrent users would probably use 100MB, 1,000 would probably use 1000MB, and so on. Unless the DBA was sitting at the console continually adjusting the sort/hash area size settings, everyone would pretty much use the same values all day long. Consider the previous example, where you saw for yourself how the physical I/O to temp decreased as the amount of RAM we allowed ourselves to use went up. If you run that example for yourself, you will almost certainly see a decrease in response time as the amount of RAM available for sorting increases. Manual allocation fixes the amount of memory to be used for sorting at a more or less constant number, regardless of how much memory is actually available. Automatic memory management allows us to use the memory when it is available; it dynamically adjusts the amount of memory we use based on the workload.

* Memory control: As a result of the previous point, it was hard, if not impossible, to keep the Oracle instance inside a ¿box¿ memory-wise. You could not control the amount of memory the instance was going to use, as you had no real control over the number of simultaneous sorts/hashes taking place. It was far too easy to use more real memory (actual physical free memory) than was available on the machine.


Enter automatic PGA memory management. Here, you first simply set up and size the SGA. The SGA is a fixed-size piece of memory, so you can very accurately see how big it is, and that will be its total size (until and if you change that). You then tell Oracle, ¿This is how much memory you should try to limit yourself across all workareas¿a new umbrella term for the sorting and hashing areas you use.¿ Now, you could in theory take a machine with 2GB of physical memory and allocate 768MB of memory to the SGA and 768MB of memory to the PGA, leaving 512MB of memory for the OS and other processes. I say ¿in theory¿ because it doesn¿t work exactly that cleanly, but it¿s close. Before I discuss why that is true, we¿ll take a look at how to set up automatic PGA memory management and turn it on.

The process to set this up involves deciding on the proper values for two instance initialization parameters, namely

* WORKAREA_SIZE_POLICY: This parameter may be set to either MANUAL, which will use the sort area and hash area size parameters to control the amount of memory allocated, or AUTO, in which case the amount of memory allocated will vary based on the current workload present in the database. The default and recommended value is AUTO.

* PGA_AGGREGATE_TARGET: This parameter controls how much memory the instance should allocate, in total, for all workareas used to sort/hash data. Its default value varies by version and may be set by various tools such as the DBCA. In general, if you are using automatic PGA memory management, you should explicitly set this parameter.

So, assuming that WORKAREA_SIZE_POLICY is set to AUTO, and PGA_AGGREGATE_TARGET has a nonzero value, you will be using the new automatic PGA memory management. You can ¿turn it on" in your session via the ALTER SESSION command or at the system level via the ALTER SESSION command.
</quote>


If you set yours to 4gb - then the database will try keep PGA memory allocations under that. It does this by only giving each session some small percentage of the allowed PGA - eg: about 5% or less. So, a single session would not monopolize all of the pga, but rather gets a bit of it.

And if your session exceeds that - it is just like exceeding the sort area size - it'll spill into temp.

Consider the pga aggregate target a way to have the sort area size dynamically set and reset itself as the load on the system goes up and down over time.


Rating

  (11 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

But be careful!!

A reader, May 02, 2007 - 6:07 am UTC

In case of Shared Server Architecture, the PGA_AGGREGATE_TARGET is ignored. It is only used when the database is in Dedicated mode.
Tom Kyte
May 02, 2007 - 9:07 am UTC

in 9i, but not so in 10g.

A reader, May 08, 2007 - 10:25 pm UTC

Thanks Tom!
You said above:
And if your session exceeds that - it is just like exceeding the sort area size - it'll spill into temp.

But in another thread¿sorry I can't find it) ¿you said the total PGA size can exceed the pga_target_size because of a larging sorting...
I think big sorting will used the left os RAM not temp ts.
Sorry ,But I am quite confusing.
Waiting for your aply.
Regards.
Alan
Tom Kyte
May 11, 2007 - 9:24 am UTC

if your SESSION exceeds the dynamic memory allocated to it, it'll spill to temp.


if the sum(sessions dynamic work areas) exceed the pga aggregate target - well, that is all you can say - they exceeded your target.

sessions spill into temp individually.

A reader, May 08, 2007 - 10:26 pm UTC

Thanks Tom!
You said above:
And if your session exceeds that - it is just like exceeding the sort area size - it'll spill into temp.

But in another thread¿sorry I can't find it) ¿you said the total PGA size can exceed the pga_target_size because of a large sorting...
I think big sorting will used the left os RAM not temp ts.
Sorry ,But I am quite confusing.
Waiting for your aply.
Regards.
Alan

size of pga_aggregate_target

Branka, May 31, 2007 - 10:52 am UTC

How to know if size of pga_aggregate_target in my database is good? (oracle 9i)

I run selects below:
select name,value from v$sysstat where name like 'workarea executions%';


NAME VALUE
------------------------------ ----------
workarea executions - optimal 19334639
workarea executions - onepass 174
workarea executions - multipass 0

select * from v$pgastat;

NAME VALUE UNIT
---------------------------------------- ---------- ------------
aggregate PGA target parameter 1048576000 bytes
aggregate PGA auto target 898080768 bytes
global memory bound 52428800 bytes
total PGA inuse 50969600 bytes
total PGA allocated 101782528 bytes
maximum PGA allocated 205692928 bytes
total freeable PGA memory 16711680 bytes
PGA memory freed back to OS 2.3360E+10 bytes
total PGA used for auto workareas 24576 bytes
maximum PGA used for auto workareas 84390912 bytes
total PGA used for manual workareas 0 bytes
maximum PGA used for manual workareas 0 bytes
over allocation count 0
bytes processed 1.9707E+11 bytes
extra bytes read/written 9.1902E+10 bytes
cache hit percentage 68.19 percent

select round(pga_target_for_estimate/1024/1024) as target_size_MB,
bytes_processed,estd_extra_bytes_rw as est_rw_extra_bytes,
estd_pga_cache_hit_percentage as est_hit_pct,
estd_overalloc_count as est_overalloc
from v$pga_target_advice

TARGET_SIZE_MB BYTES_PROCESSED EST_RW_EXTRA_BYTES EST_HIT_PCT EST_OVERALLOC
-------------- --------------- ------------------ ----------- ---------
125 3.4378E+10 3.1062E+10 53 0
250 3.4378E+10 3.0998E+10 53 0
500 3.4378E+10 3.0998E+10 53 0
750 3.4378E+10 3.0998E+10 53 0
1000 3.4378E+10 8768714752 80 0
1200 3.4378E+10 8737902592 80 0
1400 3.4378E+10 8737902592 80 0
1600 3.4378E+10 8737902592 80 0
1800 3.4378E+10 8737902592 80 0
2000 3.4378E+10 8737902592 80 0
3000 3.4378E+10 8737902592 80 0
4000 3.4378E+10 8737902592 80 0
6000 3.4378E+10 8737902592 80 0
8000 3.4378E+10 8737902592 80 0

I also don¿t know why cache hit percentage is only 68.19 percent

Tom Kyte
May 31, 2007 - 10:55 am UTC

use statspack, it'll have a nice report for you with recommendations.

using a fixed width font so you can read it :)

pga_agregate_target

Branka, May 31, 2007 - 11:45 am UTC

Here is Statspack result. It seam that size iz OK, but Estd PGA Cache Hit % is 80.0. Why is that?


PGA Aggr Target Stats for DB: PACRP Instance: PACRP Snaps: 827 -828
-> B: Begin snap E: End snap (rows dentified with B or E contain data
which is absolute i.e. not diffed over the interval)
-> PGA cache hit % - percentage of W/A (WorkArea) data processed only in-memory
-> Auto PGA Target - actual workarea memory target
-> W/A PGA Used - amount of memory used for all Workareas (manual + auto)
-> %PGA W/A Mem - percentage of PGA memory allocated to workareas
-> %Auto W/A Mem - percentage of workarea memory controlled by Auto Mem Mgmt
-> %Man W/A Mem - percentage of workarea memory under manual control

PGA Cache Hit % W/A MB Processed Extra W/A MB Read/Written
--------------- ---------------- -------------------------
100.0 355 0

%PGA %Auto %Man
PGA Aggr Auto PGA PGA Mem W/A PGA W/A W/A W/A Global Mem
Target(M) Target(M) Alloc(M) Used(M) Mem Mem Mem Bound(K)
- --------- --------- ---------- ---------- ------ ------ ------ ----------
B 1,000 855 99.5 0.0 .0 .0 .0 51,200
E 1,000 850 105.0 0.0 .0 .0 .0 51,200
-------------------------------------------------------------

PGA Aggr Target Histogram for DB: PACRP Instance: PACRP Snaps: 827 -828
-> Optimal Executions are purely in-memory operations

Low High
Optimal Optimal Total Execs Optimal Execs 1-Pass Execs M-Pass Execs
------- ------- -------------- ------------- ------------ ------------
2K 4K 54,811 54,811 0 0
4K 8K 1,724 1,724 0 0
8K 16K 1,040 1,040 0 0
16K 32K 344 344 0 0
32K 64K 618 618 0 0
64K 128K 160 160 0 0
128K 256K 174 174 0 0
256K 512K 47 47 0 0
512K 1024K 84 84 0 0
1M 2M 6 6 0 0
-------------------------------------------------------------

PGA Memory Advisory for DB: PACRP Instance: PACRP End Snap: 828
-> When using Auto Memory Mgmt, minimally choose a pga_aggregate_target value
where Estd PGA Overalloc Count is 0

Estd Extra Estd PGA Estd PGA
PGA Target Size W/A MB W/A MB Read/ Cache Overalloc
Est (MB) Factr Processed Written to Disk Hit % Count
---------- ------- ---------------- ---------------- -------- ----------
125 0.1 33,461.6 29,623.4 53.0 0
250 0.3 33,461.6 29,561.8 53.0 0
500 0.5 33,461.6 29,561.8 53.0 0
750 0.8 33,461.6 29,561.8 53.0 0
1,000 1.0 33,461.6 8,362.5 80.0 0
1,200 1.2 33,461.6 8,333.1 80.0 0
1,400 1.4 33,461.6 8,333.1 80.0 0
1,600 1.6 33,461.6 8,333.1 80.0 0
1,800 1.8 33,461.6 8,333.1 80.0 0
2,000 2.0 33,461.6 8,333.1 80.0 0
3,000 3.0 33,461.6 8,333.1 80.0 0
4,000 4.0 33,461.6 8,333.1 80.0 0
6,000 6.0 33,461.6 8,333.1 80.0 0
8,000 8.0 33,461.6 8,333.1 80.0 0
-------------------------------------------------------------

Tom Kyte
May 31, 2007 - 2:19 pm UTC

man oh man.

*using a fixed width font* (eg: ala the CODE BUTTON)

I'm not even going to try to mentally line up these columns.


This however has prompted me to put in a change request for the asktom software. User supplied content is going to be entirely fixed width fonts again soon.

freeing memory,

A reader, May 31, 2007 - 12:10 pm UTC

I have heard that there is a Oracle package that can free up the memory (I guess it is PGA) that are filled up by stuff executed by the cursors.

What is that package? How does it work?

I have seen packages failing after sometime due to ORA-04030 error. Can we use this package during the execution to prevent memory related error?

Thanks,

Tom Kyte
May 31, 2007 - 2:19 pm UTC

if you have access to Expert One on One Oracle and or Expert Oracle database architecture, I cover that

and explain why it is a very good placebo sort of tool, makes some people feel better.

Shared/Dedicated Architecture in 10g

Sergey, June 01, 2007 - 8:36 am UTC

Dear Tom,

could you explain a little your response:
"Followup May 2, 2007 - 9am US/Eastern:
in 9i, but not so in 10g."
I haven't seen any changes about sort algorithm in 10g in Docu Library.
Thanks in advance.
Sergey

Tom Kyte
June 01, 2007 - 1:07 pm UTC

it is.

9i:
http://docs.oracle.com/docs/cd/B10501_01/server.920/a96533/memory.htm#43228

10g:
this space left blank. the caveat is not there..

pga_agregate_target

Branka, June 02, 2007 - 11:24 am UTC

Here is Statspack result. It seam that size iz OK, but Estd PGA Cache Hit % is 80.0. Why is that?
PGA Aggr Target Stats for DB: PACRP Instance: PACRP Snaps: 827 -828
-> B: Begin snap E: End snap (rows dentified with B or E contain data
which is absolute i.e. not diffed over the interval)
-> PGA cache hit % - percentage of W/A (WorkArea) data processed only in-memory
-> Auto PGA Target - actual workarea memory target
-> W/A PGA Used - amount of memory used for all Workareas (manual + auto)
-> %PGA W/A Mem - percentage of PGA memory allocated to workareas
-> %Auto W/A Mem - percentage of workarea memory controlled by Auto Mem Mgmt
-> %Man W/A Mem - percentage of workarea memory under manual control

PGA Cache Hit % W/A MB Processed Extra W/A MB Read/Written
--------------- ---------------- -------------------------
100.0 355 0

%PGA %Auto %Man
PGA Aggr Auto PGA PGA Mem W/A PGA W/A W/A W/A Global Mem
Target(M) Target(M) Alloc(M) Used(M) Mem Mem Mem Bound(K)
- --------- --------- ---------- ---------- ------ ------ ------ ----------
B 1,000 855 99.5 0.0 .0 .0 .0 51,200
E 1,000 850 105.0 0.0 .0 .0 .0 51,200
-------------------------------------------------------------

PGA Aggr Target Histogram for DB: PACRP Instance: PACRP Snaps: 827 -828
-> Optimal Executions are purely in-memory operations

Low High
Optimal Optimal Total Execs Optimal Execs 1-Pass Execs M-Pass Execs
------- ------- -------------- ------------- ------------ ------------
2K 4K 54,811 54,811 0 0
4K 8K 1,724 1,724 0 0
8K 16K 1,040 1,040 0 0
16K 32K 344 344 0 0
32K 64K 618 618 0 0
64K 128K 160 160 0 0
128K 256K 174 174 0 0
256K 512K 47 47 0 0
512K 1024K 84 84 0 0
1M 2M 6 6 0 0
-------------------------------------------------------------

PGA Memory Advisory for DB: PACRP Instance: PACRP End Snap: 828
-> When using Auto Memory Mgmt, minimally choose a pga_aggregate_target value
where Estd PGA Overalloc Count is 0
Estd PGA Cache Hit % is 80.0
Estd Extra Estd PGA Estd PGA
PGA Target Size W/A MB W/A MB Read/ Cache Overalloc
Est (MB) Factr Processed Written to Disk Hit % Count
---------- ------- ---------------- ---------------- -------- ----------
125 0.1 33,461.6 29,623.4 53.0 0
250 0.3 33,461.6 29,561.8 53.0 0
500 0.5 33,461.6 29,561.8 53.0 0
750 0.8 33,461.6 29,561.8 53.0 0
1,000 1.0 33,461.6 8,362.5 80.0 0
1,200 1.2 33,461.6 8,333.1 80.0 0
1,400 1.4 33,461.6 8,333.1 80.0 0
1,600 1.6 33,461.6 8,333.1 80.0 0
1,800 1.8 33,461.6 8,333.1 80.0 0
2,000 2.0 33,461.6 8,333.1 80.0 0
3,000 3.0 33,461.6 8,333.1 80.0 0
4,000 4.0 33,461.6 8,333.1 80.0 0
6,000 6.0 33,461.6 8,333.1 80.0 0
8,000 8.0 33,461.6 8,333.1 80.0 0

Tom Kyte
June 03, 2007 - 5:46 pm UTC

because the % column is a function of the prior two columns

c1/(c1+c2)

and c2 != 0....


pga_agregate_target

Branka, June 03, 2007 - 11:32 pm UTC

Would % change if I increase pga_agregate_target more?
Tom Kyte
June 05, 2007 - 7:51 am UTC

it says "no" up to 8,000 mb.

Dynamic Factor

Jagjeet Singh, June 04, 2007 - 4:16 pm UTC

Hi Tom,

You said ...

>Consider the pga aggregate target a way to have the sort area size dynamically set and reset itself as the load on the system goes up and down over time.

Here I want to ask what is dynamic here ? --
As per documentation, each session will get either 5% or 100mb which is less and it would be depend upon the value of PGA_AGG. When/what got reset when system goes up and down
over time.


Tom Kyte
June 06, 2007 - 12:37 pm UTC

at most 5% or .... (and that'll vary by release as they 'tweak' this over time)

it backs off the size of the allocated workareas as the amount of PGA in use goes up (if interested in an example and you have access to my book Expert Oracle Database Architecture - I have one in there that shows the amount of memory allocated to each sort as the number of users goes from small to large)

SERVER PROCESS

Deepak, June 26, 2007 - 8:50 am UTC

Hi,

Am running 9i DB on Solaris 9 (64bit). When I configure my database for shared server connection I can see one shared server UNIX process "s000" (whan used ps -ef) getting spawned.

Similarly please describe, how can I see a "dedicated" UNIX server process by exeuting "ps -ef" when a user is connected through sqlplus with the database.

Can we see dedicated server processes spawning when users connect to the database?

Please help.



Tom Kyte
July 02, 2007 - 9:18 am UTC

[tkyte@tkyte-pc ~]$ ps -aef | grep ora10gr2
ora10gr2  3726     1  0 08:55 ?        00:00:00 ora_pmon_ora10gr2
ora10gr2  3728     1  0 08:55 ?        00:00:00 ora_psp0_ora10gr2
ora10gr2  3730     1  0 08:55 ?        00:00:00 ora_mman_ora10gr2
ora10gr2  3732     1  0 08:55 ?        00:00:00 ora_dbw0_ora10gr2
ora10gr2  3734     1  0 08:55 ?        00:00:00 ora_lgwr_ora10gr2
ora10gr2  3736     1  0 08:55 ?        00:00:00 ora_ckpt_ora10gr2
ora10gr2  3738     1  0 08:55 ?        00:00:00 ora_smon_ora10gr2
ora10gr2  3740     1  0 08:55 ?        00:00:00 ora_reco_ora10gr2
ora10gr2  3742     1  0 08:55 ?        00:00:05 ora_mmon_ora10gr2
ora10gr2  3744     1  0 08:55 ?        00:00:00 ora_mmnl_ora10gr2
ora10gr2  3746     1  0 08:55 ?        00:00:00 ora_d000_ora10gr2
ora10gr2  3748     1  0 08:55 ?        00:00:00 ora_s000_ora10gr2
ora10gr2  3754     1  0 08:55 ?        00:00:00 ora_qmnc_ora10gr2
ora10gr2  3756     1  0 08:56 ?        00:00:01 ora_q000_ora10gr2
ora10gr2  3765     1  0 08:56 ?        00:00:00 ora_cjq0_ora10gr2
ora10gr2  3776     1  0 08:56 ?        00:00:00 ora_q001_ora10gr2
tkyte     3822  3711  0 09:16 pts/1    00:00:00 grep ora10gr2
[tkyte@tkyte-pc ~]$ sqlplus /

SQL*Plus: Release 10.2.0.2.0 - Production on Mon Jul 2 09:16:54 2007

Copyright (c) 1982, 2005, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
With the Partitioning, OLAP and Data Mining options

ops$tkyte%ORA10GR2> !ps -aef | grep ora10gr2
ora10gr2  3726     1  0 08:55 ?        00:00:00 ora_pmon_ora10gr2
ora10gr2  3728     1  0 08:55 ?        00:00:00 ora_psp0_ora10gr2
ora10gr2  3730     1  0 08:55 ?        00:00:00 ora_mman_ora10gr2
ora10gr2  3732     1  0 08:55 ?        00:00:00 ora_dbw0_ora10gr2
ora10gr2  3734     1  0 08:55 ?        00:00:00 ora_lgwr_ora10gr2
ora10gr2  3736     1  0 08:55 ?        00:00:00 ora_ckpt_ora10gr2
ora10gr2  3738     1  0 08:55 ?        00:00:00 ora_smon_ora10gr2
ora10gr2  3740     1  0 08:55 ?        00:00:00 ora_reco_ora10gr2
ora10gr2  3742     1  0 08:55 ?        00:00:05 ora_mmon_ora10gr2
ora10gr2  3744     1  0 08:55 ?        00:00:00 ora_mmnl_ora10gr2
ora10gr2  3746     1  0 08:55 ?        00:00:00 ora_d000_ora10gr2
ora10gr2  3748     1  0 08:55 ?        00:00:00 ora_s000_ora10gr2
ora10gr2  3754     1  0 08:55 ?        00:00:00 ora_qmnc_ora10gr2
ora10gr2  3756     1  0 08:56 ?        00:00:01 ora_q000_ora10gr2
ora10gr2  3765     1  0 08:56 ?        00:00:00 ora_cjq0_ora10gr2
ora10gr2  3776     1  0 08:56 ?        00:00:00 ora_q001_ora10gr2<b>
ora10gr2  3825  3824  0 09:16 ?        00:00:00 oracleora10gr2 (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))</b>
tkyte     3826  3824  0 09:17 pts/2    00:00:00 /bin/bash -c ps -aef | grep ora10gr2



it'll be that one in bold.