Skip to main content

Memory: PGA per session

When to use it

When the server is short of memory, when you see ORA-04036 (PGA limit exceeded), or to find a session using an unusual amount of memory.

Run this

Script: 01_analyze_pga_usage.sql. Full version in Performance › Performance monitoring › Memory monitoring.

ACCEPT SCHEMA_NAME PROMPT 'Enter schema name (leave blank for all): '

select p.pid,s.sid,spid,s.program,s.status,
round(PGA_USED_MEM/(1024*1024)) as PGA_USED_MEM,
round(PGA_ALLOC_MEM/(1024*1024)) as PGA_ALLOC_MEM,
round(PGA_FREEABLE_MEM/(1024*1024)) as PGA_FREEABLE_MEM,
round(PGA_MAX_MEM/(1024*1024)) AS PGA_MAX_MEM
from v$process p, v$session s where s.paddr = p.addr(+)
--and p.pga_alloc_mem!= (select max(pga_alloc_mem) from v$process where program not like '%LGWR%')
and (s.username = UPPER('&SCHEMA_NAME') OR '' = '&SCHEMA_NAME')
and s.sid not in (select sid from v$mystat)
order by p.pga_alloc_mem;

UNDEFINE SCHEMA_NAME

How to read the output

  • Values are in MB, one row per session, smallest first: the heaviest sessions are at the bottom.
  • PGA_ALLOC_MEM is what the process holds now. PGA_MAX_MEM is the most it ever held.
  • PGA_FREEABLE_MEM is memory the process could give back.
  • Background processes appear too. Focus on sessions with an application program name.

What to do next

  • For a session holding a lot of PGA, find what it is running (chapter 4) and note the SQL_ID.
  • Do not change pga_aggregate_target or pga_aggregate_limit. Report the numbers instead.

Risk level

READ ONLY Safe to run at any time. It only queries the data dictionary.