尝试获取锁时发现哪个查询导致死锁;尝试重新启动事务
我无法弄清楚哪个查询导致尝试获取锁定时发现死锁;尝试重新启动事务。 我的 mysql 包装器具有以下几行
if (mysql_errno($this->conn) == 1213) {
$this->bug_log(0,"Deadlock. SQL:".$this->sql);
}
,其中 bug_log
写入文件。
bug日志文件没有死锁错误,但/var/log/mysqld.log
有多个记录:
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
我如何追踪它?
I cannot figure out which Query is causing Deadlock found when trying to get lock; try restarting transaction
.
My wrapper for mysql has the following lines
if (mysql_errno($this->conn) == 1213) {
$this->bug_log(0,"Deadlock. SQL:".$this->sql);
}
where bug_log
writes to a file.
The bug log file has no Deadlock errors, but /var/log/mysqld.log
has multiple records:
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Deadlock found when trying to get lock; try restarting transaction
111016 3:00:02 [ERROR] /usr/libexec/mysqld: Sort aborted
How can i track it down?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果另一个事务等待当前事务完成,则使用 WHERE 子句而不是通过唯一列进行更新将导致死锁。下面是一个快速测试:
会话 1
会话 2
(会话 2 现已被阻止)
会话 1
在会话 2 中,我们收到错误
如果在更新的 WHERE 子句中我们仅使用 pk 列,则不会发生错误。
An update with WHERE clause which is not by unique column will cause deadlock if another transaction waits for the current transaction to complete. Here's a quick test:
Session 1
Session 2
(Session 2 is now blocked)
Session 1
In session 2 we receive an error
If in the WHERE clause of the update we use the pk column only, the error does not occur.
我发现这种情况发生在以下一种或多种情况下:
可能很难追踪,但情况基本上是说一个查询正在阻止另一个查询运行,这反过来又阻止第一个查询完成等...
http://en.wikipedia.org/wiki/Deadlock
I've seen this occur on one or more of the following conditions:
It can be difficult to track down but the situation is basically saying one query is preventing another from running which in turn prevents the first from finishing etc...
http://en.wikipedia.org/wiki/Deadlock