Sunday, September 1, 2019

Upgrade Oracle 11g to 18c

5:03 PM Posted by Dilli Raj Maharjan 1 comment

Environment

OS: CEntOS 6.10
Oracle: Oracle Database 11.2.0.4 SE with JUL2019 PSU Applied
Memory: 4G
HDD: 100G

Prerequisites

Verify all prerequisites packages are installed on the server. Install oracle-database-preinstall-18c package before upgrading. If you have internet access on the server you can download and install the package with yum command or you can download package from internet and install manually. Use link below to download it manually.


Execute yum command to download and install pre-install package.
yum -y install oracle-database-preinstall-18c




Create new Oracle Home for  Oracle 18c.
mkdir -p /u01/app/oracle/product/18.0.0/dbhome_1
chown -R oracle:oinstall /u01/app/oracle/product/18.0.0/dbhome_1/


Extract 18c source file to newly created Oracle Home.
su - oracle
cd /media/sf_Softwares/Oracle
unzip LINUX.X64_180000_db_home.zip -d /u01/app/oracle/product/18.0.0/dbhome_1



Add new Oracle Home setting to /etc/oratab. Make sure to comment or remove the older OH.
vi /etc/oratab



Modify response file.
Once extract is completed, change directory to 18c Oracle Home. Change environment variables and set recently created directory as ORACLE_HOME. Copy response file to some other location. This will preserve original respose file. Modify respose file till the Grid Option.
Set all the parameters value till you reach Grid Options.

. oraenv

cd $ORACLE_HOME
cd install/response/
cp db_install.rsp ~oracle/
cd ~oracle/
vi db_install.rsp 




Modify response file and fill-up all the required parameter values.  Before updating response file it has contents as below.

Once it has been modified and updated it looks as below.



Execute command below to start installation
./runInstaller -silent -ignorePrereq -waitforcompletion -responseFile ~oracle/db_install.rsp SECURITY_UPDATES_VIA_MYORACLESUPPORT=false DECLINE_SECURITY_UPDATES=true



Execute root.sh as  user root described in installation output.
/u01/app/oracle/product/18.0.0/dbhome_1/root.sh




Download and extract pre-upgrade file to new Oracle home location.

Download the latest "preupgrade.jar" file from MOS 884522.1.

cd /media/sf_Softwares/Oracle/
ls
unzip preupgrade_181_cbuild_7_lf.zip -d /u01/app/oracle/product/18.0.0/dbhome_1/rdbms/admin/


Executed pre-upgrade jar before upgrade. Make sure all issue reported should be fixed before upgrading database to latest version.


Output should be something like below. Fixes are available at the buttom.

Report generated by Oracle Database Pre-Upgrade Information Tool Version
18.0.0.0.0 Build: 6 on 2019-09-01T11:16:07

Upgrade-To version: 18.0.0.0.0

=======================================
Status of the database prior to upgrade
=======================================
      Database Name:  ORCL
     Container Name:  Not Applicable in Pre-12.1 database
       Container ID:  Not Applicable in Pre-12.1 database
            Version:  11.2.0.4.0
         Compatible:  11.2.0.4.0
          Blocksize:  8192
           Platform:  Linux x86 64-bit
      Timezone File:  14
  Database log mode:  NOARCHIVELOG
           Readonly:  FALSE
            Edition:  R1

  Oracle Component                       Upgrade Action    Current Status
  ----------------                       --------------    --------------
  Oracle Server                          [to be upgraded]  VALID         
  JServer JAVA Virtual Machine           [to be upgraded]  VALID         
  Oracle XDK for Java                    [to be upgraded]  VALID         
  Oracle Workspace Manager               [to be upgraded]  VALID         
  OLAP Analytic Workspace                [to be upgraded]  INVALID       
  Oracle Enterprise Manager Repository   [to be upgraded]  VALID         
  Oracle Text                            [to be upgraded]  VALID         
  Oracle XML Database                    [to be upgraded]  VALID         
  Oracle Java Packages                   [to be upgraded]  VALID         
  Oracle Multimedia                      [to be upgraded]  VALID         
  Oracle Spatial                         [to be upgraded]  VALID         
  Expression Filter                      [to be upgraded]  VALID         
  Rule Manager                           [to be upgraded]  VALID         
  Oracle OLAP API                        [to be upgraded]  INVALID       

