Avoiding deadlock by using NOLOCK hint

前端 未结 3 999
野趣味
野趣味 2021-02-06 00:18

Once in a while I get following error in production enviornment which goes away on running the same stored procedure again.

Transaction (Process ID 86) wa

3条回答
  •  星月不相逢
    2021-02-06 00:51

    Occasional deadlocks on an RDBMS that locks like SQL Server/Sybase are expected.

    You can code on the client to retry as recommended my MSDN "Handling Deadlocks". Basically, examine the SQLException and maybe a half second later, try again.

    Otherwise, you should review your code so that all access to tables are in the same order. Or you can use SET DEADLOCK_PRIORITY to control who becomes a victim.

    On MSDN for SQL Server there is "Minimizing Deadlocks" which starts

    Although deadlocks cannot be completely avoided

    This also mentions "Use a Lower Isolation Level" which I don't like (same as many SQL types here on SO) and is your question. Don't do it is the answer... :-)

    • What can happen as a result of using (nolock) on every SELECT in SQL Server?
    • https://dba.stackexchange.com/q/2684/630

    Note: MVCC type RDBMS (Oracle, Postgres) don't have this problem. See http://en.wikipedia.org/wiki/ACID#Locking_vs_multiversioning but MVCC has other issues.

提交回复
热议问题