Tuning Java Pool after getting ORA-04031 I'm running Oracle 12.2.0.1 Standard edition on Windows 2012 RC2. 
I'm NOT running Oracle's Automatic Memory Management. 

We are seeing these in the alert log:

ORA-04031: unable to allocate 4096 bytes of shared memory ("java pool","prv//////LBKLAGIMAAAAAAAA","JOXLE^aff7380e",":SGAClass")


First thing I thought to try was flushing the shared pool to resolve the immediate problem, while the dev team is fixing the SQL code, so I ran:

ALTER SYSTEM FLUSH SHARED_POOL;


Only then did I realise that the Java Pool isn't actually part of the shared pool. So I tried to take a look at the Java pool.

I think this tells me that my Java pool is roughly 32MB:

SQL&gt; select * from v$javapool;



CATEGORY                                            MEMUSED     CON_ID
------------------------------------------------ ---------- ----------
:Intern                                              973440          0
:SGAClass                                          32103240          0
:SROState                                             81120          0



I ran this tuning tool, which if I can interpret correctly, says that there's not much benefit from increasing the Java pool size:

    select
       estd_lc_size,
       java_pool_size_for_estimate,
       java_pool_size_factor
    from
       v$java_pool_advice;



ESTD_LC_SIZE JAVA_POOL_SIZE_FOR_ESTIMATE JAVA_POOL_SIZE_FACTOR
------------ --------------------------- ---------------------
           8                          16                    .5
          24                          32                     1
          25                          48                   1.5
          25                          64                     2
          25                          80                   2.5
          25                          96                     3
          25                         112                   3.5
          25                         128                     4
          25                         144                   4.5
          25                         160                     5
          25                         176                   5.5



I ran the following query taken from the Oracle docs here and it seems to suggest that the SGA_TARGET value is fine!

SELECT (
   (SELECT SUM(value) FROM V$SGA) -
   (SELECT CURRENT_SIZE FROM V$SGA_DYNAMIC_FREE_MEMORY)
   ) "SGA_TARGET"
FROM DUAL;



SGA_TARGET
----------
5167382528 = 4928 MB i.e. same as what it currently is!



I can see that:   

    MEMORY_TARGET = 0
    SGA_MAX_SIZE = 4928M
    SGA_TARGET = 4928M
    JAVA_POOL_SIZE = 0
    SHARED_POOL_SIZE = 0
    DB_CACHE_SIZE = 0 
    DB_KEEP_CACHE_SIZE = 0
    MEMORY_MAX_TARGET = 0


...so I'm bit confused how to tune this when we're not using AMM.

So how to resolve this issue?


is my best option to increase the Java pool size?
if so, how to do this when not using AMM?
With SGA_TARGET set and JAVA_POOL_SIZE=0 it you are at least using Automatic Shared Memory Management, so the Java Pool is already self-tuning. You can specify a JAVA_POOL_SIZE value that will become the minimum pool size and Oracle may choose to tune it higher if necessary. Changing the JAVA_POOL_SIZE will require a restart of the database. You may need to increase the SGA_TARGET value as well, as increasing the default JAVA_POOL_SIZE will take memory away from other SGA pools.

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/refrn/JAVA_POOL_SIZE.html#GUID-F24C4770-0B7C-42BD-9AAD-0EC1E92A90F6