January 15, 2024

Step by step guide to apply CPU patch on Oracle 19c database home

 


In this post I will be showing step by step guide to apply CPU patch on oracle database 19c. I will be applying CPU patch for December 2023(Patch no :- 35643107)




Activity Steps:

1. Check Opatch Tool Version:

  • Verify the current version of the Opatch tool. As per read me of Patch 35643107 , minimum required Opatch version should be 12.2.0.1.37 or later

 

2.Download Opatch Tool (if needed):

  • Upgrade the Opatch utility if the current version is outdated.  Download Opatch latest version or as mentioned in patch readme. In this case I will be installing 12.2.0.1.40 (Patch no 6880880)


3. Install Opatch Tool :

Take backup of existing Opatch directory before installing Opatch

[oracle@ocisoumya ~]$ cd $ORACLE_HOME

[oracle@ocisoumya dbhome_1]$ mv OPatch/ OPatch_bkp

[oracle@ocisoumya u01]$ cp -r p6880880_190000_Linux-x86-64.zip $ORACLE_HOME

[oracle@ocisoumya dbhome_1]$ unzip p6880880_190000_Linux-x86-64.zip

[oracle@ocisoumya dbhome_1]$ cd OPatch

[oracle@ocisoumya OPatch]$ ./opatch version

OPatch Version: 12.2.0.1.40

 

OPatch succeeded.

 

 

3. Backup ORACLE_HOME and orainventory:

  • Take a comprehensive backup of the ORACLE_HOME directory and orainventory.

[oracle@ocisoumya 19.3.0]$ cd /u01/app/oracle/19.3.0

[oracle@ocisoumya 19.3.0]$ zip -r oracle_19c_home.zip /u01/app/oracle/19.3.0/dbhome_1

[oracle@ocisoumya 35643107]$ cd /u01/app/

[oracle@ocisoumya app]$ ls

admin  audit  cfgtoollogs  checkpoints  diag  oracle  oradata  oraInventory

[oracle@ocisoumya app]$ cp -r oraInventory/ oraInventory_bkp

 

 

4. Shutdown Database and Listener:

  • Safely shut down the database and listener associated with the ORACLE_HOME to be patched.

[oracle@ocisoumya ~]$ sqlplus / as sysdba

 

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jan 14 08:02:02 2024

Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Connected to:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.3.0.0.0

 

SQL> shu immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> exit

 

[oracle@ocisoumya ~]$ lsnrctl stop

 

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 14-JAN-2024 08:02:40

 

Copyright (c) 1991, 2019, Oracle.  All rights reserved.

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

The command completed successfully

 

5. Apply PSU Patch:

  • Apply the CPU patch 35643107  to the specified ORACLE_HOME.

Navigate to patch directory and check for conflict using following

[oracle@ocisoumya ~]$ export PATH=/u01/app/oracle/19.3.0/dbhome_1/OPatch:$PATH

[oracle@ocisoumya ~]$ cd /u01/35643107/

 

[oracle@ocisoumya 35643107]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./

Oracle Interim Patch Installer version 12.2.0.1.40

Copyright (c) 2024, Oracle Corporation.  All rights reserved.

 

PREREQ session

 

Oracle Home       : /u01/app/oracle/19.3.0/dbhome_1

Central Inventory : /u01/app/oraInventory

   from           : /u01/app/oracle/19.3.0/dbhome_1/oraInst.loc

OPatch version    : 12.2.0.1.40

OUI version       : 12.2.0.7.0

Log file location : /u01/app/oracle/19.3.0/dbhome_1/cfgtoollogs/opatch/opatch2024-01-14_08-11-35AM_1.log

 

Invoking prereq "checkconflictagainstohwithdetail"

 

Prereq "checkConflictAgainstOHWithDetail" passed.

 

OPatch succeeded.

 

Install Patch

[oracle@ocisoumya 35643107]$ opatch apply

Oracle Interim Patch Installer version 12.2.0.1.40

Copyright (c) 2024, Oracle Corporation.  All rights reserved.

 

 

Oracle Home       : /u01/app/oracle/19.3.0/dbhome_1

Central Inventory : /u01/app/oraInventory

   from           : /u01/app/oracle/19.3.0/dbhome_1/oraInst.loc

