Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Robert.

Asked: August 12, 2002 - 10:11 am UTC

Last updated: February 22, 2006 - 10:13 am UTC

Version: 8.1.7.2

Viewed 1000+ times

You Asked

Morning Tom, I hope you don't mind my asking question in this forum about what I read in your book "Expert One-On_One"

Page 81, Line 7
"Even PL/SQL code...is managed in a paging mechanism....only the code
that is needed is loaded into the shared pool in small chunks"

I am quite confused about the "small chunks" reference....what exactly do you mean ?

We know it's a fact that the entire package is loaded into memory (SGA) when it's called.

So do you mean the whole pkg is NOT loaded directly into the shared pool but bits of code necessary to do the job is put into the pool ?

Thanks for the clarification
Robert

and Tom said...

we use 4k chunks to manage memory so the plsql code is loaded into the shared pool in little pieces -- so that all memory allocated in there is the same size more or less and can be reused by other things easily.

Suppose we didn't and you have procedures of various sizes:

1k
10k
100k
500k
1m


Now, we load up a bunch of 1k/10k procedures -- we need to load a 1m procedure but have run out of room. So, we flush as many loaded procedures as we can in the hopes of freeing up 1m of CONTIGOUS memory (this isn't the way we do it - assuming we did tho...). We probably cannot find 1m of contigous memory but we have lots of 1k and 10k chunks here and there that if you added them all up would be lots more then 1m.

So, by loading things into little pieces of say 4k -- when we goto load that 1m procedure, we can flush some of the 10k routines and get enough 4k chunks to hold our stuff.


So, instead of needing 1m of contigous memory for the package, we just need enough 4k chunks out there to hold it.

Rating

  (12 ratings)

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

Comments

Reader

A reader, August 13, 2002 - 12:08 am UTC

Tom,

Could you tell us the concept of Extents and Chunks in
shared pool. Is extent a contiguous space comprised of
multiple chunks by Forward coalescing mechanism of
adjacent free chunks.

Are the chunks connected by doubly linked list to previous
and next free chunk in the free list. Also if the memory is
managed in 4000 - 5000 bytes chunks, what sceanrio will
cause ORA 4031. According to the shared pool memory
management, Oracle can always allocate multiple chunks
if contiguous memory is not available

Thanks

Tom Kyte
August 13, 2002 - 8:24 am UTC

There is no concept of extents in the shared pool. extents are a "disk" thing.

Just think of the shared pool as a really big "heap". Like the heap managed by C using malloc, calloc, realloc and free. We just allocate memory in about 4k chunks and everyone that uses memory is used to having things managed that way. It is a method to decrease fragmentation (similar to the concept behind locally managed tablespaces -- all extents (eg: chunks) are either the same size or some very nice multiple of eachother and are hence very reusable -- no fragmentation)

4031 -- caused when we run out of shared pool memory, when all of the memory is being used by things that cannot be flushed right now.




Mirjana, November 12, 2002 - 10:41 am UTC

Hi Tom,
I would like your comment on this. It's a metalink note DocId: 146559.1 "Diagnosing and Resolving Error ORA-04031"

"...
Shared Pool Fragmentation:
Every time a SQL or PL/SQL statement needs to be executed the parse representation is loaded in the shared pool requiring a specific amount of free contiguous space. The first resource where the database scans is the free memory available in the shared pool. Once the free memory is exhausted, the database looks for reusing an already allocated piece not in use. If a chunk with the exact size is not available, the scan continues looking for space based on the following criteria:
- The chuck size is larger than the required size
- The space is contiguous
- The chuck is available (not in use)
Then that chunk is split and the remaining free space is added to the appropriate free space list. When the database is operating in this way for a certain period of time the shared pool structure will be fragmented.
When the shared pool is suffering fragmentation, the allocation of a piece of free space takes much more time generating slow performance in the database (the "chunk allocation" is protected by a single latch called "shared pool latch" which is held during the whole operation) or ORA-04031 errors (when the database cannot find a contiguous piece of free memory).
...
The ORA-04031 is a result of lack of contiguous space in the shared pool reserved space...
..."

Doesn't this say that specific amount of FREE CONTIGUOUS space is needed to load an object into memory (?), which differs from "4k chunks" from the post above...

??

Thanks...



Tom Kyte
November 12, 2002 - 1:34 pm UTC


Article-ID: <Note:146559.1>
Circulation: PUBLISHED (EXTERNAL)
Folder: industries.clinical
Topic: RXCUPGRADE:Upgrade Scripts
Title: Oracle Clinical Release 3.2 Patchset 3 (1796644), Windows
README


I think your note number is wrong? but anyway -- plsql is loaded in small chunks. A specific amount of free contigous space is needed - about 4k -- for plsql. (maybe lots of about 4k chunks perhaps but...)

Mirjana, November 13, 2002 - 2:05 am UTC

Ok!
Sorry, it was DocId 146599.1 with the title "Diagnosing and Resolving Error ORA-04031".
There, it says nothing about 4k chunks to manage memory (?), or am I getting this wrong?

Thanks!




Tom Kyte
November 13, 2002 - 1:26 pm UTC

It just doesn't say it -- what it says is accurate but it doesn't say everything (it covers 7.0 to 8.1 -- a hugely broad set of versions indeed! things change)


If you click through to related note:


Article-ID: <Note:62143.1>
Circulation: PUBLISHED (EXTERNAL)
Folder: server.Performance.Database
Topic: Tuning Shared Pool
Title: Understanding and Tuning the Shared Pool in Oracle7,
Oracle8, and Oracle8i

You'll find:

...

Historic Notes
The notes here relate to pre-Oracle7.3 releases of Oracle and are included for completeness only:

* In 7.3 the PLSQL was enhanced to used paged executable code reducing the number of large allocations in the shared pool and reducing the need for KEEPing.


......




Oracle Clinical?

Sikandar Hayat, May 09, 2003 - 1:11 pm UTC

Dear TOM,
I have heard about Oracle Clinical and want to know about it but unable to find any info about it. Please give some info about it or any link if you have. Thanks

Tom Kyte
May 09, 2003 - 3:08 pm UTC

if you search for clinical on oracle.com, you'll get some hits on it. It is a fairly specific application that is typical sold through a sales rep, you might ask yours about it.

when is this 4k chunk introduced

A reader, January 27, 2004 - 4:09 pm UTC

Hi

Which version is this 4k chunks assignment of memory introduced? In one customer their production support has a rule, no packages bigger than 128k in size, if bigger split in two, they say this is because they used to get lots of ORA-04031 in Oracle 7...

Tom Kyte
January 28, 2004 - 8:10 am UTC

Oracle 8

9i shared pool fragmentation

A reader, June 15, 2004 - 2:07 pm UTC

Hi,
Does it mean that 9i shared pool cannot become fragmented because it uses something like LMT (onky in memory) and if I get ora-4031 in 9i it is caused by lack of space ?

Tom Kyte
June 15, 2004 - 5:44 pm UTC

that is the theory -- of course "issues" can arise.

on a system with bind variables (or a datawarehouse without)....
and a properly sized shared pool

I've never hit it (in 9i)

ORA-04030

A reader, June 16, 2004 - 8:03 am UTC

hi tom ,

i am trying to create a table based on a view.
the view is based on xml document.
here is the view description.

CREATE OR REPLACE VIEW VW_MEPOutputData
AS
SELECT
  FileID                                                                                           FileID
, SUBSTR(extractvalue(value(MeasPoint), '/MeasPoint/Name'), 1, 255)   ||'('||
  SUBSTR(extractvalue(value(MeasPoint), '/MeasPoint/@id'), 1, 255)    ||')'                        LoadPoints
, SUBSTR(extractvalue(value(MeasPointStep),    '/MeasPointStep/@id'), 1, 255)                      LoadPointSteps
, SUBSTR(extractvalue(value(SetVar),           '/SetVar/ViewName'), 1, 255)                        SetVariable
, SUBSTR(extractvalue(value(VSV),              '/VarSetValue/@Step'), 1, 10)                      SetStep
, SUBSTR(extractvalue(value(VSV),              '/VarSetValue/VarSet/SetValue'), 1, 10)            SetValue
, SUBSTR(extractvalue(value(SetVar),           '/SetVar/SetState'), 1, 10)                        SetState
, SUBSTR(extractvalue(value(SetVar),           '/SetVar/VarDevice'), 1, 255)                       SetVarDevice
, SUBSTR(extractvalue(value(VSV),              '/VarSetValue/VarSet/SetTime'), 1, 10)             SetTime
, SUBSTR(extractvalue(value(MeasVar),          '/MeasVar/ViewName'), 1, 255)                       MeasVariable
, SUBSTR(extractvalue(value(VMV),              '/VarMeasValue/@Step'), 1, 10)                     MeasStep
, SUBSTR(extractvalue(value(VMV),              '/VarMeasValue/VarMeas/MeasValue'), 1, 10)         MeasValue
, SUBSTR(extractvalue(value(MeasVar),          '/MeasVar/MeasState'), 1, 10)                      MeasState
, SUBSTR(extractvalue(value(MeasVar),          '/MeasVar/MeasState'), 1, 255)                      MeasVarDevice
, SUBSTR(extractvalue(value(VMV),              '/VarMeasValue/VarMeas/MeasTime'), 1, 10)          MeasTime
FROM  TabL_FileContent f
, table(xmlsequence(extract(f.ResultData, '/MEPOutput/MEPOutputData/Sequences/Sequence'))) Sequence
, table(xmlsequence(extract(value(Sequence), '/Sequence/MeasPoint'))) MeasPoint
, table(xmlsequence(extract(value(MeasPoint),'/MeasPoint/MeasPointSteps'))) MeasPointSteps
, table(xmlsequence(extract(value(MeasPointSteps),'/MeasPointSteps/MeasPointStep'))) MeasPointStep
, table(xmlsequence(extract(value(MeasPointStep), '/MeasPointStep/SetPhase/SetVar'))) SetVar
, table(xmlsequence(extract(value(SetVar), '/SetVar/VarSetValues/VarSetValue'))) VSV
, table(xmlsequence(extract(value(MeasPointStep),'/MeasPointStep/MeasPhase/MeasVar'))) MeasVar
, table(xmlsequence(extract(value(MeasVar), '/MeasVar/VarMeasValues/VarMeasValue'))) VMV
/


when i try to create the table i get such an error.

SQL>  create table test_u as select * from vw_mepoutputdata where 1=2;
 create table test_u as select * from vw_mepoutputdata where 1=2
                                                               *
ERROR at line 1:
ORA-04030: out of process memory when trying to allocate 44 bytes
(callheap,temporary memory)

i increased the shared pool size and still get the error.

Total System Global Area 1074865868 bytes
Fixed Size                   456396 bytes
Variable Size            1048576000 bytes
Database Buffers           25165824 bytes
Redo Buffers                 667648 bytes

SQL> select value
  2  from v$parameter
  3  where name like 'shared_pool_size';

VALUE
---------------------------------------------
738197504

can you please help me. i have used substr becuase other wise it takes a default of varchar2(4000) for each column. 

Tom Kyte
June 16, 2004 - 12:50 pm UTC

ORA-04030: out of process memory
^^^^^^^ that is the OS here, malloc() is failing in the process itself. nothing at all to do with the shared pool.

do you have a full reproducible test case that I could run too?

A reader, June 16, 2004 - 11:58 pm UTC

Hi tom ,

i have logged a tar and seems like the problem is a bug.
here are the bug numbers given by Oracle support.

3132291/2806660

RE : PGA_AGGREGATE_TARGET

A reader, February 03, 2005 - 5:31 pm UTC

Tom,

In one of the above discussion, there is a ORA -04030 error related to process memory. If my understanding and memory is correct,

1. This happens because the process is not able to allocate PGA memory. Is it correct?
2. If my understanding on 1 is correct, then using PGA_AGGREGATE_TARGET should solve this problem because PGA_AGGREGATE_TARGET specificies the total of all PGA memory that an instance can use (that is the maximum PGA memory for the whole instance, rather than session wise). Correct?
3. Even if PGA_AGGREGATE_TARGET is set to a large value and still we get this error what should we look for as to why this error is happening?

Thanks

Tom Kyte
February 04, 2005 - 1:38 am UTC

1) correct
2) nope. it limits work areas (sort, hash). It does not in any way, nor could it in any way prevent you from filling up 2 million entries in a plsql table and blowing out memory.

