Oracle 18c – Cancel SQL Statement in a Session

Description:-

Before 18c, If we want to terminate a SQL query for consuming excessive resources in a session or to cancel the blocking session or cancel incorrect SQL statement, the only way is to find out the particular session’s SID, SERIAL id and the kill the session using following command ALTER SYSTEM KILL SESSION ‘sid,serial#’;.

After 18c, instead of kill the originating session we can cancel the particular SQL of another session using “ALTER SYSTEM CANCEL SQL ‘SID, SERIAL'”.
If we are cancel a DML statement, the statement has been rolled backed.

SQL> select banner_full from v$version;

BANNER_FULL
———————————————————–
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.2.0.0.0

Step:1 To find the SID for current session.

SQL> select distinct sid from v$mystat;

SID
———-
280

SQL> begin loop null; end loop; end;
/

Step:2 This command help us to find out the SQL_ID using the SQL_TEXT from particular SQL statement. 

SQL> select sql_text,sql_id from v$sql where sql_text like ‘%loop null; end loop%’;

SQL_TEXT                                                                                                    SQL_ID
——- ————————–                                   ————-
select sql_text,sql_id from v$sql                                                       6vbb9d7zj9t5w where sql_text like ‘%loop null; end loop%’

begin loop null; end loop; end;                                                              3tfmdd4xagv3y

Step:3 To find the SERIAL# using the session ID.

SQL> select serial# from v$session where sid=280;

SERIAL#
———-
22827

Step:4 Here is the syntax of cancelling a SQL statement.

ALTER SYSTEM CANCEL SQL ‘SID, SERIAL’

SQL> alter system cancel sql ‘280,22827,3tfmdd4xagv3y’;

System altered.

SQL> begin
loop null;
end loop;
end;
/
begin
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

 

Catch Me On:- Hariprasath Rajaram

LinkedIn:    https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:   https://www.facebook.com/HariPrasathdba
FB Group:   https://www.facebook.com/groups/894402327369506/
FB Page:      https://www.facebook.com/dbahariprasath/?
Twitter:       https://twitter.com/hariprasathdba

Upgrade Oracle 18c Cloud Database from 18.1 to 18.2

Description:-

  • In this article we are going to upgrade the oracle 18c cloud database from 18.1 to 18.2
  • Oracle release the first Update (RU) 18.2.0  on April 2018.
  • Creating a Free Account In Oracle Cloud Here
  • Creating an Oracle 18c Database Cloud Service Instance Here

Patch Information:-

  • 18.2 Release update released on April18.
  • Database Apr 2018 Release Update (DB RU) 18.2.0.0.180417 (Doc ID 27676517.8)

Prerequisites:-

  • 18c Cloud Database Creation
  • Check the Opatch utility version.
  • You must have the Opatch utility version 12.2.0.1.13 or later version
  • If not we need to upgrade the Opatch utility version to 12.2.0.1.13 .
  • Which is available for download in My Oracle support Patch 6880880
                           Creating 18c database on Oracle Cloud

Step:1 18c Cloud Database Creation

Step 1:  Log in to your Oracle Cloud services account,                                                                 go to the Oracle Database Cloud Service page, and                                                       create a new service:- For Instance Name enter oracle18c.

– From the Software Release list, select Oracle Database 18c.
– From the Software Edition list, select Enterprise Edition.
– From the Database Type list, select Single Instance.Then click Next to continue.

Step 2:  In the Service Details screen, do the following:- For DB Name (SID), enter oracle18c and PDB Name, enter PDB1.
– Set an administrative password of your choice and confirm the password (this will be your sys password).
– For Usable Database Storage (GB), enter 25.
– From the Compute Shape list, select OC3 -1.0 OCPU, 7.5 GB RAM (this is the bare minimum required).
– For SSH Public Key, enter publickey.

Step 3: Finally, review the configuration and click Create to create your cloud database.

 After a few minutes, the cloud database instance has been created successfully.

Connect to the Cloud Database

  • We need to generate a public key and private key to use cloud instance.
  • Open an instance of the PuTTY executable and connect to the Oracle Database Cloud Service compute node using an SSH public key.

Step:2 Check the Opatch utility version

[oracle@orcl18c ~]$ cd $ORACLE_HOME/OPatch
[oracle@orcl18c OPatch]$ ./opatch version
OPatch Version: 12.2.0.1.11
OPatch succeeded.

Step:3 upgrade the Opatch utility version

[oracle@orcl18c ~]$ cd $ORACLE_HOME/OPatch
[oracle@orcl18c OPatch]$
[oracle@orcl18c OPatch]$ ./opatch version
OPatch Version: 12.2.0.1.13
OPatch succeeded.

