Wednesday, February 14, 2024

Automatic transaction rollback in 23c

Automatic transaction rollback in 23c with high, medium and low priority transactions


Visit my group in LinkedIn to find more:

https://www.linkedin.com/groups/8151826


Automatic transaction rollback is another very interesting new topic in 23c. 

It provides functionality to control when transactions which are holding row locks can be automatically rolled back by terminating its session.


This feature means no more long transaction level locking or the infamous event ‘
enq: TX row lock contention‘ or the pessimistic locking.


If a transaction does not commit or rollback for a long time while holding row locks, it can potentially block other high-priority transactions. 


This feature allows applications to assign priorities to transactions, and administrators to set timeouts for each priority. 

The database will automatically rollback a lower-priority transaction and release the row locks held if it blocks a higher-priority transaction beyond the set timeout, allowing the higher-priority transaction to proceed.

Automatic Transaction Rollback reduces the administrative burden while also helping to maintain transaction latencies/SLAs on higher-priority transactions.


For example let's assume an application modifies some rows for a long time and Oracle acquires a row lock for each row that is modified e.g. by any kind of DML operations. 

It can block another transaction on a row lock as long as it does not release the locked rows.To release the locked rows, a COMMIT or ROLLBACK must be issued in the session holding the lock. 

Sometimes it needs a database administrator to manually terminate the blocking transaction by killing the session with ALTER SYSTEM KILL or cancel the SQL statement with ALTER SYSTEM CANCEL SQL.

To implement the feature a decision needs to be taken in which case a transaction will be rolled back. Therefore different priorities for transactions are introduced. 

That means it is possible now to define the priority of your transaction. You can decide between low, medium and high (default). The Automatic Transaction Rollback feature will then automatically roll back low-priority transactions that are blocking higher priority transactions from obtaining row locks after a pre-defined wait time. 

The default priority for a transaction is always high and there is no automatic rollback enabled.

To implement this feature you need to set both parameters - one for the transaction priority and one for the wait time. Here is a short definition of the two parameters. 


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.


Both control the maximum time duration, in seconds. 


A transaction with priority HIGH & MEDIUM will wait this defined wait time before the database rolls back a lower priority transaction holding a row lock. 


The default value is the maximum number value.
Note: You need to have the ALTER SYSTEM privilege to configure this parameter. For example use the following  ALTER SYSTEM command to set the wait parameter to 25 seconds. It's modifiable in a PDB.


SQL> alter system set txn_auto_rollback_high_priority_wait_target = 25;


The transaction priority parameter is TXN_PRIORITY and can have the values LOW, MEDIUM, and HIGH. 


It can be defined with an ALTER SESSION command. 

SQL> alter session set txn_priority = low;


Note: All transactions have the default priority HIGH but changeable manually.

******************************

Regards,

Alireza Kamrani.

Senior Database Consultant.

Sunday, February 11, 2024

♨️Oracle standby & Redo Apply mode on RAC♨️

Oracle standby and applying redologs methods 

Mira vs Sira

Basically Oracle has different ways to apply redo on standby site.


SIRA: Single Instance Redo Apply 

 Where MRP runs only on one of the instance on Standby RAC/Single node database.

MIRA: Multi Instance Redo Apply 

 Where MRP runs only on more than one instance on Standby RAC database.


Recommendations related to MIRA from 12.2 Onwards (Exadata and Non Exadata envirnoment) 


Starting with Oracle Database 12.2, Multi-Instance Redo Apply (MIRA) greatly improves scalability of redo apply for
Oracle RAC databases. Instead of merging all threads of redo into a single apply process, multiple apply instances divide the threads of redo between the apply instances. For example, when two apply nodes are used to apply four
threads of redo from the primary, each apply instance will apply two threads.

Important :- In Rac database it is recommended  to use single instance redo apply (SIRA) instead of MIRA when online patching for RAC rolling upgrade is in progress.

 How to Enable MIRA

 From sqlplus

 ALTER DATABASE RECOVER MANAGED STANDBY DATABASE INSTANCES [ALL|integer];


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION INSTANCES ALL -> to start from all the instances


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION INSTANCES 2 -> to start from any two instances 


