top of page

ORA-00060 Deadlock Detected: Reading the Deadlock Graph and Fixing the Cause for an Azure Application on OCI Base Database Service

OmerNarman
4 hours ago
8 min read

ORA-00060 is one of the few errors where Oracle tells you exactly what happened and also that it is not its fault. Two sessions each hold a lock the other one needs, neither can continue, and after a few seconds the database rolls back one statement of one session and raises the error there. The other session carries on. The database has done its part; the cause is in the order in which the application takes its locks, or in a missing index that makes the database take more locks than necessary.


This post works through deadlocks reported by an application in Microsoft Azure that uses a database on OCI Base Database Service over Oracle Interconnect for Microsoft Azure. It finds the trace files, reads the deadlock graph, distinguishes the two most common types, and fixes each one where it belongs.



The Use Case

The order service runs in Azure Kubernetes Service and connects to the database in OCI through the interconnect. Since a release that added a new order-cancellation feature, the service logs ORA-00060 several times an hour, and the nightly cleanup job has also failed twice with the same error. Users see an occasional "please try again" message. Nothing in the database configuration has changed.


Environment used in this runbook


  • Service: OCI Base Database Service, VM DB system, single instance

  • Region: OCI Germany Central (Frankfurt)

  • Connectivity: Oracle Interconnect for Microsoft Azure to the application's Azure region

  • Database: Oracle Database 19c (19.24), PDB ORDERPDB

  • Edition: Enterprise Edition High Performance, which includes the Diagnostics Pack used for ASH in Step 5

  • Application: order service in Azure Kubernetes Service, connecting as ORDER_SVC



What a Deadlock Graph Tells You

  • Who waits for whom. The graph lists each locked resource, the session that holds it and the session that waits for it, with the lock modes.

  • TX resources mean rows. A TX enqueue is a transaction lock on rows. Two sessions holding X and waiting for X on TX resources usually updated the same rows in a different order.

  • TM resources mean tables. A TM enqueue is a table lock. Sessions holding SX and waiting for SSX or S on TM resources usually point to a foreign key without an index on the child table.

  • The SQL is in the trace. The trace file of the session that received the error shows the statements each session was running.



Step 1: Find the Deadlocks in the Alert Log

Every ORA-00060 writes a line to the alert log, with the name of the trace file that holds the details. V$DIAG_ALERT_EXT lets you count them per hour with SQL.


SQL

-- Connected to CDB$ROOT as SYSDBA

COLUMN hour FORMAT A13

SELECT TO_CHAR(originating_timestamp, 'YYYY-MM-DD HH24') AS hour,

COUNT(*) AS deadlocks

FROM v$diag_alert_ext

WHERE message_text LIKE 'ORA-00060%'

AND originating_timestamp > SYSTIMESTAMP - INTERVAL '8' HOUR

GROUP BY TO_CHAR(originating_timestamp, 'YYYY-MM-DD HH24')

ORDER BY hour;

Expected output

HOUR           DEADLOCKS
------------- ----------
2026-11-30 08          3
2026-11-30 09          7
2026-11-30 10          9
2026-11-30 11          6
2026-11-30 12          8
2026-11-30 13          5

What to expect: Between three and nine deadlocks an hour during business hours, all since the release. Each one is a failed user action that the application had to retry. The number tracks the order volume, which already suggests a normal application code path rather than a rare accident.



Step 2: Locate the Trace Files

The alert log message names the trace file of the session that was rolled back. List the most recent ones from the shell.


Shell

# On the DB system, as the oracle user

cd /u01/app/oracle/diag/rdbms/orders_fra/ORDERS/trace

grep -l "ORA-00060" ORDERS_ora_*.trc | xargs ls -t | head -3

Expected output

ORDERS_ora_48211.trc
ORDERS_ora_47960.trc
ORDERS_ora_47512.trc

What to expect: One trace file per deadlock, written by the server process of the session that received the error. Look at several, not just one: if they all show the same graph, there is one cause; if they differ, there are several.


Tip: Copy a few trace files to a safe place before reading them. Trace files are purged automatically after the ADR retention period, and a deadlock that stops after a fix leaves no new ones to compare with.


