How to Perform a Oracle JVM Re-installation to Multitenant Database

Home > Oracle Database > How to Perform a Oracle JVM Re-installation to Multitenant Database
📁
Tutorial Collection
This guide is part of our comprehensive Oracle Database Reference Hub.

(1) Create a working directory for this activity.

mkdir /tmp/jvm
cd /tmp/jvm

Note : All scripts should be created and executed in directory /tmp/jvm . If you choose to do this activity in some other directory, then change the same path in all scripts.

(2) Create below scripts.

a. Create script jvm_info.sql to check JVM status.

— Create script jvm_info.sql with following contents

column comp_name format a40
column version format a20
column status format a15
column owner format a30
column object_name format a30
column object_type format a15
column long_name format a75
column role format a40
set pagesize 500
set linesize 150
set trimspool on
set serveroutput on
set echo on
--spool jvm_info.log
------ REGISTRY INFO ------

SELECT comp_name, version, status
FROM dba_registry
ORDER BY comp_name;

SELECT *
FROM dba_registry_history
ORDER BY action_time DESC;

------ JAVA OBJECT INFO ------

SELECT owner, object_type, status, COUNT(*)
FROM dba_objects
WHERE object_type LIKE '%JAVA%'
GROUP BY owner, object_type, status
ORDER BY owner, object_type, status;

SELECT owner, object_name, object_type, status
FROM dba_objects
WHERE object_name LIKE 'DBMS_JAVA%'
OR object_name LIKE '%INITJVMAUX%'
ORDER BY owner, object_name, object_type;

SELECT owner, NVL(longdbcs,object_name) long_name, object_type, status
FROM dba_objects, sys.javasnm$
WHERE object_type LIKE '%JAVA%'
AND status <> 'VALID'
AND short (+) = object_name
ORDER BY owner, long_name, object_type;

------ JAVA ROLE INFO ------

SELECT role
FROM dba_roles
WHERE role LIKE '%JAVA%'
ORDER BY role;

------ MEMORY INFO ------

SELECT *
FROM v$sgastat
WHERE pool = 'java pool' OR name = 'free memory'
ORDER BY pool, name;

------ DATABASE PARAMETER INFO ------

show parameter pool_size

show parameter target

show parameter sga

------ TEST JAVAVM USAGE AND CHECK VERSION ------
SELECT dbms_java.get_jdk_version JDK_Version FROM dual;

b. Create the REMOVAL scripts: pre_jvm_deinstall.sql, jvm_deinstall.sql, post_jvm_deinstall.sql, and fulljvmrm.sql

— Create script pre_jvm_deinstall.sql with following contents

alter system set "_system_trig_enabled" = false scope=memory;

-- to avoid any problems trying to run catnojava.sql, lets force the registry to reflect VALID components
execute sys.dbms_registry.loaded('JAVAVM');
execute sys.dbms_registry.loaded('CATJAVA');
execute sys.dbms_registry.valid('JAVAVM');
execute sys.dbms_registry.valid('CATJAVA');

set pagesize 500

set linesize 150

set echo on

set echo on
select obj#, name from obj$
where type#=28 or type#=29 or type#=30 or namespace=32;

— Create script jvm_deinstall_part_1.sql with following contents

set pagesize 500
start ?/rdbms/admin/catnoexf.sql
start ?/rdbms/admin/catnojav.sql
start ?/xdk/admin/rmxml.sql

— Create script jvm_deinstall_part_2.sql with following contents

set serveroutput on

set echo on

execute rmjvm.run(FALSE);

truncate table java$jvm$status;

truncate table java$jvm$steps$done;

drop table java$policy$shared$table;

set pagesize 500

select * from obj$ where obj#=0 and type#=0;
delete from obj$ where obj#=0 and type#=0;
commit;

— Create script post_jvm_deinstall.sql with following contents

set pagesize 500

set linesize 150

set echo on

select owner, count(*) from all_objects
where object_type like '%JAVA%' group by owner;
select obj#, name from obj$
where type#=28 or type#=29 or type#=30 or namespace=32;
select o1.name from obj$ o1,obj$ o2
where o1.type#=5 and o1.owner#=1 and o1.name=o2.name and o2.type#=29;

— Create script jvmremoval.sql with following contents

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b pre_jvm_deinstall_ /tmp/jvm/pre_jvm_deinstall.sql

-- Note: Comment out the deinstall_part_1 if you find that you are encountering ORA-7445 or ORA-600 errors preventing them from completing
-- since deinstall_part_2 will do a brute force removal of any remaining JVM related objects from SYS anyway.
host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -r -l /tmp/jvm -n 1 -b jvm_deinstall_part_1_ /tmp/jvm/jvm_deinstall_part_1.sql

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -r -l /tmp/jvm -n 1 -b jvm_deinstall_part_2_ /tmp/jvm/jvm_deinstall_part_2.sql

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -r -l /tmp/jvm -n 1 -b post_jvm_deinstall_ /tmp/jvm/post_jvm_deinstall.sql

c. Create the INSTALL scripts: pre_jvm_install.sql, jvm_install.sql, post_jvm_install.sql, and fulljvminstall.sql

See also  Enabling TLS in R12.1

— Create script pre_jvm_install.sql with following contents

set pagesize 500
set linesize 150

set echo on

select obj#, name from obj$
where type#=28 or type#=29 or type#=30 or namespace=32;