From Broker :- Data Guard Broker database set property ApplyInstances 

 

Change value for ApplyInstances = number of instances (set value to 2 in this case)


DGMGRL> edit database "ORCL" set property ApplyInstances=2;


Property "applyinstances" updated

DGMGRL> show configuration

 

How to Check if MIRA is running 

 

You can grep the Alert log for Word MIRA


Starting Multi Instance Redo Apply (MIRA)  ----------------> If MIRA is used.


Disable SMART PING feature on EXADATA/SuperCluster box before starting MIRA.

Mira cannot handle the redo generated by SMART PING feature which is enabled by default on Exadata, so we need to disable smart ping as prerequisite on Engineered systems:


“_cache_fusion_pipelined_updates”=false 


Note: This needs to be set on both primary and standby databases. Also this NON RAC rolling parameter requires complete DB bounce.


Convert to SIRA during RAC rolling upgrade/patching.

In RAC database it is recommended  to use single instance redo apply (SIRA) instead of MIRA when online patching for RAC rolling upgrade is in progress.


Recommended Database version.

Most MIRA optimisations are implemented in Oracle Database 19c and are not available in earlier database releases. In fact, Oracle recommends the database release be no earlier than Oracle Database 19.13 because it includes some important MIRA fixes.


Important bug fixes to be considered for MIRA.

34198944; MIRA HANG IN ADG
32012137; REDUCE NUMBER OF LWNHIST RECORDS SENT
33821145; MIRA FAILED TO ADVANCE INFLUX SCN
33940540; MIRA RECEIVER NEEDS TO FREE SENT MESSAGES
34239061; MERGE ON DATABASE RU 19.11.0.0.0 OF 34238063 33940540 ==> Merge of all above 4 patches.
34775309; APPLY PROCESS IS VERY SLOW AFTER APPLYING PATCH 33165338


  • Not recommended for environments with poor IO performance.


Starting from 12c Release 1 (12.1), USING CURRENT LOGFILE is deprecated and no longer required to start real-time apply. 


When the real-time apply feature is enabled, redo data can be directly applied to the standby database without waiting for the current standby redo log file to be archived.


To enable the real-time apply feature on the physical standby database, issue the following SQL statement (Active Data guard option is licensed)


ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;


Starting from 12c Release 1 (12.1), USING CURRENT LOGFILE is deprecated and no longer required to start real-time apply.


MIRA is not recommended to for environments with poor IO throughput. It is recommended to solve/tune suboptimal IO throughput before converting from SIRA to MIRA.


How does it work:

Well, each applied instance on the standby site will divide the threads of redo received from primary among the apply instances to improve the scalability of redo apply.


For example, four redo threads from the primary are divided by two threads for each apply instance on standby.


To cancel the MRP,

ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


To check the status of the MRP,

SELECT STATUS FROM V$MANAGED_STANDBY WHERE PROCESS=’MRP0′;


As a result of the managed recovery process (MRP), the standby database will have its archived redo logs maintained in real-time or near real-time. 


ENABLE_IMC_WITH_MIRA

ENABLE_IMC_WITH_MIRA enables or disables the In-Memory Column Store and Oracle Data Guard Multi-Instance Redo Apply, at the same time, on an Active Data Guard standby database.

Property

Description

Parameter type

Boolean

Default value

false

Modifiable

ALTER SYSTEM

Modifiable in a PDB

No

Range of values

true | false

Basic

No

Oracle RAC

Different instances can use different values.

The value of this parameter is relevant only on the instance where MRP0 is spawned at the start of Redo Apply on a standby database.


Best Regards,

Alireza Kamrani 


Fleet Patching & Provisioning (FPP) Concepts and cloning methods for Oracle/Grid Home

  Fleet Patching & Provisioning (FPP) Concepts and cloning methods for Oracle/Grid Home:                           ♠️Alireza Kamrani♠️  ...