Tales From A Lazy Fat DBA

Its all about Databases & their performance, troubleshooting & much more …. ¯\_(ツ)_/¯

Archive for April, 2023

Auto Transaction Rollback in Oracle 23c – Is this the end of Row Lock Contention in Oracle Database ?

Posted by FatDBA on April 14, 2023

Hi Guys,

Oracle 23c is full of great features, one of the outstanding feature added to the version is the Automatic Transaction Rollback … Means no more long transaction level locking or the infamous event ‘enq: TX row lock contention‘ or the pessimistic locking 🙂

In case of a row level locking or pessimistic level locking where a single row of a table was locked by one of the following statements INSERT, UPDATE, DELETE, MERGE, and SELECT … FOR UPDATE. The row level lock from first session will exist it performs the rollback or a commit. This situation becomes severe in some case i.e. The application modifies some rows but doesn’t commit or terminate the transaction because of an exception in the application. Traditionally, in such cases the database administrator have to manually terminate the blocking transaction by killing the parent session.

Oracle 23c has come up with a brilliant feature which it implements through a session settings to control the transaction priority. Transaction priority (TXN_PRIORITY) is set at session level using ALTER SESSION command. Once the transaction priority is set, it will remain the same for all the transactions created in that session. This parameter specifies a priority (HIGH, MEDIUM, or LOW) for all transactions in a user session. When running in ROLLBACK mode, you can track the performance of Automatic Transaction Rollback by monitoring the following statistics:

TXN_AUTO_ROLLBACK_HIGH_PRIORITY_WAIT_TARGET This param specifies the max number of seconds that a HIGH priority txn will wait for a row lock. Similarly, there is another parameter for MEDIUM classed statements TXN_AUTO_ROLLBACK_MEDIUM_PRIORITY_WAIT_TARGET which specifies the max number of seconds that a MEDIUM priority txn will wait for a row lock.

Lets do a quick demo to explain this behavior in details.

I have created a small table with two rows and two columns and will use it for this demo to test automatic txn rollback features. To show a quick demo, I will set txn_auto_rollback_high_priority_wait_target to a lower value of 15 seconds. Will issue an UPDATE statement from the first session after setting the TXN_PRIORITY to ‘LOW‘ at the session level and will open a parallel session (session 2) and issue the same statement where the it will try to modify the same row already in exclusive lock mode by session 1.




--------------------------------------
-- SESSION 1 
--------------------------------------

[oracle@mississauga ~]$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Fri Apr 14 22:46:34 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle.  All rights reserved.
Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL>
SQL> select * from dixit;

        ID NAME
---------- --------------------
       999 Fatdba
       101 Prashant

SQL> select to_number(substr(dbms_session.unique_session_id,1,4),'XXXX') mysid from dual;  

     MYSID
----------
        59

SQL> show parameter TXN_AUTO_ROLLBACK_HIGH_PRIORITY_WAIT_TARGET

NAME                                         TYPE        VALUE
-------------------------------------------- ----------- ------------------------------
txn_auto_rollback_high_priority_wait_target  integer     15

SQL> alter session set TXN_PRIORITY=LOW;

Session altered.

SQL> show parameter TXN_PRIORITY

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
txn_priority                         string      LOW


-- I will now issue update and don't issue ROLLBACK or COMMIT 
SQL> update dixit set id=101010101 where name='Fatdba';

1 row updated.

SQL > 

Okay so the stage is set! We’ve already ran an UPDATE statement on the table from SESSION 1 (SID : 59) and I will open a new session (session 2) and issue the same statement, but here the txn_priority is set to its default ‘HIGH‘ and we’ve already set txn_auto_rollback_high_priority_wait_target to 15 seconds earlier.




--------------------------------------
-- SESSION 2 
--------------------------------------

[oracle@mississauga ~]$ sqlplus / as sysdba

SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Fri Apr 14 22:46:34 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle.  All rights reserved.
Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL>
SQL> select to_number(substr(dbms_session.unique_session_id,1,4),'XXXX') mysid from dual; 

     MYSID
----------
       305

SQL> show parameter TXN_PRIORITY;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
txn_priority                         string      HIGH

