ORA-04032: pga_aggregate_limit exceeded — Diagnosis and Fix
ORA-04032 is thrown when the total PGA (Program Global Area) memory consumed across all database sessions exceeds the hard limit defined by the pga_aggregate_limit parameter, introduced in Oracle 12c. Unlike pga_aggregate_target, which is merely an advisory target, pga_aggregate_limit is a strict ceiling that Oracle enforces by terminating the offending operation immediately. This error commonly surfaces during heavy sort operations, hash joins, or long-running PL/SQL batch jobs that accumulate memory over time.
Top 3 Causes
1. Memory-Intensive SQL Operations (Sorts & Hash Joins)
Large-scale sorting and hash join operations consume significant PGA work area memory. When multiple concurrent sessions run such queries simultaneously, the aggregate PGA can spike well beyond the configured limit.
-- Identify SQL statements consuming large PGA work areas
SELECT
sql_id,
operation_type,
policy,
estimated_optimal_size / 1024 / 1024 AS optimal_mb,
last_memory_used / 1024 / 1024 AS last_used_mb,
last_execution
FROM
v$sql_workarea
WHERE
last_memory_used > 100 * 1024 * 1024 -- over 100 MB
ORDER BY
last_memory_used DESC
FETCH FIRST 10 ROWS ONLY;
2. pga_aggregate_limit Set Too Low
The default value of pga_aggregate_limit is the greater of 2x pga_aggregate_target or 2 GB. On servers with limited RAM or conservative initial configurations, this default can be insufficient for real-world workloads — especially as application usage grows over time.
-- Check current PGA parameter settings
SHOW PARAMETER pga_aggregate_limit;
SHOW PARAMETER pga_aggregate_target;
-- Check actual PGA consumption vs. limit
SELECT
name,
value / 1024 / 1024 AS value_mb
FROM
v$pgastat
WHERE
name IN (
'total PGA allocated',
'aggregate PGA target parameter',
'global memory bound'
);
3. PGA Memory Leak in PL/SQL or Application Code
Unclosed cursors, oversized in-memory collections (VARRAY, Nested Table), or improperly managed session state in PL/SQL can cause a session's PGA to grow continuously. Long-running batch processes are the most common culprit.
-- Find sessions with abnormally high PGA allocation
SELECT
s.sid,
s.serial#,
s.username,
s.program,
s.last_call_et AS seconds_active,
p.pga_alloc_mem / 1024 / 1024 AS pga_alloc_mb
FROM
v$session s
JOIN v$process p ON s.paddr = p.addr
WHERE
p.pga_alloc_mem > 200 * 1024 * 1024 -- sessions using over 200 MB
ORDER BY
p.pga_alloc_mem DESC;
Quick Fix Solutions
Increase the PGA limit dynamically (no restart required):
-- Increase pga_aggregate_limit
ALTER SYSTEM SET pga_aggregate_limit = 8G SCOPE = BOTH;
-- Adjust pga_aggregate_target accordingly (recommended: ~50% of pga_aggregate_limit)
ALTER SYSTEM SET pga_aggregate_target = 4G SCOPE = BOTH;
Kill the offending session if immediate relief is needed:
-- Terminate the high-PGA session
ALTER SYSTEM KILL SESSION '&sid,&serial#' IMMEDIATE;
Force a less memory-intensive join method using hints:
-- Use Nested Loop instead of Hash Join to reduce PGA pressure
SELECT /*+ USE_NL(e d) */
e.employee_id,
e.last_name,
d.department_name
FROM
employees e,
departments d
WHERE
e.department_id = d.department_id;
Prevention Tips
1. Set up proactive PGA monitoring.
Regularly check PGA utilization as a percentage of pga_aggregate_limit. Alert your team when usage exceeds 75% to allow time for intervention before sessions start failing.
-- Quick PGA utilization check (schedule via cron or OEM)
SELECT
ROUND(
(SELECT value FROM v$pgastat WHERE name = 'total PGA allocated') /
(SELECT value FROM v$parameter WHERE name = 'pga_aggregate_limit') * 100, 2
) AS pga_utilization_pct
FROM dual;
2. Enforce code review standards for memory-heavy operations.
Before deploying new SQL or PL/SQL to production, review execution plans using DBMS_XPLAN.DISPLAY_CURSOR and check V$SQL_WORKAREA for estimated memory usage. Always close cursors explicitly in PL/SQL — including in EXCEPTION blocks — and avoid loading entire large result sets into collections when row-by-row or bulk LIMIT processing is feasible.
Related Errors
- ORA-04031 — Insufficient memory in the Shared Pool or Large Pool (SGA side, not PGA).
- ORA-04030 — OS-level process memory allocation failure; may precede ORA-04032 under extreme memory pressure.
- ORA-01652 — Temp tablespace exhaustion, often occurring alongside PGA issues when sort operations spill to disk.
📖 Want a more detailed guide?
Check out the full in-depth version (Korean) on oraerror.com — includes detailed analysis, additional SQL examples, and prevention tips.
Top comments (0)