Monday, March 2, 2020

My OCM 11g Journey

8:38 PM Posted by Dilli Raj Maharjan 2 comments
 Oracle Certified Master 11g.

My OCM badge


OCM was my BIG dream 😁. I had heard about OCM in 2005 and always dreamed to become OCM. Honestly, I was dying to become Oracle Certified Master.

I setup my mind to sit for OCM 11g exam in 2013. I enrolled for OCM 11g preparation class in August 2012. The class was phenomenal and had learned a lot from instructor Karan Dodwal. He taught us how to prepare and what to prepare for the exam like Oracle pro does. The class was not a common OCM preparation class it was an Oracle expert guiding us the proper way to prepare OCM. The class was so helpful to start my preparation. He is so inspiring and motivating. 

I had attended all pre-requisite course from Oracle University and prepared for almost four years, till 2017. Though I had good instructor for OCM preparation, my OCM preparation was lit bit  frustrating. Basically,  I did not have list of activity to be done after reading each Oracle documentation. I had 3 days work week at that time so I spent plenty of time reading entire oracle documentation word by word. Since I did not have any list of activity to practice. My preparation was like 1 step forward and 2 step backward. Due to lack of proper activity guide, I was able to prepare just 1% in entire four years.

I was desperately searching for any reference book with list of activity for each skillset. I had read reviews about few OCM books and came to know that those books had not helped people. In mid 2016, I heard about the book "OCM 11G" -by KARMAN AGJAYEV A. I did not read a single review about the book but ordered the book from Amazon. I don't know how I decided to purchase a book that costs around 8000 in my currency, may be my sixth sense insist to do that. Though it took around 3 months to reach the book to my desk, purchasing it was one of my best decision I had made ever.


My Amazon Shipping confirmation email.


For me the book is like a good map. In real, it does not matter how good the map is, mountaineer has to reach summit himself. In contrast, whatever skill the mountaineer has, without a good map he is half prepared to reach summit. So good book, work experiences and dedication of an examiner are core components to pass OCM. I am not marketing this book, but literally this book is awesome and  helped me a lot. The best part of the book is a list of activities to practice, Oracle document reference and in-depth explanation with solid and clear examples. I enjoyed a lot reading this book. Thank you Karman for writing such an awesome books. 


Me with OCM 11g book.


Finally it happened, on the 19th December, 2017 I received email from Oracle that I passed OCM. I am very thankful to my friends in Banglore: Posh Kanta Pandey, Harihar Paneru and Ajay Acharya. They are good people who had supported me  lot during my exam preparation. Without them it was not possible at all. I stayed with them for entire 2 months for the exam. Guys! you are rockstars. Thank you once again. I like to thank my family, friends and everyone who helped me to pass OCM exam.


Email from Oracle Certification Program after I passed exam.


Following are few tips I found useful during my exam.

  • Prepare exam as you do prepare for College exam. Write important point in paper and read them repeatedly. 
  • Good Typing skill is important. Accuracy is more important than words per min. Signup  for free in https://play.typeracer.com and do at least 50 type challenges every day. 
  • Good Skill to navigate Oracle Documentation. Download Oracle documentation offline. Install web server, Apache and start navigating it without Search feature.
  • Practice on Linux machine, Forget Windows. If possible install Linux on your workstation. Version of Linux should match version specified in URL http://education.oracle.com.
  • Practice with normal USB keyboard. Not a fancy and bluetooth ones
  • At least 15 days leave prior to exam. Relax and prepare well. Don't get panic.
  • Linux tips and tricks to save time. Linux short cuts for copy/paste and others.
  • Linux text editor skills. Prepare for vim.
  • Mentally prepare to become OCM. You should believe it before You have it.

A page from my notebook.

A regret 😞

I am extremely sorry for posting this post 2 years late. I must have posted it immediately after exam. I am really a badass, always waiting for right time. I was unknown, the right time is right now, that's why it is termed as present, a gift to human mankind. So guys don't wait for right time, do it now.  






Sunday, February 16, 2020

Oracle Resource Manager

9:49 PM Posted by Dilli Raj Maharjan , 1 comment

Resource Manager




Oracle Database Resource Manager enables you to limit database resources. Oracle Database Resource Manager lets you specify how much of the resources you want to assign. It provides granular control of database resources allocated to users, applications, and services. It can be used to guarantee certain session a minimum and maximum amount of CPU. Limiting parallelism, active session pools to control maximum number of sessions within the group. The most interesting features is manage runaway sessions and switch groups. Manage runaway sessions help us with terminating user session whenever a session or call consumes more than specified resources. Any session in a particular group can be switched to another group if the session consumes more than specified resource.

Elements of Oracle Database Resource Manager

1. Resource consumer group
2. Resource plan
3. Resource plan directive

Resource consumer group is collection of user based on their need. SYS_GROUP and OTHER_GROUPS are two predefined groups. User SYS and SYSTEM belongs to SYS_GROUP and all other users within a plan that do not belongs to any group falls in OTHER_GROUPS.

Resource plan is the directives stating how the resource should be shared among the consumer groups.

The set of Reource plan directive determines how resources will be distributed among the users with in a Resource Plan.

Create dummy table for testing.



Copying data from same table to the table.

 
 


Create Service for single instance database.

 

Start service.



 Check if service is listed on listener or not



Create pending area. If any already existing pending area.



Create Resource Manager Plan.



Create Plan Directives



Mapping services SRV_DEV to Resource Consumer Group.



Validate pending area.



Submit pending area.



Create tnsnames.



Connecting user using tnsnames.



Check current user is logged in using the services.



Execute cpu intensive query as user DILLI.



 Show oracle resource related parameters.



 Noticed CPU load has increased and PID 2519 has consumed 99.9% of CPU.



Set resource manager plan to DAY_PLAN.



Noticed CPU usage has decreased to 3.7% load.



Revert back the resource manager plan.



Noticed CPU% has increased to 99.9% for PID 2519.



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