Installation:-

  • Patch Pre-Installation
  • Patch Installation
  • Patch Post-installation

Patch pre-Installation:-

Step:-1 Environment checks

[oracle@test18c ~]$ export PATH=$PATH:$ORACLE_HOME/OPatch:$ORACLE_HOME/bin
[oracle@test18c ~]$ opatch version
OPatch Version: 12.2.0.1.13
OPatch succeeded.

Step:-2 Check database version

[oracle@orcl18c ~]$ sqlplus ‘/as sysdba’

SQL*Plus: Release 18.0.0.0.0 Production on Thu May 10 19:57:23 2018
Version 18.1.0.0.0
Copyright (c) 1982, 2017, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.1.0.0.0

Pluggable Database

SQL> show pdbs

CON_ID CON_NAME                       OPEN MODE           RESTRICTED
———- ———                  ———-         ———-
2 PDB$SEED                                            READ ONLY                    NO
3 CDB2DEMO                                          MOUNTED
4 PDB1                                                       READ WRITE                   NO

Step:-3 Interim Patch Conflict Detection and Resolution

[oracle@orcl18c ~]$ cd 27676517
[oracle@test18c 27676517]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./
Oracle Interim Patch Installer version 12.2.0.1.13
Copyright (c) 2018, Oracle Corporation. All rights reserved.

PREREQ session
Oracle Home : /u01/app/oracle/product/18.0.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/18.0.0/dbhome_1/oraInst.loc
OPatch version : 12.2.0.1.13
OUI version : 12.2.0.4.0
Log file location : /u01/app/oracle/product/18.0.0/dbhome_1/cfgtoollogs/opatch/opatch2018-05-10_20-18-12PM_1.log
Invoking prereq "checkconflictagainstohwithdetail"
Prereq "checkConflictAgainstOHWithDetail" passed.
OPatch succeeded.

Patch Installation:-

• It is not Rac database so we need to shutdown the databases and listeners associated with Oracle home.

Step:-1 Stop the CDB & PDB database and listener

[oracle@orcl18c ~]$ sqlplus ‘/as sysdba’

SQL*Plus: Release 18.0.0.0.0 Production on Thu May 10 20:29:00 2018
Version 18.1.0.0.0
Copyright (c) 1982, 2017, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.1.0.0.0

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.1.0.0.0

SQL> ALTER PLUGGABLE DATABASE all CLOSE IMMEDIATE;

Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME        OPEN MODE            RESTRICTED
———- —————————— —-
2 PDB$SEED                         READ ONLY                   NO
3 CDB2DEMO                        MOUNTED
4 PDB1                                     MOUNTED

[oracle@orcl18c ~]$ lsnrctl stop

LSNRCTL for Linux: Version 18.0.0.0.0 – Production on 10-MAY-2018 20:30:33
Copyright (c) 1991, 2017, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test18c.compute-600163227.oraclecloud.internal)(PORT=1521)))
The command completed successfully

• Go to the Patch directory and unzip the patch (27606517).

[oracle@orcl18c ~]$ cd 27676517/
[oracle@orcl18c 27676517]$ opatch apply
Oracle Interim Patch Installer version 12.2.0.1.13
Copyright (c) 2018, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/18.0.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/18.0.0/dbhome_1/oraInst.loc
OPatch version : 12.2.0.1.13
OUI version : 12.2.0.4.0
Log file location : /u01/app/oracle/product/18.0.0/dbhome_1/cfgtoollogs/opatch/opatch2018-05-10_20-32-57PM_1.log
Verifying environment and performing prerequisite checks...
OPatch continues with these patches: 27676517
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/product/18.0.0/dbhome_1')
Is the local system ready for patching? [y|n] y
User Responded with: Y
Backing up files...
Applying interim patch '27676517' to OH '/u01/app/oracle/product/18.0.0/dbhome_1'
ApplySession: Optional component(s) [ oracle.assistants.usm, 18.0.0.0.0 ] , [ oracle.has.crs, 18.0.0.0.0 ] , [ oracle.network.cman, 18.0.0.0.0 ] , [ oracle.assistants.asm, 18.0.0.0.0 ] not present in the Oracle Home or a higher version is found.
Patching component oracle.network.rsf, 18.0.0.0.0...
Patching component oracle.rdbms.crs, 18.0.0.0.0...
Patching component oracle.assistants.acf, 18.0.0.0.0...
Patching component oracle.sqlplus.ic, 18.0.0.0.0...
Patching component oracle.rdbms.deconfig, 18.0.0.0.0...
Patching component oracle.sqlplus, 18.0.0.0.0...
Patching component oracle.rdbms.util, 18.0.0.0.0...
Patching component oracle.rdbms, 18.0.0.0.0...
Patching component oracle.rdbms.dbscripts, 18.0.0.0.0...
Patching component oracle.assistants.deconfig, 18.0.0.0.0...
Patching component oracle.assistants.server, 18.0.0.0.0...
Patching component oracle.rdbms.install.plugins, 18.0.0.0.0...
Patching component oracle.rdbms.rsf, 18.0.0.0.0...
Patching component oracle.rdbms.rman, 18.0.0.0.0...
Patching component oracle.javavm.client, 18.0.0.0.0...
Patching component oracle.ldap.owm, 18.0.0.0.0...
Patching component oracle.ldap.security.osdt, 18.0.0.0.0...
Patch 27676517 successfully applied.
Log file location: /u01/app/oracle/product/18.0.0/dbhome_1/cfgtoollogs/opatch/opatch2018-05-10_20-32-57PM_1.log
OPatch succeeded.