==============
BEFORE UPGRADE
==============

  REQUIRED ACTIONS
  ================
  1.  Contact Oracle Support for instructions on how to resolve this error.
      ERROR: ORA-29548 ORA-29548: Java system class reported: could not
      identify release specified in classes.bin
      
      There is a problem with the JAVAVM component and database upgrade cannot
      be performed until it is corrected.
      
      JAVAVM component must be functioning properly before database upgrade.

  RECOMMENDED ACTIONS
  ===================
  2.  Update NUMERIC INITIALIZATION PARAMETERS to meet estimated minimums. 
      This action may be done now or when starting the database in upgrade mode
      using the 18.0.0.0.0 ORACLE HOME.
      
       Parameter                                 Currently  18.0.0.0.0 minimum
       ---------                                 ---------  ------------------
      *memory_target                             729808896          1203765248
       processes                                       150                 300
      
      The database upgrade process requires certain initialization parameters
      to meet minimum values.  The Oracle upgrade process itself has minimum
      values which may be higher and are marked with an asterisk.  After
      upgrading, those asterisked parameter values may be reset if needed.

  3.  Remove the EM repository.
      
      - Copy the $ORACLE_HOME/rdbms/admin/emremove.sql script from the target
      18.0.0.0.0 ORACLE_HOME into the source 11.2.0.4.0 ORACLE_HOME.
      
      Step 1: If database control is configured, stop EM Database Control,
      using the following command
      
        $> emctl stop dbconsole
      
      Step 2: Connect to the database using the SYS account AS SYSDBA
      
        SET ECHO ON;
        SET SERVEROUTPUT ON;
        @emremove.sql
      
      Without the set echo and serveroutput commands, you will not be able to
      follow the progress of the script.
      
      The database has an Enterprise Manager Database Control repository.
      
      Starting with Oracle Database 12c, the local Enterprise Manager Database
      Control does not exist anymore. The repository will be removed from your
      database during the upgrade.  This step can be manually performed before
      the upgrade to reduce downtime.

  4.  Remove OLAP Catalog by running the 11.2.0.4.0 SQL script
      $ORACLE_HOME/olap/admin/catnoamd.sql script.
      
      The OLAP Catalog component, AMD, exists in the database.
      
      Starting with Oracle Database 12c, the OLAP Catalog (OLAP AMD) is
      desupported and will be automatically marked as OPTION OFF during the
      database upgrade if present. Oracle recommends removing OLAP Catalog
      (OLAP AMD) before database upgrade.  This step can be manually performed
      before the upgrade to reduce downtime.

  5.  Upgrade Oracle Application Express (APEX) manually before the database
      upgrade.
      
      The database contains APEX version 3.2.1.00.12. Upgrade APEX to at least
      version 5.1.3.00.05.
      
      Starting with Oracle Database Release 18, APEX is not upgraded
      automatically as part of the database upgrade. Refer to My Oracle Support
      Note 1088970.1 for information about APEX installation and upgrades.

  6.  (AUTOFIXUP) Gather stale data dictionary statistics prior to database
      upgrade in off-peak time using:
      
        EXECUTE DBMS_STATS.GATHER_DICTIONARY_STATS;
      
      Dictionary statistics do not exist or are stale (not up-to-date).
      
      Dictionary statistics help the Oracle optimizer find efficient SQL
      execution plans and are essential for proper upgrade timing. Oracle
      recommends gathering dictionary statistics in the last 24 hours before
      database upgrade.
      
      For information on managing optimizer statistics, refer to the 11.2.0.4
      Oracle Database Performance Tuning Guide.

  7.  Directly grant ADMINISTER DATABASE TRIGGER privilege to the owner of the
      trigger or drop and re-create the trigger with a user that was granted
      directly with such. You can list those triggers using "SELECT OWNER,
      TRIGGER_NAME FROM DBA_TRIGGERS WHERE TRIM(BASE_OBJECT_TYPE)='DATABASE'
      AND OWNER NOT IN (SELECT GRANTEE FROM DBA_SYS_PRIVS WHERE
      PRIVILEGE='ADMINISTER DATABASE TRIGGER')"
      
      There is one or more database triggers whose owner does not have the
      right privilege on the database.
      
      The creation of database triggers must be done by users granted with
      ADMINISTER DATABASE TRIGGER privilege. Privilege must have been granted
      directly.

  8.  (AUTOFIXUP) Gather statistics on fixed objects prior the upgrade.
      
      None of the fixed object tables have had stats collected.
      
      Gathering statistics on fixed objects, if none have been gathered yet, is
      recommended prior to upgrading.
      
      For information on managing optimizer statistics, refer to the 11.2.0.4
      Oracle Database Performance Tuning Guide.

  INFORMATION ONLY
  ================
  9.  To help you keep track of your tablespace allocations, the following
      AUTOEXTEND tablespaces are expected to successfully EXTEND during the
      upgrade process.
      
                                                 Min Size
      Tablespace                        Size     For Upgrade
      ----------                     ----------  -----------
      SYSAUX                             510 MB       720 MB
      SYSTEM                             760 MB      1195 MB
      TEMP                                20 MB       150 MB
      UNDOTBS1                            50 MB       446 MB
      
      Minimum tablespace sizes for upgrade are estimates.

  ORACLE GENERATED FIXUP SCRIPT
  =============================
  All of the issues in database ORCL
  which are identified above as BEFORE UPGRADE "(AUTOFIXUP)" can be resolved by
  executing the following

    SQL>@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/preupgrade_fixups.sql