-- Now this session will go into blocking state. 
SQL> update dixit set id=0 where name='Fatdba';
...
.....


Alright, so session 2 (SID : 305) with txn_priority=HIGH is now blocked, as the row was first locked in exclusive mode by session 1 (SID : 59), but we’ve set TXN_PRIORITY=LOW (at session level) and system level change of TXN_AUTO_ROLLBACK_HIGH_PRIORITY_WAIT_TARGET to 15 seconds,

Lets query the database and see what is waiting on what ?? You will see SID 305 (session 2) is waiting for the txn level lock and waiting on event ‘enq: TX – row lock (HIGH priority)‘. BTW, this also a new event added into Oracle 23c for sessions waiting with HIGH priorities, other two are for LOW and MEDIUM priorities.

SQL>
SQL> select event#, name, WAIT_CLASS from v$event_name where name like '%TX - row%';

    EVENT# NAME                                                             WAIT_CLASS
---------- ---------------------------------------------------------------- ----------------------------------------------------------------
       340 enq: TX - row lock contention                                    Application
       341 enq: TX - row lock (HIGH priority)                               Application
       342 enq: TX - row lock (MEDIUM priority)                             Application
       343 enq: TX - row lock (LOW priority)                                Application

SQL>



-----------------------------------------------------------------
-- Contention details (What has blocked what ?)   
-----------------------------------------------------------------


SQL>

 INST_ID        SID    SERIAL# USERNAME                                                                                                                     SQL_ID PLAN_HASH_VALUE DISK_READS BUFFER_GETS ROWS_PROCESSED EVENT
---------- ---------- ---------- -------------------------------------------------------------------------------------------------------------------------------- ------------- --------------- ---------- ----------- -------------- ----------------------------------------------------------------
OSUSER                                                                                                                           STATUS   BLOCKING_SE BLOCKING_INSTANCE BLOCKING_SESSION PROCESS               MACHINE                                                          PROGRAM
-------------------------------------------------------------------------------------------------------------------------------- -------- ----------- ----------------- ---------------- ------------------------ ---------------------------------------------------------------- ------------------------------------------------------------------------------------
MODULE                                                           ACTION                                                           LOGONTIME           LAST_CALL_ET SECONDS_IN_WAIT STATE
---------------------------------------------------------------- ---------------------------------------------------------------- ------------------- ------------ --------------- -------------------
SQL_TEXT
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
RUNNING_SIN
-----------
         1        305      15926 SYS                                                                                                                          9jwbjqg195zdw      2635034114   0           6              0 enq: TX - row lock (HIGH priority)
oracle                                                                                                                           ACTIVE   VALID                   1        59 8808                     mississauga.candomain                                            sqlplus@mississauga.candomain (TNS V1-V3)
sqlplus@mississauga.candomain (TNS V1-V3)                                                                                         04-14-2023 22:46:35       12               13 WAITING
update dixit set id=00000000 where name='Fatdba'
00:00:12

The session 2 (SID 305) will wait for 15 seconds and database will automatically snipes session 1 (SID 59) due to LOW priority and UPDATE issued by Session 2 will persist, whereas session 1 (SID 59) and will throw “ORA-03135: connection lost contact”.

-- SESSION 1 with SID 59 
SQL>
SQL> select * from dixit;
select * from dixit
       *
ERROR at line 1:
ORA-03135: connection lost contact
Process ID: 8843
Session ID: 59 Serial number: 31129


-- SESSION 2 with SID 305 
SQL> update dixit set id=0 where name='Fatdba';

1 row updated.

SQL>    select * from dixit;

        ID NAME
---------- --------------------
         0 Fatdba
       101 Prashant

SQL>

Hope It Helped!
Prashant Dixit

Advertisement

Posted in Uncategorized | Tagged: , , , | 1 Comment »

Exploring new shiny Oracle 23 Developer Free Release …

Posted by FatDBA on April 8, 2023

Hi All,

Oracle on April 3, 2023 announced a free version of Oracle Database 23c (Release 23.0.0.0.0 – Developer-Release). Oracle Database 23c Free—Developer Release is available for download as a Docker Image, VirtualBox VM, or Linux RPM installation file, without requiring a user account or login.