Also, 4030 happens at the process level, processes are limited in the amount of memory they can allocate -- pga agg target is at the system level. It would be very possible to have pga aggregate target set less than available memory, and hit ora-4030 by having ulimit set too low.


3) you are running out of memory? that is why it happens. now you need to look at what you are doing in your processing -- to see "why".

shared_pool_reserved_size, _shared_pool_reserved_min_alloc

Edgar, February 04, 2005 - 7:44 am UTC

Hi,

So, am i correctlly understanded, that shared pool fragmentation is no longer concern starting from Oracle8?

Then, setting %reserved% init.ora parameters, pinning using DBMS_SHARED_POOL.KEEP is no longer meaningfull topic
for preventing ORA-4031?
for performance tuning?

And i should forget that stuff from Steve Adams?
</code> http://www.ixora.com.au/q+a/pool.htm#end <code>

Sincerely,

Tom Kyte
February 04, 2005 - 11:49 am UTC

no, never said that -- just that the large pool removes the large allocations (and that was the major cause of the problem, why the shared pool reserved was added).




I read steves stuff? what part do you think i said you should be forgetting about?

A few problems

K.Rajeev, November 18, 2005 - 7:41 am UTC

Hi Tom

I am on Oracle 8i (8.1.7.0)/Windows 2K Server/ RAID 5 dual processor server with 4gb RAM.Application is in D2K. Until recently, the database and application was working just about fine.There have been changes in the infrastructure of the network with the intro of thin clients using terminal services (RDP) and some problems with the network.

