Oracle 26ai Lock-Free Reservations: The Hot Row Stops Queuing. Your CDC Stops Seeing It.
Every system has a hot row. The stock count of the product on sale, the seat counter of a popular flight, the
balance of the account everything is paid from. Each sale does qty = qty - 1, and each one takes the row lock and
holds it until commit. Under load, the sessions line up behind each other in enq: TX - row lock contention, and
the time a transaction spends between its update and its commit becomes the time everyone else waits.
Oracle 23ai added a fix for exactly this, and 26ai keeps it: lock-free reservations. Mark the column
RESERVABLE, and an update of it no longer locks the row. Oracle records the change as a reservation and applies
it at commit.
I measured it on Oracle AI Database 26ai Free. It works, and the difference under contention is large. It also
comes with rules that surprise anyone who has written UPDATE statements for twenty years, and one that the
documentation doesn’t mention at all: Debezium, reading the redo with LogMiner, doesn’t see the changes.
The setup
Two tables, identical except for one keyword:
create table stock_res (
id number(10) primary key,
name varchar2(20),
qty number(10) reservable constraint stock_res_qty_ck check (qty >= 0));
STOCK_PLAIN is the same table without RESERVABLE. Oracle requires a primary key, and the column has to be
numeric. When you create the table, it also creates a journal table in the same schema, named after the table’s
object number: SYS_RESERVJRNL_73297 in my run. That’s where the reservations live until commit.
Concurrent decrements stop waiting
One session decrements row 1 and stays open for 15 seconds. A second session decrements the same row:
| normal column | RESERVABLE | |
|---|---|---|
| the second decrement | waits 14.8 s, for the first to commit | returns in 41 ms |
| final quantity after both commit | 99,998 | 99,998 |
Then the real test: eight sessions, 100 transactions each, every transaction a qty = qty - 1 on row 1, 20 ms of
other work, and a commit. The 20 ms stands in for whatever an application does between its update and its commit.
| normal column | RESERVABLE | |
|---|---|---|
| per-session elapsed | 4.0 s to 16.3 s | 2.1 s each |
| final quantity | 99,200 | 99,200 |
With the normal column the sessions took turns: 800 transactions times 20 ms is 16 seconds, and the slowest
session waited for nearly all of them. With RESERVABLE every session ran at its own pace. 100 transactions times
20 ms is 2 seconds, so they hardly waited at all. No updates were lost.
The constraint is checked at the UPDATE, against the worst case
This is the part that makes it safe, and the part that changes how errors reach the application. The CHECK
constraint isn’t checked against the row as it is. It’s checked against the row minus every decrement that other
transactions have reserved and not yet committed.
Row 2 has qty = 5. One session reserves -3 and stays open. Then a second session:
update stock_res set qty = qty - 3 where id = 2;
ORA-02290: check constraint (APP.STOCK_RES_QTY_CK) violated
update stock_res set qty = qty - 2 where id = 2;
1 row updated.
5 - 3 - 3 is below zero, so the second -3 fails, at once, at the UPDATE. Nobody waits to find out whether the
first transaction commits. If it rolls back, the stock was there after all, and the second session was told no.
Increments are treated the other way. With another session’s +4 pending, a -7 still fails: a pending
replenishment doesn’t count until it commits. The session’s own +4 does count: +4 then -7 in the same
transaction works. Oracle’s documentation
describes this as allowing a reservation only if there is enough left after the outstanding ones.
In practice this means ORA-02290 becomes a normal business outcome, “not enough stock right now”, that the
application has to handle on the UPDATE, not something that only shows up when the data is broken.
A session can’t read its own decrement
After its own uncommitted -3, the session reads the row:
update stock_res set qty = qty - 3 where id = 2;
select qty from stock_res where id = 2; -- 5
commit;
select qty from stock_res where id = 2; -- 2
Before the commit it still reads 5. The change isn’t in the row yet. It’s a row in the journal table, which
the session can query (ID 2, QTY_OP '-', QTY_RESERVED 3), and other sessions can’t. Any code that updates a
balance and then reads it back to decide what to do next, or to show it, reads the old value. That code needs to
change before the column does.
The rules
- Only
+and-.set qty = 7fails withORA-55746. A reset to a fixed value has to be written as a difference, or done after the column stops being reservable. - One kind of column per statement.
set qty = qty - 1, name = 'x'fails withORA-55735. Split it in two. - Other columns aren’t affected. An update of
NAME, orSELECT ... FOR UPDATE, on a row with a pending reservation didn’t wait (41 ms and 40 ms). DELETEfails instead of waiting. With a reservation pending on the row, aDELETEof that row failed withORA-55754(“Resource busy error is detected for the reservable column update statement”) after 2 to 3 seconds, while the reservation was still open, with or withoutDDL_LOCK_TIMEOUT. The documentation says the delete is retried internally for up to 5 seconds. A purge job that deletes rows other sessions are still decrementing needs to handle that error and try again later.- DDL behaves as usual.
ALTER TABLE ... ADDfailed withORA-00054at once, or afterDDL_LOCK_TIMEOUTwhen it was set: the same as for any table with an open transaction.
It isn’t free, either. In one session with no contention, 2,000 update-and-commit loops wrote 1,854 bytes of redo per transaction on the reservable column against 794 on the normal one, and took several times longer (200 ms against 20 ms for all 2,000, in a PL/SQL loop). The journal row goes in at the update and out at commit. That cost is small next to 14 seconds of waiting, and pointless on a row that nobody else updates.
Debezium doesn’t see the changes
This is the part I didn’t expect. With a Debezium connector (3.7.1, LogMiner adapter, the documented setup and
(ALL) COLUMNS supplemental logging on both tables) capturing STOCK_PLAIN and STOCK_RES:
- The snapshot had both tables.
- A committed decrement on
STOCK_PLAINarrived in Kafka:op=u,QTY 100000 -> 99995. - A committed decrement on
STOCK_RESproduced no event. - An
INSERTof a new row intoSTOCK_RESproduced no event either. - The connector stayed
RUNNING. The only trace was one line per transaction in the Kafka Connect log:
WARN An unsupported operation detected for table 'FREEPDB1.APP.STOCK_RES' in transaction 0600050041020000
with SCN 2263830 on redo thread 1.
LogMiner itself shows why. For the same transaction, V$LOGMNR_CONTENTS has the journal insert and delete as normal
DML, and the change to STOCK_RES as OPERATION = 'UNSUPPORTED', INFO = 'Object or Data type Unsupported',
with or without (ALL) COLUMNS supplemental logging. Debezium skips unsupported operations and logs that warning.
Kafka keeps the snapshot values, and every consumer downstream (the search index, the warehouse, the cache) keeps
the stock count from the day the connector started. Oracle’s chapter on lock-free reservations doesn’t mention
LogMiner, GoldenGate or CDC at all.
Capturing the journal table does deliver something. With APP.SYS_RESERVJRNL_<n> in table.include.list, a
committed -4 arrived as a create and a delete of a journal row: ID 1, QTY_OP "-", QTY_RESERVED 4. A consumer
could apply those deltas. I wouldn’t build on it: the table name contains an object number that changes when the
table is recreated, it’s an internal table, and inserts into the base table are still missing. If a table has to
be captured by LogMiner-based CDC, keep its columns non-reservable, or test your tool first, the way this lab does.
To see which tables have reservable columns:
select owner, table_name, column_name
from dba_tab_cols
where reservable_column = 'YES'
order by owner, table_name;
Compare that list with your connectors’ table.include.list.
When to use it
Use it for the counter that many sessions change at once and nobody else depends on seeing change by change: stock, seats, quotas, balances that are only ever added to and taken from. Before you switch it on:
- Make the application handle
ORA-02290on theUPDATEas “not available right now”. - Remove any read-after-update of the column inside the same transaction.
- Rewrite any
SET col = valueas a difference. - Make purge jobs handle
ORA-55754. - Check whether anything reads the table from the redo: Debezium, GoldenGate, a logical standby. On Debezium, it stopped seeing the table.
Prove it
The lab runs Oracle Database Free 26ai (23.26.3), a single-node Kafka 4.3.1 and Kafka Connect with Debezium 3.7.1.Final:
drill case result
nowait 2nd decrement while the 1st is open 15 s normal: waits 14.8 s; RESERVABLE: 41 ms
hotrow 8 sessions x 100 x (qty - 1, 20 ms, commit) normal: 4-16 s each; RESERVABLE: 2.1 s each;
both end at 99,200
check qty 5, another session's -3 pending -3: ORA-02290 at the UPDATE; -2: works
another's +4 pending / own +4 -7 fails / -7 works
read own -3, then SELECT 5 before commit, 2 after
rules qty = 7 / qty and name together ORA-55746 / ORA-55735
NAME update, SELECT FOR UPDATE no wait
delete DELETE of a row with a pending reservation ORA-55754 after 2-3 s
ALTER TABLE ADD ORA-00054 (DDL_LOCK_TIMEOUT applies)
overhead 2,000 update + commit, one session 1,854 vs 794 bytes of redo per transaction
cdc Debezium on both tables normal: op=u arrives; RESERVABLE: update and
insert never arrive, task RUNNING, WARN in log
the journal table captured the delta arrives as create + delete
Don’t take my word for it — run it. The reservable lab asserts every row: the wait on the normal column and none on the reservable one, the hot-row timings and the final quantity,
ORA-02290at theUPDATEand which pending changes count, the old value after the session’s own decrement,ORA-55746,ORA-55735andORA-55754, the redo per transaction, and that Debezium delivers nothing for the reservable table while the task staysRUNNING. If any of that doesn’t reproduce, the run fails. Proven on every CI push.
What the lab doesn’t cover: RAC, GoldenGate, the XStream adapter, and sagas (the journal’s ORA_SAGA_ID$ column).
What teams get wrong
- Expecting
ORA-02290only from bad data. With reservations, it’s how the database says “not enough left, counting what others have reserved”. It comes from theUPDATE, under normal load. - Reading the balance back after updating it. The session reads the old value until it commits.
- Assuming
DELETEwaits like it always did. It fails withORA-55754after a few seconds. - Switching it on for a table that CDC captures. Debezium on LogMiner skipped every change to it, inserts
included, and the connector stayed
RUNNING. - Making every numeric column reservable. It costs more than twice the redo per transaction, and it only helps where sessions actually collide on the same row.
Frequently asked questions
What is a lock-free reservation in Oracle 23ai and 26ai?
A column declared RESERVABLE can be changed only with SET col = col + n or col - n, and such an update doesn't lock the row. Oracle records the change as a reservation in a journal table (SYS_RESERVJRNL_<object number>) and applies it to the row at commit. In the companion lab on Oracle Database Free 26ai, a second decrement of a row that another open transaction had decremented returned in 41 ms; with a normal column it waited 14.8 seconds.
When is the CHECK constraint on a reservable column enforced?
At the UPDATE, against the committed value minus every decrement other transactions have reserved and not committed. In the companion lab, with qty 5 and another session's -3 pending, a -3 failed at once with ORA-02290 and a -2 worked. Another session's pending increment didn't count; the session's own did.
Why does my session still see the old value after updating a reservable column?
Because the change isn't applied to the row until commit. It's a row in the reservation journal table, which only the session's own transaction can see. In the companion lab a session that reserved -3 on a qty of 5 still read 5, and read 2 after COMMIT.
What does ORA-55754 mean?
A DELETE (or DDL) ran into a row with active lock-free reservations: "Resource busy error is detected for the reservable column update statement." Oracle retries the delete internally for a few seconds and then raises it. In the companion lab it came after 2 to 3 seconds, while the reservation was still open, with or without DDL_LOCK_TIMEOUT.
What do ORA-55746 and ORA-55735 mean?
ORA-55746: a reservable column was assigned a value (SET qty = 7); only + and - are allowed. ORA-55735: one UPDATE changed a reservable and a non-reservable column together; they have to be separate statements.
Does Debezium capture changes to a reservable column?
Not with the LogMiner adapter in the companion lab (Debezium 3.7.1, Oracle Database Free 26ai, (ALL) COLUMNS supplemental logging). LogMiner reports the base-table change as UNSUPPORTED, and Debezium skipped it with the WARN 'An unsupported operation detected for table'. Neither a committed decrement nor an insert of a new row produced an event, and the connector stayed RUNNING. Capturing the journal table delivered each committed reservation as a create and a delete carrying the delta.
Do lock-free reservations add overhead?
Yes. In the companion lab, one session with no contention wrote 1,854 bytes of redo per update-and-commit on a reservable column against 794 on a normal one, and took several times longer for 2,000 of them. It pays off only where sessions actually wait for each other on the same row.
Lock-free reservations do what they promise: the hot row stops being a queue. In return, the UPDATE can fail
with ORA-02290 because of what other sessions reserved, a session can’t read its own change, DELETE fails
instead of waiting, and on this setup Debezium stopped seeing the table, without a single error. Check those four
things before you add the keyword, and prove it with the reservable
lab.
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