OPatch version    : 12.2.0.1.40

OUI version       : 12.2.0.7.0

Log file location : /u01/app/oracle/19.3.0/dbhome_1/cfgtoollogs/opatch/opatch2024-01-14_08-13-23AM_1.log

 

Verifying environment and performing prerequisite checks...

OPatch continues with these patches:   35643107

 

Do you want to proceed? [y|n]

y

User Responded with: Y

All checks passed.

 

Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.

(Oracle Home = '/u01/app/oracle/19.3.0/dbhome_1')

 

 

Is the local system ready for patching? [y|n]

y

User Responded with: Y

Backing up files...

Applying interim patch '35643107' to OH '/u01/app/oracle/19.3.0/dbhome_1'

ApplySession: Optional component(s) [ oracle.network.gsm, 19.0.0.0.0 ] , [ oracle.pg4mq, 19.0.0.0.0 ] , [ oracle.rdbms.ic, 19.0.0.0.0 ] , [ oracle.rdbms.tg4db2, 19.0.0.0.0 ] , [ oracle.tfa, 19.0.0.0.0 ] , [ oracle.rdbms.tg4msql, 19.0.0.0.0 ] , [ oracle.ons.cclient, 19.0.0.0.0 ] , [ oracle.rdbms.tg4sybs, 19.0.0.0.0 ] , [ oracle.options.olap.api, 19.0.0.0.0 ] , [ oracle.network.cman, 19.0.0.0.0 ] , [ oracle.sdo.companion, 19.0.0.0.0 ] , [ oracle.xdk.companion, 19.0.0.0.0 ] , [ oracle.rdbms.tg4tera, 19.0.0.0.0 ] , [ oracle.net.cman, 19.0.0.0.0 ] , [ oracle.ons.eons.bwcompat, 19.0.0.0.0 ] , [ oracle.oid.client, 19.0.0.0.0 ] , [ oracle.rdbms.tg4ifmx, 19.0.0.0.0 ] , [ oracle.options.olap, 19.0.0.0.0 ] , [ oracle.jdk, 1.8.0.191.0 ]  not present in the Oracle Home or a higher version is found.

 

Patching component oracle.rdbms.util, 19.0.0.0.0...

 

Patching component oracle.rdbms.rsf, 19.0.0.0.0...

 

Patching component oracle.rdbms, 19.0.0.0.0...

 

 

Patching component oracle.assistants.acf, 19.0.0.0.0...

 

Patching component oracle.assistants.deconfig, 19.0.0.0.0...

 

Patching component oracle.assistants.server, 19.0.0.0.0...

 

Patching component oracle.blaslapack, 19.0.0.0.0...

 

Patching component oracle.buildtools.rsf, 19.0.0.0.0...

 

Patching component oracle.ctx, 19.0.0.0.0...

 

Patching component oracle.dbdev, 19.0.0.0.0...

 

Patching component oracle.dbjava.ic, 19.0.0.0.0...

 

Patching component oracle.dbjava.jdbc, 19.0.0.0.0...

 

Patching component oracle.dbjava.ucp, 19.0.0.0.0...

 

Patching component oracle.duma, 19.0.0.0.0...

 

Patching component oracle.javavm.client, 19.0.0.0.0...

 

Patching component oracle.ldap.owm, 19.0.0.0.0...

 

Patching component oracle.ldap.rsf, 19.0.0.0.0...

 

Patching component oracle.ldap.security.osdt, 19.0.0.0.0...

 

Patching component oracle.marvel, 19.0.0.0.0...

 

Patching component oracle.network.rsf, 19.0.0.0.0...

 

Patching component oracle.odbc.ic, 19.0.0.0.0...

 

Patching component oracle.ons, 19.0.0.0.0...

 

Patching component oracle.ons.ic, 19.0.0.0.0...

 

Patching component oracle.oracore.rsf, 19.0.0.0.0...

 

Patching component oracle.perlint, 5.28.1.0.0...

 

Patching component oracle.precomp.common.core, 19.0.0.0.0...

 

Patching component oracle.precomp.rsf, 19.0.0.0.0...

 