Oracle 23c has a long list of new features, example Boolean datatype, No select from DUAL table just select it from the expression, lock free DMLs, joins in UPDATE & DELETE statements, 4096 columns in a table. Some of the development related additions i.e. drop table if exists, create table if not exists, Java script in the database (MLE), Multiple rows in a single insert command, store data as JSON and as relational both etc.

This long weekend gave me an opportunity to test the new Oracle 23c Developer release. This post is to explain the easy installation of the database on Oracle Linux 8 using RPM. You have to download Oracle 23c preinstall and core/main RPM file. Get it from the download link https://www.oracle.com/database/technologies/free-downloads.html

[root@mississauga files]#
[root@mississauga files]# ls
oracle-database-free-23c-1.0-1.el8.x86_64.rpm  oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
[root@mississauga files]# yum install oracle-database-preinstall-23c-1.0-0.5.el8.x86_64.rpm
Last metadata expiration check: 0:03:51 ago on Sat 08 Apr 2023 01:17:02 PM EDT.
Dependencies resolved.
=============================================================================================================================================================
 Package                                          Architecture             Version                                 Repository                           Size
=============================================================================================================================================================
Installing:
 oracle-database-preinstall-23c                   x86_64                   1.0-0.5.el8                             @commandline                         30 k
Installing dependencies:
 compat-openssl10                                 x86_64                   1:1.0.2o-4.el8_6                        ol8_appstream                       1.1 M
 ksh                                              x86_64                   20120801-257.0.1.el8                    ol8_appstream                       929 k
 libnsl                                           x86_64                   2.28-211.0.1.el8                        ol8_baseos_latest                   105 k

Transaction Summary
=============================================================================================================================================================
Install  4 Packages

Total size: 2.2 M
Total download size: 2.1 M
Installed size: 6.3 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): libnsl-2.28-211.0.1.el8.x86_64.rpm                                                                                    548 kB/s | 105 kB     00:00
(2/3): compat-openssl10-1.0.2o-4.el8_6.x86_64.rpm                                                                            4.5 MB/s | 1.1 MB     00:00
(3/3): ksh-20120801-257.0.1.el8.x86_64.rpm                                                                                   3.5 MB/s | 929 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        7.9 MB/s | 2.1 MB     00:00
Oracle Linux 8 BaseOS Latest (x86_64)                                                                                        3.0 MB/s | 3.1 kB     00:00
Importing GPG key 0xAD986DA3:
 Userid     : "Oracle OSS group (Open Source Software group) <build@oss.oracle.com>"
 Fingerprint: 76FD 3DB1 3AB6 7410 B89D B10E 8256 2EA9 AD98 6DA3
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                     1/1
  Installing       : ksh-20120801-257.0.1.el8.x86_64                                                                                                     1/4
  Running scriptlet: ksh-20120801-257.0.1.el8.x86_64                                                                                                     1/4
  Installing       : compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                            2/4
  Running scriptlet: compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                            2/4
  Installing       : libnsl-2.28-211.0.1.el8.x86_64                                                                                                      3/4
  Installing       : oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                   4/4
  Running scriptlet: oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                   4/4
  Verifying        : libnsl-2.28-211.0.1.el8.x86_64                                                                                                      1/4
  Verifying        : compat-openssl10-1:1.0.2o-4.el8_6.x86_64                                                                                            2/4
  Verifying        : ksh-20120801-257.0.1.el8.x86_64                                                                                                     3/4
  Verifying        : oracle-database-preinstall-23c-1.0-0.5.el8.x86_64                                                                                   4/4

Installed:
  compat-openssl10-1:1.0.2o-4.el8_6.x86_64 ksh-20120801-257.0.1.el8.x86_64 libnsl-2.28-211.0.1.el8.x86_64 oracle-database-preinstall-23c-1.0-0.5.el8.x86_64

Complete!