— Create script jvm_install.sql with following contents

alter system set "_system_trig_enabled" = false scope=memory; 

start ?/javavm/install/reinitjvm.sql
start ?/xdk/admin/initxml.sql
start ?/rdbms/admin/catjava.sql

— Create script post_jvm_install.sql with following contents

set pagesize 500
set linesize 150

select obj#, name from obj$
where type#=28 or type#=29 or type#=30 or namespace=32;

— Create script fulljvminstall.sql with following contents

spool full_jvminst.log;
set echo on

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b pre_jvm_install_ pre_jvm_install.sql

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b jvm_install_ jvm_install.sql

host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b post_jvm_install_ post_jvm_install.sql
set echo off
spool off

(3)Run below script from a new SQL*Plus session to check current JVM status.

sqlplus / as sysdba

alter pluggable database all open;
host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b jvm_preinstall_info_ /tmp/jvm/jvm_info.sql;

(4) Remove the JVM.

a. Shutdown the database instance if it is running.

b. Prepare the database for JVM removal.

sqlplus / as sysdba

startup mount
alter database open upgrade;
alter pluggable database ALL open upgrade;
alter system enable restricted session;

set echo on

c. Perform the removal

@/tmp/jvm/jvmremoval.sql

d. shutdown and exit

shutdown immediate
exit

(5) Review the log files for JVM removal.

The jvmremoval.sql script creates 3 log files in /tmp/jvm named pre_jvm_deinstall_NN.log, jvm_deinstall_NN.log, and post_jvm_deinstall_NN.log (where NN is a sequential number to prevent overwrite of any existing logs). Review the log files and check to see if any unexpected errors were raised.

(6) Check JVM status to confirm removal from the database. Run below script to startup database and check current JVM status after removal.

sqlplus / as sysdba

startup mount force
alter database open;
alter pluggable database all open;
host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -l /tmp/jvm -n 1 -b post_jvm_removal_info_ /tmp/jvm/jvm_info.sql;

(7) After confirming the JVM was removed successfully, prepare to reinstall the JVM by first creating a new script to re-initialize the JVM based on the provided initjvm.sql script.

See also  Oracle sql_trace parameter and its impact

The initjvm.sql was only intended to install the JVM component one time. It was never intended to “re-install” the JVM in a database that had already contained the JVM previously and thus might have java objects in other schemas. Because of that, the author added syntax to cleanup from the installation in the event the JVM installation process failed for any reason. It basically is coded in such a way that after it attempts to install everything, it checks for either not enough java objects in SYS or at least one INVALID object in SYS. If it finds either of those to be the case, it does a clean removal of ALL java. This is fine for fresh installations but is dangerous for an installation that may have other Java dependent components installed such as APPS or Oracle Spatial, or even worse, your custom or a 3rd party Java stored procedure installation in another schema. Therefore, we will create a new script from initjvm.sql and to prevent it from potentially removing ALL java from the database, you will need to make the following changes to “reinitjvm.sql”.

a) navigate to the location of initjvm.sql
cd $ORACLE_HOME/javavm/install
b) make a copy of initjvm.sql called reinitjvm.sql
cp initjvm.sql reinitjvm.sql
c) in an editor, modify the reinitjvm.sql script by locating the below code block

declare
ok int;
bad int;
begin
:jvmrmaction := 'NONE';
select count() into ok from obj$ where status=1 and type#=29; select count() into bad from obj$ where status!=1 and type#=29 and owner#=0;
if bad > 0 or ok < 100 then
initjvmaux.abort_message(
'CREATE JAVA SYSTEM did not complete successfully:',
'number of java classes with status 1: '|| ok ||', with status != 1: '|| bad);
initjvmaux.abort_message('Backing out of java installation…');
:jvmrmaction := 'FULL_REMOVAL';
initjvmaux.endaction;
end if;
end;
/
and replace the block with the following statement

exec :jvmrmaction := 'NONE';

(8) Assuming you have performed step 7, and validated removal, run the below script to reinstall.

sqlplus / as sysdba

shutdown immediate;

startup mount

alter database open upgrade;

alter pluggable database all open upgrade;
@/tmp/jvm/fulljvminstall.sql
shutdown immediate

(9) Review the log files for JVM installation.

See also  How to use foreign key in oracle

The fulljvminstall.sql script creates 3 log files in /tmp/jvm named pre_jvm_install_NN.log, jvm_install_NN.log, and post_jvm_install_NN.log (where NN is a sequential number to prevent overwrite of any existing logs). Review the log files and check to see if any unexpected errors were raised.

(10) Resolve any invalid objects.

Execute the utlrp.sql against the container and all the pluggable databases.

sqlplus / as sysdba
startup mount force
alter database open;
alter pluggable database all open;
host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl -n 1 -e -b utlrp_ -d $ORACLE_HOME/rdbms/admin utlrp.sql

(11) Check JVM status to confirm it is valid in the container and all PDBs after reinstallation.

sqlplus / as sysdba
host $ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/ catcon.pl -l /tmp/jvm -n 1 -b post_jvm_installation_info_ /tmp/jvm/jvm_info.sql;
  1. Once you have confirmed the JVM reinstallation was successful, shutdown the database and bring it back up for normal use.

Related Articles

How to find the database session for JVM PID
How to check the java version in Unix
How to Reload APPS Java Class Objects in R11i/R12

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top