Patching component oracle.rdbms.crs, 19.0.0.0.0...

 

Patching component oracle.rdbms.dbscripts, 19.0.0.0.0...

 

Patching component oracle.rdbms.deconfig, 19.0.0.0.0...

 

Patching component oracle.rdbms.oci, 19.0.0.0.0...

 

Patching component oracle.rdbms.rsf.ic, 19.0.0.0.0...

 

Patching component oracle.rdbms.scheduler, 19.0.0.0.0...

 

Patching component oracle.rhp.db, 19.0.0.0.0...

 

Patching component oracle.sdo, 19.0.0.0.0...

 

Patching component oracle.sdo.locator.jrf, 19.0.0.0.0...

 

Patching component oracle.sqlplus, 19.0.0.0.0...

 

Patching component oracle.sqlplus.ic, 19.0.0.0.0...

 

Patching component oracle.wwg.plsql, 19.0.0.0.0...

 

Patching component oracle.ldap.rsf.ic, 19.0.0.0.0...

 

Patching component oracle.ldap.client, 19.0.0.0.0...

 

Patching component oracle.rdbms.dv, 19.0.0.0.0...

 

Patching component oracle.rdbms.install.common, 19.0.0.0.0...

 

Patching component oracle.rdbms.hsodbc, 19.0.0.0.0...

 

Patching component oracle.nlsrtl.rsf, 19.0.0.0.0...

 

Patching component oracle.xdk.rsf, 19.0.0.0.0...

 

Patching component oracle.odbc, 19.0.0.0.0...

 

Patching component oracle.xdk.parser.java, 19.0.0.0.0...

 

Patching component oracle.ctx.atg, 19.0.0.0.0...

 

Patching component oracle.network.listener, 19.0.0.0.0...

 

Patching component oracle.ctx.rsf, 19.0.0.0.0...

 

Patching component oracle.rdbms.hs_common, 19.0.0.0.0...

 

Patching component oracle.dbtoolslistener, 19.0.0.0.0...

 

Patching component oracle.xdk, 19.0.0.0.0...

 

Patching component oracle.rdbms.rman, 19.0.0.0.0...

 

Patching component oracle.rdbms.drdaas, 19.0.0.0.0...

 

Patching component oracle.install.deinstalltool, 19.0.0.0.0...

 

Patching component oracle.ovm, 19.0.0.0.0...

 

Patching component oracle.rdbms.install.plugins, 19.0.0.0.0...

 

Patching component oracle.mgw.common, 19.0.0.0.0...

 

Patching component oracle.xdk.xquery, 19.0.0.0.0...

 

Patching component oracle.network.client, 19.0.0.0.0...

 

Patching component oracle.ldap.ssl, 19.0.0.0.0...

 

Patching component oracle.oraolap.api, 19.0.0.0.0...

 

Patching component oracle.javavm.server, 19.0.0.0.0...

 

Patching component oracle.sdo.locator, 19.0.0.0.0...

 

Patching component oracle.oraolap, 19.0.0.0.0...

 

Patching component oracle.oraolap.dbscripts, 19.0.0.0.0...

 

Patching component oracle.rdbms.lbac, 19.0.0.0.0...

 

Patching component oracle.precomp.common, 19.0.0.0.0...

 

Patching component oracle.precomp.lang, 19.0.0.0.0...

 

Patching component oracle.jdk, 1.8.0.201.0...

Patch 35643107 successfully applied.

Sub-set patch [29517242] has become inactive due to the application of a super-set patch [35643107].

Please refer to Doc ID 2161861.1 for any possible further required actions.

Log file location: /u01/app/oracle/19.3.0/dbhome_1/cfgtoollogs/opatch/opatch2024-01-14_08-13-23AM_1.log

 

OPatch succeeded.

 

 

6. Validate Patch in Inventory:

  • Confirm the successful application of the patch in the inventory.

[oracle@ocisoumya 35643107]$ opatch lsinventory | grep 35643107

Patch  35643107     : applied on Sun Jan 14 08:16:16 GMT 2024

Patch description:  "Database Release Update : 19.21.0.0.231017 (35643107)"

 

7. Startup Database and Listener:

  • Start up the database and listener services associated with the patched Oracle home.