=============
AFTER UPGRADE
=============

  REQUIRED ACTIONS
  ================
  None

  RECOMMENDED ACTIONS
  ===================
  10. (AUTOFIXUP) If you use the -T option for the database upgrade, then run
      $ORACLE_HOME/rdbms/admin/utluptabdata.sql after the upgrade is complete,
      to VALIDATE and UPGRADE any user tables affected by changes to
      Oracle-Maintained types.
      
      There are user tables dependent on Oracle-Maintained object types.
      
      If the -T option is used to set user tablespaces to READ ONLY during the
      upgrade, user tables in those tablespaces, that are dependent on
      Oracle-Maintained types, will not be automatically upgraded. If a type is
      evolved during the upgrade, any dependent tables need to be re-validated
      and upgraded to the latest type version AFTER the database upgrade
      completes.

  11. Upgrade the database time zone file using the DBMS_DST package.
      
      The database is using time zone file version 14 and the target 18.0.0.0.0
      release ships with time zone file version 31.
      
      Oracle recommends upgrading to the desired (latest) version of the time
      zone file.  For more information, refer to "Upgrading the Time Zone File
      and Timestamp with Time Zone Data" in the 18.0.0.0.0 Oracle Database
      Globalization Support Guide.

  12. (AUTOFIXUP) Gather dictionary statistics after the upgrade using the
      command:
      
        EXECUTE DBMS_STATS.GATHER_DICTIONARY_STATS;
      
      Oracle recommends gathering dictionary statistics after upgrade.
      
      Dictionary statistics provide essential information to the Oracle
      optimizer to help it find efficient SQL execution plans. After a database
      upgrade, statistics need to be re-gathered as there can now be tables
      that have significantly changed during the upgrade or new tables that do
      not have statistics gathered yet.

  13. Gather statistics on fixed objects after the upgrade and when there is a
      representative workload on the system using the command:
      
        EXECUTE DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
      
      This recommendation is given for all preupgrade runs.
      
      Fixed object statistics provide essential information to the Oracle
      optimizer to help it find efficient SQL execution plans.  Those
      statistics are specific to the Oracle Database release that generates
      them, and can be stale upon database upgrade.
      
      For information on managing optimizer statistics, refer to the 11.2.0.4
      Oracle Database Performance Tuning Guide.

  INFORMATION ONLY
  ================
  14. Check the Oracle documentation for the identified components for their
      specific upgrade procedure.
      
      The database upgrade script will not upgrade the following Oracle
      components:  OLAP Catalog,OWB
      
      The Oracle database upgrade script upgrades most, but not all Oracle
      Database components that may be installed.  Some components that are not
      upgraded may have their own upgrade scripts, or they may be deprecated or
      obsolete.

  ORACLE GENERATED FIXUP SCRIPT
  =============================
  All of the issues in database ORCL
  which are identified above as AFTER UPGRADE "(AUTOFIXUP)" can be resolved by
  executing the following

    SQL>@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/postupgrade_fixups.sql


