Performance Series: 26ai in practice

Oracle 26ai Priority Transactions: The Database Rolls Back the Blocker for You. Read the Fine Print First.

· 11 min read

Every DBA has had this call. Checkout is hanging. You look, and there it is: a session that updated a row twenty minutes ago and never committed. A batch that paused between steps, or a SQL Developer window someone left open before lunch. Everyone who wants that row waits in enq: TX - row lock contention until you find the session and kill it.

Oracle AI Database 26ai can make that call for you. You mark the less important work LOW, tell the database how long important work may wait, and when a HIGH transaction has waited that long, the database rolls the LOW blocker back. Oracle calls it priority transactions.

It works. In the lab, a HIGH session got its row exactly at its 10-second target, every time. But the feature does nothing until you set two things. The session that gets rolled back doesn’t find out until its next statement. Its COMMIT fails. And only one kind of lock wait counts. This post covers how it works, what each side sees, and the fine print, with a lab on Oracle Database Free 26ai that proves each step.

It’s the second post in the 26ai in practice series, and a sequel to ORA-00054 resource busy, which ended with “find the idle session and kill it”. This is the database doing that for you.

Two settings, and you need both

There’s a priority for each session and a wait target for each priority:

SettingValuesDefaultSet with
TXN_PRIORITYHIGH, MEDIUM, LOWHIGHALTER SESSION
PRIORITY_TXNS_HIGH_WAIT_TARGETseconds2147483647ALTER SYSTEM (PDB-level)
PRIORITY_TXNS_MEDIUM_WAIT_TARGETseconds2147483647ALTER SYSTEM (PDB-level)
PRIORITY_TXNS_MODEROLLBACK, TRACKROLLBACKALTER SYSTEM (PDB-level)

The rule: when a transaction has waited for a row lock longer than the target for its own priority, and the session holding the lock has a lower priority, the database rolls the holder’s transaction back.

Two things follow from the defaults. Every session is HIGH, and a HIGH transaction is never rolled back. And the targets are 2147483647 seconds, about 68 years. So out of the box nothing happens, and turning on one half doesn’t change that either. In the lab, a LOW blocker and a HIGH waiter with the targets at their defaults behaved exactly as before 26ai: the waiter waited 22 seconds, until the blocker committed.

To turn it on, set the target in the PDB and mark the work that may lose:

-- as a DBA, in the PDB
ALTER SYSTEM SET priority_txns_high_wait_target = 10;

-- in the batch, report or ad hoc session, before its transaction starts
ALTER SESSION SET txn_priority = LOW;

(On 26ai Free 23.26.3, V$PARAMETER also lists the names these parameters had in 23ai: txn_auto_rollback_mode, txn_auto_rollback_high_priority_wait_target and txn_auto_rollback_medium_priority_wait_target, showing the same values. Use the new names.)

What the waiter sees

With a 10-second target, the HIGH session’s UPDATE waited, and then simply ran. In the lab it got its row after 10 seconds on every run, and its own change committed normally. While it waits, V$SESSION shows a wait event you won’t have seen before 26ai:

enq: TX - row lock (HIGH priority)

BLOCKING_SESSION points at the LOW holder, as with any row-lock wait. When the target is reached, the alert log records who lost and why:

Transaction (sid: 55, serial: 47380, xid: 8.17.586, txn_priority: "LOW") terminated by
transaction (sid: 214, serial: 22289, xid: xid not available, txn_priority: "HIGH") because of
the parameter "priority_txns_high_wait_target = 10".

And V$SYSSTAT counts it: txns rollback priority_txns_high_wait_target went up by one per rollback. That’s the statistic to watch once it’s on.

What the rolled-back session sees

This is the part to design for. The LOW session in the lab updated two rows, 1 and 500, then sat idle for 25 seconds. Nothing told it when it was rolled back at the 10-second mark. It found out on its next statement, 15 seconds later, a plain SELECT ... FROM dual:

ORA-63302: Transaction must roll back
ORA-63300: Transaction is automatically rolled back since it is blocking a
higher priority transaction from another session.

Then every statement after that failed with ORA-63302 alone. Including COMMIT:

SQL> commit;
ORA-63302: Transaction must roll back

Only an explicit ROLLBACK cleared it, and after that the session worked normally. The session isn’t killed; it’s stuck until the application acknowledges the rollback.

Two consequences:

  • The whole transaction is gone, not just the contested row. Row 500, which no one else wanted, was back to its old value. Whatever the batch had done since its last commit has to be redone.
  • The application has to handle two new errors. Catch ORA-63300 and ORA-63302, issue ROLLBACK, and restart the unit of work from its beginning. Code that doesn’t know them will log an error and try again on the same connection, and get ORA-63302 forever. Code that ignores errors on COMMIT will believe the work was saved.

A session that is still running fares the same, sooner. In the active drill the LOW session was inside a PL/SQL block that updated row 1 and then worked (slept) for 30 seconds. At the 10-second target, the running call was interrupted with ORA-63300, and it never reached its second update.

A HIGH session waits for a row held by a LOW session. At the HIGH wait target the database rolls the LOW transaction back and the HIGH session gets the row. The LOW session finds out on its next call: ORA-63300, then ORA-63302 for every statement, COMMIT included, until it issues ROLLBACK.

Who can roll back whom

The lab ran each pair with the HIGH target at 10 seconds and the blocker holding its row for 25:

BlockerWaiterMedium targetResult
HIGHHIGHnot setno rollback, waited 22 s
LOWLOWnot setno rollback, waited 23 s
MEDIUMHIGHnot setrolled back at 10 s
LOWMEDIUMnot setno rollback, waited 23 s
LOWMEDIUM5 srolled back at 5 s

So:

  • Equal priorities never roll each other back. Two HIGH sessions, which is every session by default, wait for each other exactly as they always have. The feature only ever acts on sessions someone marked LOW or MEDIUM.
  • Each waiter uses its own target. A MEDIUM waiter ignores the HIGH target. Set only the HIGH target and MEDIUM sessions behave as before.
  • There’s no LOW target. A LOW waiter never rolls anything back.

Only row-lock waits count

The waiter doesn’t have to be DML. What matters is what it’s waiting for:

HIGH waiterResult against a LOW blocker
UPDATE, SELECT ... FOR UPDATErolled the blocker back at 10 s, then ran
ALTER TABLE ... ADD a columnrolled the blocker back at 10 s, then ran
TRUNCATE TABLEORA-00054 at once
LOCK TABLE ... IN EXCLUSIVE MODEwaited 23 s for the commit, no rollback

The ADD column result is a genuine improvement for releases. In the ORA-00054 post, ALTER TABLE ... ADD waited for an idle transaction for as long as the transaction stayed open, ignoring DDL_LOCK_TIMEOUT. Here it waited for its row-lock wait, hit the target, and the LOW session that held the lock was rolled back. If your ad hoc and reporting sessions run at LOW, a forgotten window can’t hold a deploy hostage.

The other two don’t benefit. TRUNCATE doesn’t wait at all with the default DDL_LOCK_TIMEOUT of 0, so no wait target is ever reached. And LOCK TABLE waits for a table lock, not a row lock; the documentation describes the feature only for transactions “holding rowlocks”, and the lab agrees.

Measure before you roll back: TRACK mode

You can’t easily guess the right target. Too short and batches get rolled back for brief, normal contention; too long and checkout still hangs. PRIORITY_TXNS_MODE = TRACK lets you find out first:

ALTER SYSTEM SET priority_txns_mode = TRACK;
ALTER SYSTEM SET priority_txns_high_wait_target = 10;

-- later
SELECT name, value FROM v$sysstat WHERE name LIKE 'txns track mode%';

In TRACK mode the lab’s LOW blocker wasn’t rolled back (the waiter waited 23 seconds for the commit, as before), and txns track mode priority_txns_high_wait_target went up by one: a rollback that would have happened. Run TRACK through a few business cycles, month-end included, and look at the count before you switch to ROLLBACK.

Where you can’t set the priority