[oracle@ocisoumya ~]$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Jan 14 08:23:17 2024

Version 19.21.0.0.0

Copyright (c) 1982, 2022, Oracle.  All rights reserved.

 

Connected to an idle instance.

 

SQL> startup

ORACLE instance started.

 

Total System Global Area 4949276544 bytes

Fixed Size                  8935296 bytes

Variable Size             889192448 bytes

Database Buffers         4043309056 bytes

Redo Buffers                7839744 bytes

Database mounted.

Database opened.

SQL> exit

 

[oracle@ocisoumya ~]$ lsnrctl start

 

LSNRCTL for Linux: Version 19.0.0.0.0 - Production on 14-JAN-2024 08:25:10

 

Copyright (c) 1991, 2023, Oracle.  All rights reserved.

 

Starting /u01/app/oracle/19.3.0/dbhome_1/bin/tnslsnr: please wait...

 

TNSLSNR for Linux: Version 19.0.0.0.0 - Production

Log messages written to /u01/app/diag/tnslsnr/ocisoumya/listener/alert/log.xml

Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocisoumya.example.com)(PORT=1521)))

 

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 19.0.0.0.0 - Production

Start Date                14-JAN-2024 08:25:10

Uptime                    0 days 0 hr. 0 min. 0 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Log File         /u01/app/diag/tnslsnr/ocisoumya/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocisoumya.example.com)(PORT=1521)))

The listener supports no services

The command completed successfully

 

 

8. Execute Post-installation Steps (datapatch):

  • Run post-installation steps, including the execution of datapatch.

[oracle@ocisoumya ~]$ datapatch -verbose

SQL Patching tool version 19.21.0.0.0 Production on Sun Jan 14 08:26:08 2024

Copyright (c) 2012, 2023, Oracle.  All rights reserved.

 

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

 

Connecting to database...OK

Gathering database info...done

Bootstrapping registry and package to current versions...done

Determining current state...done

 

Current state of interim SQL patches:

  No interim patches found

 

Current state of release update SQL patches:

  Binary registry:

    19.21.0.0.0 Release_Update 230930151951: Installed

  SQL registry:

    Applied 19.3.0.0.0 Release_Update 190410122720 successfully on 04-OCT-23 04.48.01.858067 AM

 

Adding patches to installation queue and performing prereq checks...done

Installation queue:

  No interim patches need to be rolled back

  Patch 35643107 (Database Release Update : 19.21.0.0.231017 (35643107)):

    Apply from 19.3.0.0.0 Release_Update 190410122720 to 19.21.0.0.0 Release_Update 230930151951

  No interim patches need to be applied

 

Installing patches...

Patch installation complete.  Total patches installed: 1

 

Validating logfiles...done

Patch 35643107 apply: SUCCESS

  logfile: /u01/app/cfgtoollogs/sqlpatch/35643107/25405995/35643107_apply_ORCL_2024Jan14_08_26_38.log (no errors)

 

Automatic recompilation incomplete; run utlrp.sql to revalidate.

SQL Patching tool complete on Sun Jan 14 08:31:34 2024

 

9. Verify Patch Status from dba_registry_sqlpatch:

  • Check the status of the applied patch in the dba_registry_sqlpatch view.

SQL> COLUMN action_time FORMAT A20

SQL> COLUMN action FORMAT A10

SQL> COLUMN status FORMAT A10

SQL> COLUMN description FORMAT A60

SQL> SELECT TO_CHAR(action_time, 'DD-MON-YYYY HH24:MI:SS') AS action_time,action,status,description,patch_id FROM sys.dba_registry_sqlpatch ORDER by action_time;

 ACTION_TIME          ACTION     STATUS     DESCRIPTION                                                    PATCH_ID

-------------------- ---------- ---------- ------------------------------------------------------------ ----------

04-OCT-2023 04:48:01 APPLY      SUCCESS    Database Release Update : 19.3.0.0.190416 (29517242)           29517242

14-JAN-2024 08:31:33 APPLY      SUCCESS    Database Release Update : 19.21.0.0.231017 (35643107)          35643107





 

10. Run utlrp.sql to validate any invalid objects :