Step 3: Read the Deadlock Graph

The deadlock graph is the first thing to read in the trace file. It shows the locked resources, the holders, the waiters and the lock modes.


Shell

grep -A 4 "Deadlock graph" ORDERS_ora_48211.trc

Expected output

Deadlock graph:
                                          ------------Blocker(s)-----------  ------------Waiter(s)------------
Resource Name                             process session holds waits serial  process session holds waits serial
TX-00090013-0000A3C2-00000000-00000000         45     387     X        48211       52     412           X  31877
TX-000A0012-0000B114-00000000-00000000         52     412     X        31877       45     387           X  48211

What to expect: Two TX resources. Session 387 holds the first transaction lock in mode X and session 412 waits for it in mode X, while session 412 holds the second one and session 387 waits for that. This is the classic row-level deadlock: both sessions locked rows that the other one also needs, in opposite order.



Step 4: Identify the Rows and the Statements

Further down, the trace shows which rows each session waited for and the SQL it was running. The object number in the row information is hexadecimal.


Shell

grep -A 4 "Rows waited on" ORDERS_ora_48211.trc

grep -A 1 "current SQL" ORDERS_ora_48211.trc

Expected output

Rows waited on:
  Session 387: obj - rowid = 0001A2F3 - AAAaLzAAMAAAJ8kAAB
  (dictionary objn - 107251, file - 12, block - 40740, slot - 1)
  Session 412: obj - rowid = 0001A2F3 - AAAaLzAAMAAAJ8kAAC
  (dictionary objn - 107251, file - 12, block - 40740, slot - 2)
  current SQL:
  update order_lines set status = :1 where order_id = :2 and line_no = :3
--
  current SQL:
  update order_lines set status = :1 where order_id = :2 and line_no = :3

What to expect: Both sessions waited for rows in the same block of object 107251, in neighbouring slots, and both ran the same UPDATE on ORDER_LINES. Two sessions updating lines of the same order, each starting from a different end, is exactly how such a deadlock comes about. Confirm the object name in the PDB with SELECT owner, object_name FROM dba_objects WHERE object_id = 107251.



Step 5: Find the Code Paths with ASH

The SQL is the same for both sessions, so the statement alone does not tell you which parts of the application collided. Active Session History shows the module and action of each session at the time of the deadlock.


SQL

-- Connected to ORDERPDB as a DBA

COLUMN module FORMAT A22

COLUMN action FORMAT A16

COLUMN event FORMAT A30

SELECT session_id AS sid, module, action, event, COUNT(*) AS samples

FROM v$active_session_history

WHERE session_id IN (387, 412)

AND sample_time BETWEEN TIMESTAMP '2026-11-30 13:41:00'

AND TIMESTAMP '2026-11-30 13:42:00'

GROUP BY session_id, module, action, event

ORDER BY sid;

Expected output

       SID MODULE                 ACTION           EVENT                             SAMPLES
---------- ---------------------- ---------------- ------------------------------ ----------
       387 OrderCancelService     cancelOrder      enq: TX - row lock contention           3
       412 ShipmentUpdater        markLinesPicked  enq: TX - row lock contention           3

What to expect: The new cancellation feature collided with the warehouse update. The developers confirm that cancelOrder processes the order lines from the last to the first, while markLinesPicked goes from the first to the last. When both work on the same order at the same moment, each locks its first line and then waits for the line the other one already holds.



Step 6: Fix the Lock Order in the Application

The fix is a consistent order. If every code path that changes several lines of an order locks them in the same sequence, two sessions can still wait for each other, but never in a circle.


SQL

-- Pattern for both code paths: lock all lines of the order in a fixed order first

SELECT line_no

FROM order_lines

WHERE order_id = :order_id

ORDER BY line_no

FOR UPDATE;

-- Then update the lines in any order within the same transaction

UPDATE order_lines

SET status = :new_status

WHERE order_id = :order_id

AND line_no = :line_no;


What this does: The SELECT ... FOR UPDATE with ORDER BY line_no takes all row locks of the order in ascending order before any update starts. The second session simply waits for the first one to commit and then proceeds. Both teams apply the same pattern, so the order of the later updates no longer matters.