Patch Post-installation:-

• Run the Datapatch Utility for load the modified sql files into database.
• Check the invalids in the database and run the Utlrp.sql script
• Finally checks the dba_registry table.

Step:-1 Start the CDB & PDB database and listener

[oracle@orcl18c ~]$ sqlplus ‘/as sysdba’
SQL*Plus: Release 18.0.0.0.0 – Production on Thu May 10 20:52:23 2018
Version 18.2.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 2768239832 bytes
Fixed Size 8899800 bytes
Variable Size 704643072 bytes
Database Buffers 1979711488 bytes
Redo Buffers 74985472 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.2.0.0.0

Pluggable Database

SQL> ALTER PLUGGABLE DATABASE all open;
Pluggable database altered.

SQL> show pdbs

CON_ID CON_NAME OPEN MODE     RESTRICTED
———- —————————— ———- ———-
2 PDB$SEED                      READ ONLY             NO
3 CDB2DEMO                     READ WRITE         NO
4 PDB1                                  READ WRITE         NO

[oracle@orcl18c ~]$ lsnrctl start
LSNRCTL for Linux: Version 18.0.0.0.0 - Production on 10-MAY-2018 20:52:52
Copyright (c) 1991, 2017, Oracle. All rights reserved.
Starting /u01/app/oracle/product/18.0.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 18.0.0.0.0 - Production
System parameter file is /u01/app/oracle/product/18.0.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/test18c/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test18c.compute-600163227.oraclecloud.internal)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=test18c.compute-600163227.oraclecloud.internal)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 18.0.0.0.0 - Production
Start Date 10-MAY-2018 20:52:52
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/18.0.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/test18c/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=test18c.compute-600163227.oraclecloud.internal)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

Step:-2 Run the Datapatch Utility

[oracle@orcl18c OPatch]$ ./datapatch -verbose
SQL Patching tool version 18.0.0.0.0 Production on Thu May 10 20:56:25 2018
Copyright (c) 2012, 2018, Oracle. All rights reserved.
Log file for this invocation: /u01/app/oracle/cfgtoollogs/sqlpatch/sqlpatch_20960_2018_05_10_20_56_25/sqlpatch_invocation.log
Connecting to database...OK
Gathering database info...done
Note: Datapatch will only apply or rollback SQL fixes for PDBs
that are in an open state, no patches will be applied to closed PDBs.
Please refer to Note: Datapatch: Database 12c Post Patch SQL Automation
(Doc ID 1585822.1)
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:
18.2.0.0.0 Release_Update 1804041635: Installed
PDB CDB$ROOT:
Applied 18.2.0.0.0 Release_Update 1804041635 successfully on 24-APR-18 06.47.32.392156 PM
PDB PDB$SEED:
Applied 18.2.0.0.0 Release_Update 1804041635 successfully on 24-APR-18 06.47.32.950357 PM
PDB PDB1:
Applied 18.2.0.0.0 Release_Update 1804041635 successfully on 24-APR-18 06.47.33.780279 PM
Adding patches to installation queue and performing prereq checks...done
Installation queue:
For the following PDBs: CDB$ROOT PDB$SEED PDB1
No interim patches need to be rolled back
No release update patches need to be installed
No interim patches need to be applied
SQL Patching tool complete on Thu May 10 20:56:56 2018

Step:3 Invalid checks

SQL> COLUMN object_name FORMAT A30
SELECT owner,
object_type,
object_name,
status
FROM dba_objects
WHERE status = ‘INVALID’
ORDER BY owner, object_type, object_name;

OWNER OBJECT_TYPE                    OBJECT_NAME                                 STATUS
——— ———— ———————- ————-
C##DBAAS_MONITOR                     SYNONYM DBM_REGISTRY      INVALID
MDSYS                                                      FUNCTION SDO_VERSION         INVALID
MDSYS                                                     PACKAGE BODY MD_NET          INVALID

3 rows selected.