SQL> @?/rdbms/admin/utlrp.sql

 

 

This concludes the PSU patching activity on oracle home.

December 29, 2023

How to extract user DDL and all privileges of a user in oracle

We often require to extract information such as User DDL and all privileges granted including roles, system and object privileges, tablespace quota etc. Using the following method we can extract it easily.

Create a .sql file and paste the following code inside.

Note:- While executing this sql make sure to enter the username in UPPERCASE.

vi info.sql

-- Connect to target database and execute with a user that has DBA privileges

 

-- Example for user "CRPDTA" - Make sure to put the username in uppercase.

 

SET LONGCHUNKSIZE 20000 PAGESIZE 0 FEEDBACK OFF VERIFY OFF TRIMPOOL ON

COLUMN Extracted_DDL FORMAT A1000

 

EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'PRETTY', TRUE);

EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM, 'SQLTERMINATOR', TRUE);

 

UNDEFINE User_in_Uppercase;

 

SET LINESIZE 1000

SET LONG 2000000000

 

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_USERS

             WHERE USERNAME = '&&User_in_Uppercase' AND PROFILE <> 'DEFAULT') > 0

        ) THEN

            CHR(10) || ' -- Note: Profile' || (SELECT DBMS_METADATA.GET_DDL('PROFILE', U.PROFILE) AS DDL

                                               FROM DBA_USERS U

                                               WHERE U.USERNAME = '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: Default profile, no need to create!')

    END)

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_USERS

             WHERE USERNAME = '&User_in_Uppercase') > 0

        ) THEN

            ' -- Note: Create user statement' || DBMS_METADATA.GET_DDL('USER', '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: User not found!')

    END) Extracted_DDL

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_TS_QUOTAS

             WHERE USERNAME = '&User_in_Uppercase') > 0

        ) THEN

            ' -- Note: TBS quota' || DBMS_METADATA.GET_GRANTED_DDL('TABLESPACE_QUOTA', '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: No TS Quotas found!')

    END)

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_ROLE_PRIVS

             WHERE GRANTEE = '&User_in_Uppercase') > 0

        ) THEN

            ' -- Note: Roles' || DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT', '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: No granted Roles found!')

    END)

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM V$PWFILE_USERS

             WHERE USERNAME = '&User_in_Uppercase' AND SYSDBA = 'TRUE') > 0

        ) THEN

            ' -- Note: sysdba' || CHR(10) || TO_CLOB(' GRANT SYSDBA TO ' || '"' || '&User_in_Uppercase' || '"' || ';')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: No sysdba administrative Privilege found!')

    END)

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_SYS_PRIVS

             WHERE GRANTEE = '&User_in_Uppercase') > 0

        ) THEN

            ' -- Note: System Privileges' || DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT', '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: No System Privileges found!')

    END)

FROM DUAL

UNION ALL

SELECT

    (CASE

        WHEN (

            (SELECT COUNT(*)

             FROM DBA_TAB_PRIVS

             WHERE GRANTEE = '&User_in_Uppercase') > 0

        ) THEN

            ' -- Note: Object Privileges' || DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT', '&User_in_Uppercase')

        ELSE

            TO_CLOB(CHR(10) || ' -- Note: No Object Privileges found!')

    END)

FROM DUAL

/

 

Output:-

Login into database and run the sql we created above.. We used username as “PY920”

sqlplus / as sysdba

SQL> @info.sql

