Finding cause of deadlock error from oracle trace file

后端 未结 1 1621
借酒劲吻你
借酒劲吻你 2020-12-13 10:41

I have been getting this \"ora-00060 deadlock detected while waiting for resource\" error often now in my application when multiple users are using the application. I have g

相关标签:
1条回答
  • 2020-12-13 11:26

    First of all, select statement never lock anything in Oracle, just uses last available consistent version of data. It's not a case for select ... for update which locks data like update since Oracle 9i, but there are no for update clause in the query from question.

    Resource Name          process session holds waits  process session holds waits
    TM-000151a2-00000000       210      72    SX   SSX      208      24    SX   SSX
    

    Session #72 holds table-level lock (TM) with "Row Exclusive" type (SX) and want to acquire "Share Row Exclusive" (SSX) lock on same table. This session blocked by Session #24 which already holds table-level lock of a same type (SX) and waits while SSX lock would be available.

    Resource Name          process session holds waits  process session holds waits
    TM-000151a2-00000000       208      24    SX   SSX      210      72    SX   SSX
    

    This (second row) demonstrates exactly same situation, but in opposite direction: Session #24 waits for SSX lock become available, but blocked by Session #72 which already holds SX lock on same table.

    So, Sessions #24 and Session #72 blocks each other: deadlock happens.

    Both lock types (SX and SSX) are table-level locks.
    To understand the situation I recommend to read this article by Franck Pachot.

    Below is citation from this article, which directly relevant to your situation(note that SSX and SRX abbreviations are equivalent):

    Referential integrity also acquires TM locks. For example, the common issue with unindexed foreign keys leads to S locks on child table when you issue a delete, or update on the key, on the parent table. This is because without an index, Oracle has no single lower level resource to lock in order to prevent a concurrent insert that can violate the referential integrity.
    When the foreign key columns are the leading columns in a regular index, then the first index entry with the parent value can be used as a single resource and locked with a row level TX lock.
    And what if referential integrity has an on delete cascade? In addition to the S mode, there is the intention to update rows in the child table, as with Row X (RX) mode. This is where the share row exclusive (SRX) occurs: S+RX=SRX.

    So, most probable variant is that Session #72 and Session #24 deletes some rows in EMPLOYEE table at same time, and there are on delete cascade constraint for EMPSAL_EMP_ID in conjunction with absence of index on EMPLOYEE_SALARY table in which EMPSAL_EMP_ID column listed first.

    0 讨论(0)
提交回复
热议问题