SQL> exit
Disconnected from Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.2.0.0.0
[oracle@orcl18c OPatch]$ sqlplus ‘/as sysdba’
SQL*Plus: Release 18.0.0.0.0 – Production on Thu May 10 21:01:01 2018
Version 18.2.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.2.0.0.0

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

Session altered.

TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_BGN 2018-05-10 21:01:14

DOC> The following PL/SQL block invokes UTL_RECOMP to recompile invalid
DOC> objects in the database. Recompilation time is proportional to the
DOC> number of invalid objects in the database, so this command may take
DOC> a long time to execute on a database with a large number of invalid
DOC> objects.
DOC>
DOC> Use the following queries to track recompilation progress:
DOC>
DOC> 1. Query returning the number of invalid objects remaining. This
DOC> number should decrease with time.
DOC> SELECT COUNT(*) FROM obj$ WHERE status IN (4, 5, 6);
DOC>
DOC> 2. Query returning the number of objects compiled so far. This number
DOC> should increase with time.
DOC> SELECT COUNT(*) FROM UTL_RECOMP_COMPILED;
DOC>
DOC> This script automatically chooses serial or parallel recompilation
DOC> based on the number of CPUs available (parameter cpu_count) multiplied
DOC> by the number of threads per CPU (parameter parallel_threads_per_cpu).
DOC> On RAC, this number is added across all RAC nodes.
DOC>
DOC> UTL_RECOMP uses DBMS_SCHEDULER to create jobs for parallel
DOC> recompilation. Jobs are created without instance affinity so that they
DOC> can migrate across RAC nodes. Use the following queries to verify
DOC> whether UTL_RECOMP jobs are being created and run correctly:
DOC>
DOC> 1. Query showing jobs created by UTL_RECOMP
DOC> SELECT job_name FROM dba_scheduler_jobs
DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>
DOC> 2. Query showing UTL_RECOMP jobs that are running
DOC> SELECT job_name FROM dba_scheduler_running_jobs
DOC> WHERE job_name like 'UTL_RECOMP_SLAVE_%';
DOC>#
PL/SQL procedure successfully completed.
TIMESTAMP
--------------------------------------------------------------------------------
COMP_TIMESTAMP UTLRP_END 2018-05-10 21:01:27
DOC> The following query reports the number of invalid objects.
DOC>
DOC> If the number is higher than expected, please examine the error
DOC> messages reported with each object (using SHOW ERRORS) to see if they
DOC> point to system misconfiguration or resource constraints that must be
DOC> fixed before attempting to recompile these objects.
DOC>#
OBJECTS WITH ERRORS
-------------------
0
DOC> The following query reports the number of exceptions caught during
DOC> recompilation. If this number is non-zero, please query the error
DOC> messages in the table UTL_RECOMP_ERRORS to see if any of these errors
DOC> are due to misconfiguration or resource constraints that must be
DOC> fixed before objects can compile successfully.
DOC> Note: Typical compilation errors (due to coding errors) are not
DOC> logged into this table: they go into DBA_ERRORS instead.
DOC>#
ERRORS DURING RECOMPILATION
---------------------------
0
Function created.
PL/SQL procedure successfully completed.
Function dropped.
PL/SQL procedure successfully completed.

SQL> COLUMN object_name FORMAT A30
SELECT owner,
object_type,
object_name,
status
FROM dba_objects
WHERE status = 'INVALID'
ORDER BY owner, object_type, object_name;

no rows selected

Step:4 Query to check Patch has been applied physically.

SQL> alter system set “_exclude_seed_cdb_view”=false scope=both;
System altered.

SQL> select patch_id, patch_type, action, status,con_id from cdb_registry_sqlpatch order by con_id, action_time;
PATCH_ID PATCH_TYPE ACTION STATUS CON_ID
———- ———- ————— ————————-
27676517 RU APPLY SUCCESS 1
27676517 RU APPLY SUCCESS 2
27676517 RU APPLY SUCCESS 4

Step:5 Database upgrade

SQL> select banner_full from v$version;
BANNER_FULL
——————————————————————————–
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 – Production
Version 18.2.0.0.0

Summary:-
Here successfully applied the RU patch and upgrade the Cloud 18c database.
Upgrade the database from 18.1 to 18.2

References:-
https://updates.oracle.com/Orion/Services/download?type=readme&aru=22097537

 

Catch Me On:- Hariprasath Rajaram

LinkedIn:    https://www.linkedin.com/in/hari-prasath-aa65bb19/
Facebook:   https://www.facebook.com/HariPrasathdba
FB Group:   https://www.facebook.com/groups/894402327369506/
FB Page:      https://www.facebook.com/dbahariprasath/?
Twitter:       https://twitter.com/hariprasathdba