Enter value for user_in_uppercase: PY920

 

 -- Note: Profile

   CREATE PROFILE "UNLIM_LOG"

    LIMIT

         COMPOSITE_LIMIT UNLIMITED

         SESSIONS_PER_USER UNLIMITED

         CPU_PER_SESSION UNLIMITED

         CPU_PER_CALL UNLIMITED

         LOGICAL_READS_PER_SESSION UNLIMITED

         LOGICAL_READS_PER_CALL UNLIMITED

         IDLE_TIME UNLIMITED

         CONNECT_TIME UNLIMITED

         PRIVATE_SGA UNLIMITED

         FAILED_LOGIN_ATTEMPTS UNLIMITED

         PASSWORD_LIFE_TIME UNLIMITED

         PASSWORD_REUSE_TIME UNLIMITED

         PASSWORD_REUSE_MAX UNLIMITED

         PASSWORD_VERIFY_FUNCTION DEFAULT

         PASSWORD_LOCK_TIME UNLIMITED

         PASSWORD_GRACE_TIME UNLIMITED

         INACTIVE_ACCOUNT_TIME DEFAULT

         PASSWORD_ROLLOVER_TIME DEFAULT ;

 

 -- Note: Create user statement

   CREATE USER "PY920" IDENTIFIED BY VALUES 'S:E927BDEC46440F4264941D55A483B1C07A522B852D94203349093C5B2F2D;T:5FC638A2DA78087F85E7BABF9EA95404BD400DC6923181FE420BC91A8A11C6CD4B5D95103E1FB27E01981266C7B3F43C9AE5851EE4AFFC7BDC6066E63598D80C51295AC44FAD0651B66B72A4C2E0E639'

      DEFAULT TABLESPACE "PY920T"

      TEMPORARY TABLESPACE "TEMP2"

      PROFILE "UNLIM_LOG";

 ALTER USER "PY920" LOCAL TEMPORARY TABLESPACE "TEMP2";

 

 -- Note: TBS quota

  DECLARE

  TEMP_COUNT NUMBER;

  SQLSTR VARCHAR2(200);

BEGIN

  SQLSTR := 'ALTER USER "PY920" QUOTA UNLIMITED ON "PY920I"';

  EXECUTE IMMEDIATE SQLSTR;

EXCEPTION

  WHEN OTHERS THEN

    IF SQLCODE = -30041 THEN

      SQLSTR := 'SELECT COUNT(*) FROM USER_TABLESPACES

              WHERE TABLESPACE_NAME = ''PY920I'' AND CONTENTS = ''TEMPORARY''';

      EXECUTE IMMEDIATE SQLSTR INTO TEMP_COUNT;

      IF TEMP_COUNT = 1 THEN RETURN;

      ELSE RAISE;

      END IF;

    ELSE

      RAISE;

    END IF;

END;

/

  DECLARE

  TEMP_COUNT NUMBER;

  SQLSTR VARCHAR2(200);

BEGIN

  SQLSTR := 'ALTER USER "PY920" QUOTA UNLIMITED ON "PY920T"';

  EXECUTE IMMEDIATE SQLSTR;

EXCEPTION

  WHEN OTHERS THEN

    IF SQLCODE = -30041 THEN

      SQLSTR := 'SELECT COUNT(*) FROM USER_TABLESPACES

              WHERE TABLESPACE_NAME = ''PY920T'' AND CONTENTS = ''TEMPORARY''';

      EXECUTE IMMEDIATE SQLSTR INTO TEMP_COUNT;

      IF TEMP_COUNT = 1 THEN RETURN;

      ELSE RAISE;

      END IF;

    ELSE

      RAISE;

    END IF;

END;

/

 

 -- Note: Roles

   GRANT "JDEUSER" TO "PY920";

   GRANT "JDE_ROLE" TO "PY920";

 

 

 -- Note: No sysdba administrative Privilege found!

 

 

 -- Note: No System Privileges found!

 

 

 -- Note: No Object Privileges found!

 

SQL>

 


November 20, 2023

Steps to Clone A Pluggable Database From Existing PDB

 

Steps to Clone A Pluggable Database From Existing PDB

 

So, I had a requirement for a customer where I had to clone a PDB from existing PDB on same CDB . I followed the following steps to do this.

 

Step 1.

Put the PDB in read only mode

SQL> select name,open_mode from v$pdbs;

 

NAME OPEN_MODE

------------------------------ ----------

PDB$SEED READ ONLY

DEV READ WRITE

 

 

SQL> alter session set container=DEV;
 
Session altered.
 
SQL> select file_name from dba_data_files;
 
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/nonprod/dev/system01.dbf
/u01/app/oracle/oradata/nonprod/dev/sysaux01.dbf
/u01/app/oracle/oradata/nonprod/dev/users01.dbf
 

 

SQL> show con_name
 
CON_NAME
------------------------------
DEV
 
SQL> shu immediate;
Pluggable Database closed.
 
SQL> startup open read only
Pluggable Database opened.

 

 

 