Two limits that decide how you roll it out:

  • Not inside a transaction. ALTER SESSION SET txn_priority after the session has changed a row fails with ORA-63304. Set it at the start of the unit of work, before the first DML.

  • Not in a scheduler job. Inside a DBMS_SCHEDULER job, the same ALTER SESSION failed with:

    ORA-63303: Cannot set the parameter txn_priority inside an Oracle Scheduler job

    So scheduler jobs always run at HIGH. That’s exactly where much nightly batch work runs, and exactly the work you’d most want to mark LOW. To use the feature for batch, the batch has to run from a client session: an external scheduler or a cron job connecting through SQL*Plus, JDBC or Python, setting LOW before it starts.

One more consequence of TXN_PRIORITY being a session setting: it stays set until changed. If an application sets LOW on a pooled connection and returns it to the pool, the next borrower gets a LOW session. Set it explicitly at the start of each unit of work, in both directions.

A safe way to turn it on

  1. Decide who loses. Batch, reports, ad hoc and support sessions are the usual LOW. Leave the application at the default HIGH. Use MEDIUM only if you have three real tiers, and then set both targets.
  2. Make the LOW code ready first. It must catch ORA-63300 and ORA-63302, issue ROLLBACK, and redo the unit of work. Commit in units that are safe to redo.
  3. Start in TRACK mode with the target you have in mind, and watch txns track mode ... for a full cycle.
  4. Switch to ROLLBACK, then watch txns rollback priority_txns_high_wait_target and the alert log’s “terminated by transaction” lines. Every one of those is redone work in a LOW session.
  5. Keep running the blocker queries. Two HIGH sessions still wait on each other for as long as the transaction stays open; the feature doesn’t remove the need to find idle transactions, it only covers the ones you marked.

Prove it

The lab runs Oracle Database Free 26ai in a container. The blocker is a SQL*Plus session that updates two rows of APP.ORDERS and sits idle for 25 seconds; the waiter wants one of them. PRIORITY_TXNS_HIGH_WAIT_TARGET is 10 seconds unless noted:

drill     case                                         result
off       LOW blocker, targets at the default          no rollback; the waiter waits 22 s for the commit
rollback  the same with the 10 s target                waiter gets the row after 10 s (HIGH priority wait event);
                                                       blocker: ORA-63302 + ORA-63300 on its next statement,
                                                       ORA-63302 on COMMIT, whole transaction gone;
                                                       alert log line; V$SYSSTAT counter +1
active    blocker still running PL/SQL                 interrupted with ORA-63300 at 10 s
rules     HIGH/HIGH, LOW/LOW                           no rollback
          MEDIUM blocker, HIGH waiter                  rollback at 10 s
          LOW blocker, MEDIUM waiter                   no rollback; with a 5 s medium target, rollback at 5 s
ddl       ADD column / TRUNCATE / LOCK TABLE           rollback at 10 s / ORA-00054 at once / waits for commit
track     PRIORITY_TXNS_MODE = TRACK                   no rollback; TRACK counter +1
limits    inside a transaction / a scheduler job       ORA-63304 / ORA-63303

Don’t take my word for it — run it. The priority-txns lab asserts every row: no rollback with the default targets; the waiter’s row at the target, within a few seconds, with the (HIGH priority) wait event; ORA-63300 and ORA-63302 on the blocker’s next statement and ORA-63302 on its COMMIT; the blocker’s second row restored; the alert log line and both V$SYSSTAT counters; each priority pair; the three DDL waiters; and both ORA-63304 and ORA-63303. If any of that doesn’t reproduce, the run fails. Proven on every CI push.

What teams get wrong

  • Setting LOW and expecting something to happen. Without a wait target nothing is rolled back. Without a LOW or MEDIUM session, setting the target does nothing either.
  • Treating ORA-63300 like a deadlock. After an ORA-00060 deadlock only the statement is rolled back. After ORA-63300 the whole transaction is gone, and the session refuses everything until ROLLBACK.
  • Ignoring errors on COMMIT. A rolled-back LOW session’s COMMIT fails with ORA-63302. If the code doesn’t check, the batch reports success for work that was discarded.
  • Planning to mark scheduler jobs LOW. They can’t be (ORA-63303).
  • Expecting it to rescue every deploy. It helps DDL that waits on a row lock, like ADD column. TRUNCATE still fails with ORA-00054, and table-lock waits aren’t covered.
  • Choosing the target by feel. Run TRACK mode first.