[root@mississauga files]#
[root@mississauga files]# dnf -y localinstall /root/Desktop/files/oracle-database-free-23c-1.0-1.el8.x86_64.rpm
Last metadata expiration check: 0:05:23 ago on Sat 08 Apr 2023 01:17:02 PM EDT.
Dependencies resolved.
=============================================================================================================================================================
 Package                                          Architecture                   Version                          Repository                            Size
=============================================================================================================================================================
Installing:
 oracle-database-free-23c                         x86_64                         1.0-1                            @commandline                         1.6 G

Transaction Summary
=============================================================================================================================================================
Install  1 Package

Total size: 1.6 G
Installed size: 5.2 G
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                     1/1
  Running scriptlet: oracle-database-free-23c-1.0-1.x86_64                                                                                               1/1
  Installing       : oracle-database-free-23c-1.0-1.x86_64                                                                                               1/1
  Running scriptlet: oracle-database-free-23c-1.0-1.x86_64                                                                                               1/1
[INFO] Executing post installation scripts...
[INFO] Oracle home installed successfully and ready to be configured.
To configure Oracle Database Free, optionally modify the parameters in '/etc/sysconfig/oracle-free-23c.conf' and then run '/etc/init.d/oracle-free-23c configure' as root.

  Verifying        : oracle-database-free-23c-1.0-1.x86_64                                                                                               1/1

Installed:
  oracle-database-free-23c-1.0-1.x86_64

Complete!
[root@mississauga files]#
[root@mississauga files]#


[root@mississauga ~]# cd /etc/init.d
[root@mississauga init.d]# ls
functions  oracle-database-preinstall-23c-firstboot  oracle-free-23c  README
[root@mississauga init.d]# /etc/init.d/oracle-free-23c configure
Specify a password to be used for database accounts. Oracle recommends that the password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9]. Note that the same password will be used for SYS, SYSTEM and PDBADMIN accounts:
Confirm the password:
Configuring Oracle Listener.

        Listener configuration succeeded.
Configuring Oracle Database FREE.
Enter SYS user password:                                                                                                                                    **********
Enter SYSTEM user password:
*******
Enter PDBADMIN User Password:
***********
Prepare for db operation
7% complete
Copying database files
29% complete
Creating and starting Oracle instance
30% complete
33% complete
36% complete
39% complete
43% complete
Completing Database Creation
47% complete
49% complete
50% complete
Creating Pluggable Databases
54% complete
71% complete
Executing Post Configuration Actions
93% complete
Running Custom Scripts
100% complete
Database creation complete. For details check the logfiles at:
 /opt/oracle/cfgtoollogs/dbca/FREE.
Database Information:
Global Database Name:FREE
System Identifier(SID):FREE
Look at the log file "/opt/oracle/cfgtoollogs/dbca/FREE/FREE.log" for further details.

Connect to Oracle Database using one of the connect strings:
     Pluggable database: mississauga.candomain/FREEPDB1
     Multitenant container database: mississauga.candomain

[oracle@mississauga ~]$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Apr 8 13:57:09 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle.  All rights reserved.
Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL>

Done with the installation. Though there are multiple additions into Oracle 23c database, I would like to start with a quick one, insert multiple rows in a single INSERT command. If you use DBMSs such as MySQL or SQL Server, the syntax for inserting multiple rows into a table with a single statement is quite straightforward. Its now available in Oracle databases! 🙂

[oracle@mississauga ~]$ sqlplus / as sysdba
SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sat Apr 8 13:57:09 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle.  All rights reserved.
Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

SQL> select name, open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
FREE      READ WRITE

SQL> 
SQL> create table albumdetails (album_code number(10), albumrack_number number(10), albumreleaseyear number(20), albumtype varchar2(70));

Table created.

SQL>
SQL> insert into albumdetails (album_code, albumrack_number, albumreleaseyear, albumtype) values
('100','20','1999','Vinyl'),
('101','18','2008','cassattee'),
('102','01','1992','Vinyl'),
('103','05','1988','LPRecord'),
('104','05','2018','Vinyl');  

5 rows created.

Next I will be posting each of the new features and experiments that I will be doing on 23c.

Hope It Helped!
Prashant Dixit

Posted in Uncategorized | Tagged: , , | Leave a Comment »

 
%d bloggers like this: