Database deadlocks

前端 未结 6 1499
鱼传尺愫
鱼传尺愫 2020-12-14 09:07

One of the classical reasons we have a database deadlock is when two transactions are inserting and updating tables in a different order.

For example, transaction A

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 09:48

    1. All transactions are inserting\updating in the same order.
    2. Deletes; identify records to be deleted outside a transaction and then attempt the deletion in the smallest possible transaction, e.g. looking up by the primary key or similar identified during the lookup stage.
    3. Small transactions generally.
    4. Indexing and other performance tuning to both speed transactions and to promote index lookups over tablescans.
    5. Avoid 'Hot tables', e.g. one table with incrementing counters for other tables primary keys. Any other 'switchboard' type configuration is risky.
    6. Especially if not using Oracle, learn the looking behaviour of the target RDBMS in detail (optimistic / pessimistic, isolation levels, etc.) Ensure you do not allow row locks to escalate to table locks as some RDMSes will.

提交回复
热议问题