Step 7: Recognise the Second Type in the Cleanup Job

The trace files of the nightly cleanup job show a different graph. Check them separately, because a second cause needs a second fix.


Shell

grep -A 4 "Deadlock graph" ORDERS_ora_31207.trc

Expected output

Deadlock graph:
                                          ------------Blocker(s)-----------  ------------Waiter(s)------------
Resource Name                             process session holds waits serial  process session holds waits serial
TM-0001A2F3-00000000-00000000-00000000         38     214    SX        22918       61     508    SX   SSX   9041
TM-0001A2F3-00000000-00000000-00000000         61     508    SX         9041       38     214    SX   SSX  22918

What to expect: TM resources on the same object 107251, ORDER_LINES, with both sessions holding SX and waiting for SSX. That pattern is the signature of a foreign key without an index on the child table: deleting a parent row, here an archived order, needs a stronger table lock on ORDER_LINES while other sessions hold row locks on it.



Step 8: Find the Unindexed Foreign Keys

List the foreign keys of the schema whose leading column has no index on the child table.


SQL

COLUMN table_name FORMAT A14

COLUMN constraint_name FORMAT A20

COLUMN column_name FORMAT A12

SELECT c.table_name, c.constraint_name, cc.column_name

FROM dba_constraints c

JOIN dba_cons_columns cc

ON cc.owner = c.owner AND cc.constraint_name = c.constraint_name

WHERE c.owner = 'SALES'

AND c.constraint_type = 'R'

AND cc.position = 1

AND NOT EXISTS (SELECT 1

FROM dba_ind_columns ic

WHERE ic.table_owner = c.owner

AND ic.table_name = c.table_name

AND ic.column_name = cc.column_name

AND ic.column_position = 1)

ORDER BY c.table_name;

Expected output

TABLE_NAME     CONSTRAINT_NAME      COLUMN_NAME
-------------- -------------------- ------------
ORDER_LINES    FK_LINES_ORDER       ORDER_ID

What to expect: One foreign key, from ORDER_LINES to ORDERS on ORDER_ID, has no index starting with that column. The existing primary key of ORDER_LINES starts with LINE_ID, so it does not help. This query checks single-column keys; for multi-column foreign keys, compare all columns of the key with the leading columns of each index.



Step 9: Add the Index Online and Confirm the Result

Create the missing index without blocking the application, then watch the deadlock count over the next days.


SQL

CREATE INDEX sales.order_lines_order_ix

ON sales.order_lines (order_id)

ONLINE;

-- A few days later, connected to CDB$ROOT

COLUMN day FORMAT A10

SELECT TO_CHAR(originating_timestamp, 'YYYY-MM-DD') AS day,

COUNT(*) AS deadlocks

FROM v$diag_alert_ext

WHERE message_text LIKE 'ORA-00060%'

AND originating_timestamp > SYSTIMESTAMP - INTERVAL '7' DAY

GROUP BY TO_CHAR(originating_timestamp, 'YYYY-MM-DD')

ORDER BY day;

Expected output

Index created.

DAY         DEADLOCKS
---------- ----------
2026-11-29         51
2026-11-30         49
2026-12-01          3

What to expect: About 50 deadlocks a day before the fixes and three on 1 December, the day both went live, all from pods that still ran the old release in the morning. The days since then do not appear at all, because the alert log has had no ORA-00060 since. The new index also makes deletes on ORDERS and joins on ORDER_ID faster, so it has a benefit beyond the locking.


Tip: Ask the developers to log ORA-00060 with the module name and retry the transaction once. A deadlock rolls back only the statement that hit it, not the whole transaction, so the application must roll back itself before it tries again.


Summary

ORA-00060 means two sessions waited for each other in a circle, and the database broke the circle by rolling back one statement. Count the errors in V$DIAG_ALERT_EXT, find the trace files, and read the deadlock graph. TX resources held and waited for in mode X point to rows locked in a different order; fix them by locking rows in a consistent order in every code path, using ASH to find which modules collided. TM resources with SX held and SSX waited for point to an unindexed foreign key; find it with a dictionary query and add the index online. Then confirm with the alert log that the deadlocks are gone.

Recent Posts

See All

Comments


bottom of page