DEV Community

umzzil nng
umzzil nng

Posted on • Originally published at oraerror.com

Oracle ORA-00371 Error: Causes and Solutions Complete Guide

ORA-00371: Not Enough Shared Pool Memory

ORA-00371 is raised when Oracle's Shared Pool — the SGA region responsible for caching parsed SQL, PL/SQL code, and data dictionary information — runs out of available memory. This error typically surfaces during peak workloads or when the database is heavily hit with hard parsing activity. Left unaddressed, it can cascade into ORA-04031 errors and cause widespread session failures across the entire database.


Top 3 Causes

1. Undersized SHARED_POOL_SIZE Parameter

The most straightforward cause: the shared pool is simply too small for the workload. As applications grow, the original sizing becomes inadequate. Check current usage before making changes.

-- Check current shared pool allocation and free memory
SELECT name,
       ROUND(bytes / 1024 / 1024, 2) AS size_mb
FROM   v$sgastat
WHERE  pool = 'shared pool'
  AND  name IN ('free memory', 'library cache', 'dictionary cache')
ORDER  BY bytes DESC;

-- Review current parameter settings
SHOW PARAMETER shared_pool_size;
SHOW PARAMETER sga_target;
Enter fullscreen mode Exit fullscreen mode

2. Excessive Hard Parsing Due to Literal SQL

When applications embed literal values directly into SQL instead of using bind variables, Oracle treats each unique statement as a brand-new query and performs a full hard parse every time. This floods the library cache with thousands of unique cursors and drains shared pool memory rapidly.

-- Find top SQL statements causing hard parses
SELECT sql_text,
       parse_calls,
       executions,
       ROUND(parse_calls / DECODE(executions,0,1,executions)*100,2) AS parse_ratio_pct
FROM   v$sql
WHERE  executions > 0
ORDER  BY parse_calls DESC
FETCH  FIRST 10 ROWS ONLY;

-- Identify literal SQL flooding the library cache (same pattern, many cursors)
SELECT SUBSTR(sql_text,1,60) AS sql_sample,
       COUNT(*)              AS cursor_count
FROM   v$sql
GROUP  BY SUBSTR(sql_text,1,60)
HAVING COUNT(*) > 20
ORDER  BY cursor_count DESC;
Enter fullscreen mode Exit fullscreen mode

3. Memory Fragmentation from Large Object Reloading

Large PL/SQL packages and objects require contiguous memory blocks when loaded into the shared pool. If the pool is fragmented, Oracle cannot find a large enough free block even when total free memory appears sufficient. This triggers repeated aging-out and reloading cycles, worsening fragmentation over time.

-- Check for large objects in the library cache
SELECT owner, name, type,
       ROUND(sharable_mem/1024/1024, 2) AS size_mb,
       loads,
       kept
FROM   v$db_object_cache
WHERE  sharable_mem > 1048576   -- objects larger than 1 MB
ORDER  BY sharable_mem DESC
FETCH  FIRST 15 ROWS ONLY;
Enter fullscreen mode Exit fullscreen mode

Quick Fix Solutions

Increase shared pool size dynamically (no restart needed in most cases):

-- Increase shared pool size on the fly (ASMM environment)
ALTER SYSTEM SET shared_pool_size = 512M SCOPE = BOTH;

-- Increase overall SGA target to give shared pool more room
ALTER SYSTEM SET sga_target = 4G SCOPE = BOTH;
Enter fullscreen mode Exit fullscreen mode

Emergency flush to relieve fragmentation (use with caution in production):

-- Flush the shared pool - causes temporary performance dip
-- Run during a maintenance window only
ALTER SYSTEM FLUSH SHARED_POOL;
Enter fullscreen mode Exit fullscreen mode

Pin large, frequently-used packages to prevent aging-out:

-- Pin critical packages into the shared pool at startup
EXECUTE DBMS_SHARED_POOL.KEEP('OWNER.PACKAGE_NAME', 'P');

-- Verify pinned objects
SELECT owner, name, type, kept
FROM   v$db_object_cache
WHERE  kept = 'YES';
Enter fullscreen mode Exit fullscreen mode

Enable CURSOR_SHARING as a temporary workaround (test before applying):

ALTER SYSTEM SET cursor_sharing = FORCE SCOPE = BOTH;
Enter fullscreen mode Exit fullscreen mode

Prevention Tips

1. Monitor shared pool utilization proactively.
Schedule a monitoring job that alerts when shared pool usage exceeds 85%. Use v$shared_pool_advice to right-size the pool based on actual workload data.

-- Shared Pool Advisor recommendations
SELECT shared_pool_size_for_estimate AS pool_mb,
       estd_lc_time_saved_factor     AS perf_factor
FROM   v$shared_pool_advice
ORDER  BY shared_pool_size_for_estimate;
Enter fullscreen mode Exit fullscreen mode

2. Enforce bind variable usage from day one.
Mandate bind variables in your development coding standards and include literal SQL detection as part of every code review. Regularly query v$sql in lower environments to catch literal SQL patterns before they reach production. This single practice eliminates the majority of shared pool pressure in OLTP systems.


Related Errors

  • ORA-04031 — Direct "unable to allocate shared memory" failure; often the next error after ORA-00371 appears in alert logs.
  • ORA-00604 — Recursive SQL error that frequently wraps ORA-04031 or ORA-00371 in the error stack.

📖 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)