Since, the following errors have crept up.

ORA-04030 Out of Process Memory
Especially when running reports.

TNS-12500 Listener failed to start a dedicated server
Especially when using SQL-Loader and otherwise also.

FRM error giving a NO AUTHORIZATION message

Redo Space Wait Ratio 8.70

Chained Fetch Ratio 0.14
User tablespaces are LMTs

Parse to Execute Ratio 35.6

CPU Parse Overhead 100.00


I feel that a lot of the problems are not database related and I do not want to un-necessarily modify any parameters. Could you please give me some pointers to analyse, work on and remedy the problems?

K.Rajeev

Tom Kyte
November 18, 2005 - 3:13 pm UTC

sounds like you have run out of memory here more than anything. Windows is going to limit the total memory used by the server by *alot* (you might have 4 gig, but you are probably limited to something less than 2gig)

so, how many users and what is the SGA size.

ORA-04030

Kumar, February 22, 2006 - 9:39 am UTC

Hi,
I am also facing the similar type of error:
ORA-04030: out of process memory when trying to allocate 917536 bytes (joxcx callheap,ioc_allocate ufree)
and ORA -12500 when trying to connect through toad or sqlplus.
I am working on Oracle 9i R2, Windows 2000 Advanced Server. Application is Java.
When the application servers were restarted, I was able to connect to DB. Is this related to the number of concurrent connections that hit the database?
Is there any restrictions on connections to the db?

Tom Kyte
February 22, 2006 - 10:13 am UTC

Your computer running the database ran out of memory.

If bouncing the application servers "fixed it", it would seem that you have a leak of some sort in your applications running in the middle tier (that needs to be corrected - the fix is not to schedule periodic reboots of the middle tier!)



More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library