Frequently asked questions

What are priority transactions in Oracle 26ai?

A feature of Oracle AI Database 26ai that lets the database roll back a lower-priority transaction that holds a row lock a higher-priority transaction is waiting for. Each session has a TXN_PRIORITY of HIGH (the default), MEDIUM or LOW, and PRIORITY_TXNS_HIGH_WAIT_TARGET and PRIORITY_TXNS_MEDIUM_WAIT_TARGET set how many seconds a HIGH or MEDIUM transaction waits before the blocker is rolled back. In the companion lab, with a 10-second target, a HIGH session waiting on a LOW session's row got it after 10 seconds.

What does ORA-63300 mean?

ORA-63300 'Transaction is automatically rolled back since it is blocking a higher priority transaction from another session' means the database rolled back your session's transaction because it held a row lock that a higher-priority transaction had waited for longer than its wait target. The whole transaction is rolled back, not just the contested row. In the companion lab an idle session received it, stacked with ORA-63302, on its next statement; a running PL/SQL call was interrupted with it.

How do I fix ORA-63302 Transaction must roll back?

Issue ROLLBACK. After a priority-transaction rollback, every statement in the session, including COMMIT, fails with ORA-63302 until the application explicitly rolls back to acknowledge it. In the companion lab, a SELECT, an UPDATE and a COMMIT all failed with ORA-63302, and after ROLLBACK the session worked normally. Then redo the unit of work: its changes are gone.

Why are no transactions being rolled back after I set TXN_PRIORITY to LOW?

Because the wait targets default to 2147483647 seconds, so the feature is effectively off until you set PRIORITY_TXNS_HIGH_WAIT_TARGET (and PRIORITY_TXNS_MEDIUM_WAIT_TARGET for MEDIUM waiters) in the PDB. Also check that the waiter really has a higher priority: two HIGH sessions, the default for every session, never roll each other back. And check PRIORITY_TXNS_MODE: in TRACK mode the database only counts.

Can I set TXN_PRIORITY in a DBMS_SCHEDULER job?

No. ALTER SESSION SET txn_priority inside a scheduler job fails with ORA-63303 'Cannot set the parameter txn_priority inside an Oracle Scheduler job', so scheduler jobs run at the default HIGH priority. In the companion lab the job's error stack showed ORA-02097 followed by ORA-63303. Batch that should run at LOW has to run from a client session that sets the priority before its transaction starts.

Do priority transactions work for DDL and table locks?

They work for waits on row locks, whatever statement is waiting. In the companion lab a HIGH ALTER TABLE ... ADD column waiting on a LOW session's row rolled it back at the 10-second target and ran. TRUNCATE still failed at once with ORA-00054, because it doesn't wait, and LOCK TABLE ... IN EXCLUSIVE MODE waited for the commit without rolling anything back, because it waits for a table lock.

What is PRIORITY_TXNS_MODE TRACK?

A mode in which the database doesn't roll anything back but counts each rollback that would have happened, in the V$SYSSTAT statistics 'txns track mode priority_txns_high_wait_target' and 'txns track mode priority_txns_medium_wait_target'. Use it to choose the wait targets before switching to the default mode, ROLLBACK. In the companion lab, in TRACK mode the HIGH waiter waited for the commit and the TRACK counter went up by one.

Priority transactions turn “find the idle session and kill it” into a policy: decide which work may lose, give the important work a wait target, and let the database act at second ten instead of minute twenty. Before you turn it on, make the LOW code handle ORA-63300 and ORA-63302, run TRACK mode first, and remember that scheduler jobs and table locks are outside it. Then prove it with the priority-txns lab, where an idle LOW session loses both of its rows at second ten and can’t even commit until it says it knows.

Have a question or some feedback?

I write here in a personal capacity and enjoy comparing notes with other Oracle folks. Say hello.

Get in touch