==================
PREUPGRADE SUMMARY
==================
  /u01/app/oracle/cfgtoollogs/orcl/preupgrade/preupgrade.log
  /u01/app/oracle/cfgtoollogs/orcl/preupgrade/preupgrade_fixups.sql
  /u01/app/oracle/cfgtoollogs/orcl/preupgrade/postupgrade_fixups.sql

Execute fixup scripts as indicated below:

Before upgrade log into the database and execute the preupgrade fixups
@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/preupgrade_fixups.sql

After the upgrade:

Log into the database and execute the postupgrade fixups
@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/postupgrade_fixups.sql

Preupgrade complete: 2019-09-01T11:16:07
[oracle@oratest dbhome_1]$

Fix all the issues and execute preupgrade_fixups.sql

@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/preupgrade_fixups.sql


Recompile all invalid objects
@?/rdbms/admin/utlrp







Stop database and listener process that is running from 11g
shutdown immediate
lsnrctl stop



Copy network configuration files, spfile and password files to new ORACLE_HOME.




Start listener and database in upgrade mode
Change environments to 18c
Start listener
Start database in upgrade mode

lsnrctl start
sqlplus / as sysdba
startup upgrade




Set following environments. Without these environment variable I had encountered error.
cat >> .bashrc
export LANG=en_US.UTF-8
export LC_ALL="en_US.UTF-8"
source .bash_profile 

echo $LANG
echo $LC_ALL

Error I have encountered:
[oracle@oratest ~]$ cat /u01/app/oracle/product/18.0.0/dbhome_1/cfgtoollogs/orcl/upgrade20190625090048/catupgrd_datapatch_upgrade.log
SQL Patching tool version 18.0.0.0.0 Production on Tue Jun 25 09:23:57 2019
Copyright (c) 2012, 2018, Oracle.  All rights reserved.

Log file for this invocation: /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_18753_2019_06_25_09_23_57/sqlpatch_invocation.log

Connecting to database...OK
Gathering database info...done
Bootstrapping registry and package to current versions...done
Error: prereq checks failed!
verify_queryable_inventory returned ORA-20001: Latest xml inventory is not loaded into table
Prereq check failed, exiting without installing any patches.

Please refer to MOS Note 1609718.1 and/or the invocation log
/u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_18753_2019_06_25_09_23_57/sqlpatch_invocation.log
for information on how to resolve the above errors.

SQL Patching tool complete on Tue Jun 25 09:24:04 2019
[oracle@ oratest ~]$

Start Oracle database upgrading
Change directory to 18c ORACLE_HOME/bin
execute dbupgrade
cd $ORACLE_HOME/bin
./dbupgrade



Start database once up gradation is completed. Check timezone file version. If version of the file is less than 31 then apply timezone fix.

sqlplus / as sysdba
startup
SELECT * FROM v$timezone_file;


Top apply timezone fix start database in upgrade mode.
shutdown immediate
startup upgrade



Execute Timezone fix
SET SERVEROUTPUT ON
DECLARE
  l_tz_version PLS_INTEGER;
BEGIN
  l_tz_version := DBMS_DST.get_latest_timezone_version;

  DBMS_OUTPUT.put_line('l_tz_version=' || l_tz_version);
  DBMS_DST.begin_upgrade(l_tz_version);
END;
/




Start database normally and apply upgrades
shutdown immediate
startup

SET SERVEROUTPUT ON
DECLARE
  l_failures   PLS_INTEGER;
BEGIN
  DBMS_DST.upgrade_database(l_failures);
  DBMS_OUTPUT.put_line('DBMS_DST.upgrade_database : l_failures=' || l_failures);
  DBMS_DST.end_upgrade(l_failures);
  DBMS_OUTPUT.put_line('DBMS_DST.end_upgrade : l_failures=' || l_failures);
END;
/





Verify timezone file version.
SELECT * FROM v$timezone_file;

COLUMN property_name FORMAT A30
COLUMN property_value FORMAT A20

SELECT property_name, property_value
FROM   database_properties
WHERE  property_name LIKE 'DST_%'
ORDER BY property_name;





Execute post upgrade fixups once upgrade completes.
@/u01/app/oracle/cfgtoollogs/orcl/preupgrade/postupgrade_fixups.sql