Priority Transactions in Oracle Database 26ai
The Oracle database supports automatic rollback of transactions and provides parameters to control this behavior.
A row lock restricts access to a single row within a table. Transactions acquire a row lock whenever they execute statements such as `INSERT`, `UPDATE`, `DELETE`, `MERGE`, or `SELECT … FOR UPDATE`. This lock remains in place until the transaction is either committed or rolled back. In certain situations, transactions can hold row locks for an extended period. For example, an application may modify rows but fail to commit or terminate the transaction due to an exception. Traditionally, if a transaction was blocked for a long time by another transaction holding a row lock, the database administrator needed to manually terminate the blocking session using the `ALTER SYSTEM KILL SESSION` command.
Starting with Oracle Database 26ai, administrators can configure parameters to determine which transactions holding row locks can be rolled back automatically and when. The database rolls back the transaction, but the session remains active. The application must issue a `ROLLBACK` statement to acknowledge the automatic rollback.
Applications can also assign a priority to their transactions. If a low-priority transaction blocks a high-priority transaction, Oracle will automatically roll back the low-priority transaction to allow the higher-priority transaction to proceed.
Administrators can set the amount of time a low-priority transaction can hold a lock before it is automatically rolled back.
Priority Transactions introduce a smarter way to handle locking:
- Assign priorities to transactions
- Protect critical operations
- Automatically rollback less important transactions if needed
This shifts Oracle from a “first-come, first-served” model to a “business-priority-driven” model.
A low-value transaction can block a high-value one.
Using Priority Transactions
Oracle Database provides session settings to control the transaction priority.
Transaction 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.
For example, to set the priority of all transactions in the current session to high, use the following command:
ALTER SESSION SET "txn_priority" = "HIGH";
txn_priority are LOW, MEDIUM, and HIGH. All the transactions get a default priority of HIGH, that is, no transaction will be rolled back by default. If this parameter is modified after the transaction has started, then current transaction’s priority will not be changed dynamically. The next transaction created in the session will use the updated priority.If a HIGH priority transaction is blocked for a row lock, Oracle database can roll back the transaction that is holding the row lock only if the holder is LOW or MEDIUM priority.
If a MEDIUM priority transaction is blocked for a row lock, Oracle database can roll back the transaction that is holding the row lock only if the holder is LOW priority.
If a LOW priority transaction is blocked for a row lock, Oracle database will not attempt to roll back the transaction holding the row lock irrespective of its priority.
Oracle database never rolls back a HIGH priority transaction.
Wait Threshold (Key Parameter)
ALTER SYSTEM SET priority_txns_high_wait_target = 15;
- A HIGH priority transaction waits up to 15 seconds
- If still blocked → Oracle automatically rolls back the blocking transaction
Setting Priority Transaction Mode
Priority Transaction supports two modes so that you can try out this feature before enabling it.
The default mode for priority transactions is ROLLBACK. In this mode, if PRIORITY_TXNS_HIGH_WAIT_TARGET and PRIORITY_TXNS_MEDIUM_WAIT_TARGET are appropriately configured, transactions that are holding row locks and blocking higher priority transactions would be automatically rolled back and allow higher priority waiting transactions to progress.
The purpose of TRACK mode is for database administrators to try out the priority transactions feature. In TRACK mode, the database will increment statistics in V$SYSSTAT reflecting how many transactions this feature would have rolled back, instead of actually rolling back any transactions. Applications can use this mode to tune the right wait target value before switching to ROLLBACK mode.
To set priority transaction mode to TRACK, use the following command:
ALTER SYSTEM SET "priority_txns_mode"="TRACK";
To set priority transaction mode to ROLLBACK, use the following command:
Monitoring Priority Transactions
Fixed views provide the information to assist in monitoring transaction priority and wait targets.
Two columns are available in V$TRANSACTION to aid in monitoring transactions. TXN_PRIORITY shows the transaction priority and PRIORITY_TXNS_WAIT_TARGET shows the wait target for the transaction specified in seconds.
Alerts are shown in the alert log whenever a transaction is terminated. For example:
Transaction (sid: 203, serial: 39661, xid: 7.23.1161, txn_priority: "LOW")
terminated by transaction (sid: 204, serial: 9266, xid: 13.15.3, txn_priority:
"HIGH") because of the parameter "priority_txns_high_wait_target = 10"
TXN_PRIORITY cannot be set for a scheduler job. If it is set for a scheduler job, error ORA-63303 is thrown and reported in the alert log.
- Statistics Incremented in ROLLBACK Mode
Specific statistics are incremented for Priority Transactions when in ROLLBACK mode.
The following statistics are incremented only inROLLBACKmode. These statistics are incremented each time a transaction is rolled back because of a higher priority waiter transaction.SQL> select name from V$SYSSTAT where name like '%txns rollback%'; NAME --------------------------------------------------------------- txns rollback priority_txns_high_wait_target txns rollback priority_txns_medium_wait_targetFor example, if a MEDIUM or LOW priority transaction is rolled back because of a HIGH priority transaction, then
txns rollback priority_txns_high_wait_targetwill be incremented. - Statistics Incremented in TRACK Mode
Specific statistics are incremented for Priority Transactions when in TRACK mode.The following statistics are incremented only inTRACKmode. These statistics are incremented each time a transaction would have rolled back because of a higher priority waiter transaction.SQL> select name from V$SYSSTAT where name like '%txns track mode%'; NAME ---------------------------------------------------------------- txns track mode priority_txns_high_wait_target txns track mode priority_txns_medium_wait_targetFor example, if a MEDIUM or LOW priority transaction would have rolled back because of a HIGH priority transaction, then
txns track mode priority_txns_high_wait_targetwill be incremented.
Below example demonstrate how a HIGH-priority transaction can preempt a LOW-priority transaction that blocks a row.
Step 0: Setup – Create a Test Table
-- Create a simple table
CREATE TABLE orders (
order_id NUMBER PRIMARY KEY,
status VARCHAR2(20)
);
-- Insert some test data
INSERT INTO orders VALUES (1, 'PENDING');
INSERT INTO orders VALUES (2, 'PENDING');
COMMIT;
Step 1: Session 1 – LOW Priority Transaction (Blocking)
- Open a new SQL session/window.
- Set the transaction priority to LOW:
ALTER SESSION SET txn_priority = LOW;
- Begin transaction and lock a row:
-- Lock order_id = 1
UPDATE orders SET status = 'PROCESSING' WHERE order_id = 1;
-- Do not commit yet
At this point, order_id = 1 is locked by this LOW-priority transaction.
Step 2: Session 2 – HIGH Priority Transaction (Waiting)
- Open a second SQL session/window.
- Set transaction priority to HIGH:
ALTER SESSION SET txn_priority = HIGH;
- Begin transaction and try to update the same row:
UPDATE orders SET status = 'COMPLETED' WHERE order_id = 1;
- By default, this HIGH transaction waits because the row is locked by LOW.
- Oracle waits up to the configured wait target (
priority_txns_high_wait_target) seconds.
Step 3: System Behavior – Automatic Rollback
- Configure wait target (if not set):
ALTER SYSTEM SET priority_txns_high_wait_target = 10; -- 10 seconds
ALTER SYSTEM SET priority_txns_mode = ROLLBACK;
- If the HIGH transaction waits longer than 10 seconds:
- Oracle automatically rolls back the LOW-priority transaction
- The HIGH-priority transaction proceeds
Step 4: Session 1 Reaction
After the automatic rollback:
ORA–63300: low–priority transaction was rolled back to allow a high–priority transaction to proceed
- LOW transaction is terminated
- HIGH transaction succeeds
Step 5: Verify Results
-- Check status
SELECT * FROM orders;
— You should see:
— order_id = 1 → ‘COMPLETED’
— order_id = 2 → ‘PENDING’
Step 6: Optional – TRACK Mode Demo
- Change to TRACK mode first (simulation):
ALTER SYSTEM SET priority_txns_mode = TRACK;
- Repeat Steps 1–2:
- No rollback occurs
- LOW transaction still blocks HIGH
- Use this to observe which transactions would be rolled back in production without affecting live data
As a result :
- HIGH-priority transaction never waits indefinitely
- LOW-priority transaction can be rolled back automatically
- TRACK mode lets you simulate before enforcing rollback
- Useful for real-time payments, checkout systems, or critical microservices