Step 2.

Connect to the CDB and initiate PDB clone:

 

Set Oracle SID as CDB SID

[oracle@server1]$export ORACLE_SID=NONPROD

[oracle@server1]$sqlplus / as sysdba

SQL> show con_name
 
CON_NAME
------------------------------
CDB$ROOT

 

-- Clone pluggable

 

 

SQL> create pluggable database DEVCLONE from DEV FILE_NAME_CONVERT=('/u01/app/oracle/oradata/nonprod/dev','/u01/app/oracle/oradata/nonprod/devclone');

Pluggable database created.

 

 

 

Step 3:

Start the new cloned PDB In read write mode

SQL> select name,open_mode from v$pdbs;
 
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
DEV READ ONLY
DEVCLONE MOUNTED
 
SQL> alter session set CONTAINER=DEV;
 
Session altered.
 
SQL> shutdown immediate;
Pluggable Database closed.
SQL> startup
Pluggable Database opened.
SQL> show con_name
DEV

 

 

 

 

Step4:-

start the new cloned PDB( DEVCLONE)

SQL> alter session set container=DEVCLONE;
 
Session altered.
SQL> SHU IMMEDIATE
 
SQL> startup
Pluggable Database opened.
 
 
SQL> conn sys/syspassword@NONPROD as sysdba
Connected.
SQL> select name,open_mode from v$pdbs;
 
NAME OPEN_MODE
------------------------------ ----------
PDB$SEED READ ONLY
DEV READ WRITE
DEVCLONE READ WRITE

 

 

 

November 14, 2023

Oracle datapump error ORA-39077: unable to subscribe agent KUPC$A_1_083325450472000

Oracle datapump error ORA-39077: unable to subscribe agent KUPC$A_1_083325450472000

 

During import we faced following error.

Error Details:-


D:\oracle\product\19.3.0\dbhome_1\bin>impdp HOSPITAL/HOSPITAL@ORCL dumpfile=EXP_HOSPITAL_20231113140110_A.DMP logfile=IMP_HOSPITAL_20231113140110_A.LOG directory=dumps

 

Import: Release 19.0.0.0.0 - Production on Mon Nov 13 16:59:16 2023

Version 19.13.0.0.0

 

Copyright (c) 1982, 2021, Oracle and/or its affiliates.  All rights reserved.

 

Connected to: Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

ORA-31626: job does not exist

ORA-31638: cannot attach to job SYS_IMPORT_FULL_01 for user HOSPITAL

ORA-06512: at "SYS.KUPV$FT", line 1142

ORA-06512: at "SYS.KUPV$FT", line 1744

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95

ORA-06512: at "SYS.KUPV$FT_INT", line 498

ORA-39077: unable to subscribe agent KUPC$A_1_165917326000000 to queue "KUPC$C_1_20231113165917_0"

ORA-06512: at "SYS.DBMS_SYS_ERROR", line 95

ORA-06512: at "SYS.KUPC$QUE_INT", line 294

ORA-00972: identifier is too long

ORA-06512: at "SYS.DBMS_AQADM_SYS", line 9306

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 1873

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 3802

ORA-06512: at "SYS.DBMS_RULE_ADM", line 296

ORA-06512: at "SYS.DBMS_RULEADM_INTERNAL", line 106

ORA-24000: invalid value "SYS"."KUPC$C_1_20231113165917_0$10471", RULE SET should be of the form [SCHEMA.]NAME

ORA-00972: identifier is too long

ORA-06512: at "SYS.DBMS_RULEADM_INTERNAL", line 109

ORA-06512: at "SYS.DBMS_RULEADM_INTERNAL", line 97

ORA-06512: at "SYS.DBMS_RULE_ADM", line 290

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 3757

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 3709

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 1756

ORA-06512: at "SYS.DBMS_PRVTAQIS", line 1516

ORA-06512: at "SYS.DBMS_AQADM_SYS", line 9900

ORA-06512: at "SYS.DBMS_AQADM_SYS", line 9269

ORA-06512: at "SYS.DBMS_AQADM", line 881

ORA-06512: at "SYS.KUPC$QUE_INT", line 267

ORA-06512: at "SYS.KUPC$QUE_INT", line 1360

ORA-06512: at line 1

ORA-06512: at "SYS.KUPC$QUEUE_INT", line 65

ORA-06512: at "SYS.KUPV$FT_INT", line 465

ORA-06512: at "SYS.KUPV$FT", line 1664



Cause:-

Once the sequence SYS.AQ$_KUPC$DATAPUMP_QUETAB_1_N exceeds 10000, the name of a rule set then exceeds 30 characters, which should not be a problem any more with 19c version.

The max identifier length with DB compatibility set to < 12.2  is  30
The max identifier length with DB compatibility set to >= 12.2  is  128

The issue in this case was caused due to compatible setting 11.2.0.4.0, in which case the name of a rule set then cannot exceed 30 characters.

 

Solution:-

 

Since our database was of version 19c which was upgraded from 11.2.0.4 but the compatible was still set to “11.2.0.4.0”. Because of this the issue was present.

After changing the compatible parameter to “19.0.0” it was resolved

 

SQL> alter system set compatible=’19.0.0’ scope=spfile;


October 11, 2023

batch script to send email notification once if any service goes down and sends mail once service is up

Hi Everyone,

Recently I came across an issue where oracle service on windows was getting stopped due to some reason. Since customer was not using any monitoring tool, it was very hard to track when the service was going down.

To mitigate the problem , I wrote a batch script which will monitor oracleservice and listener service on windows . The script will send a mail once notifying service has gone down and once service comes back it will send another notification on email with service is running message.

Save the following script in .bat format and schedule it as per your requirement in task scheduler.

@echo off

setlocal enabledelayedexpansion

set my_date=%date%

set my_time=%TIME%

set my_hours=%my_time:~0,2%

set my_minutes=%my_time:~3,2%

set my_seconds=%my_time:~6,2%

 

rem Configure email settings

 

set TO_EMAIL=soumya.das@email.com

set FROM_EMAIL=noreply@alerts.com

set SMTP_SERVER=smtp.gmail.com

set SMTP_PORT=587 

set SMTP_USER=noreply@alerts.com

set SMTP_PASSWORD=Password

set SUBJECT="Service Monitor Alert"

 

rem List of services to monitor (add more as needed)

set "SERVICES=OracleServiceORCL OracleOraDB19Home1TNSListener"

 

rem Create a temporary file to store service status

set STATUS_FILE=status.txt

 

rem Loop through the services and check their status using PowerShell

for %%s in (%SERVICES%) do (

    sc query "%%s" | find "STATE" | find "RUNNING" >nul

    if errorlevel 1 (

        echo %%s service is not running.

        if not exist !STATUS_FILE! (

            echo Sending email notification.

            powershell -command "Send-MailMessage -From '%FROM_EMAIL%' -To '%TO_EMAIL%' -Subject '%SUBJECT%' -Body 'The %%s service is not running.' -SmtpServer '%SMTP_SERVER%' -Port %SMTP_PORT% -UseSsl -Credential (New-Object PSCredential('%SMTP_USER%', (ConvertTo-SecureString '%SMTP_PASSWORD%' -AsPlainText -Force)))"

            rem Create the status file to indicate that an alert has been sent

            echo DOWN > !STATUS_FILE!

        )

    ) else (

        echo %%s service is running.

        if exist !STATUS_FILE! (

            echo Sending email notification.

            powershell -command "Send-MailMessage -From '%FROM_EMAIL%' -To '%TO_EMAIL%' -Subject 'Service Monitor Alert' -Body 'The %%s service is now running.' -SmtpServer '%SMTP_SERVER%' -Port %SMTP_PORT% -UseSsl -Credential (New-Object PSCredential('%SMTP_USER%', (ConvertTo-SecureString '%SMTP_PASSWORD%' -AsPlainText -Force)))"

            rem Delete the status file to indicate that the service is running

            del !STATUS_FILE!

        )

    )

)

 

endlocal


Oracle Database 26ai Installation Using RPM on Oracle Linux 9 (OEL 9) – Step-by-Step Guide

  In this post I will describe the installation of Oracle Database 26ai 64-bit on Oracle Linux 9 (OL8) 64-bit. The installation requires a m...