简体   繁体   English

Mysql上的innodb_lock_wait_timeout值很高

[英]High values of innodb_lock_wait_timeout on Mysql

we're trying to get some statistics over our large log tables on MySQL. 我们试图在MySQL的大型日志表上获得一些统计信息。 Some select queries are taking too long to complete and causing exceptions as; 某些选择查询需要很长时间才能完成并导致异常;
Caused by: java.sql.SQLException: Lock wait timeout exceeded; 引起:java.sql.SQLException:超出锁定等待超时; try restarting transaction 尝试重新启动事务
This is causing our whole application to stop serving with the same error. 这导致我们的整个应用程序停止使用相同的错误。 After some research we decided to change 'innodb_lock_wait_timeout' variable of our MySQL server configuration. 经过一些研究,我们决定更改MySQL服务器配置的'innodb_lock_wait_timeout'变量。

But, What are the drawbacks of this configuration change? 但是,这种配置改变的缺点是什么?

I am not sure this applies to your issue, but your question is something I have dealt with a while ago. 我不确定这适用于您的问题,但您的问题是我刚才处理过的问题。 I found out that on my system the locks were not needed and were related to queries like CREATE TABLE AS SELECT * FROM table_x... which apparently lock all records in table_x even in InooDB. 我发现在我的系统上不需要锁,并且与诸如CREATE TABLE AS SELECT * FROM table_x...类的查询相关CREATE TABLE AS SELECT * FROM table_x...这显然会锁定table_x中的所有记录,即使在InooDB中也是如此。

The solution was to set the global parameter innodb_locks_unsafe_for_binlog to true (in my.cnf add the line innodb_locks_unsafe_for_binlog=1 ). 解决方案是将全局参数innodb_locks_unsafe_for_binlog设置为true(在my.cnf中添加行innodb_locks_unsafe_for_binlog=1 )。 Which changes the way InnoDB locks records. 这改变了InnoDB锁定记录的方式。

Here is some documentation about it. 是一些关于它的文档。 It really saved my application from those unexpected locks. 它确实将我的应用程序保存在那些意外的锁中

As load increases, you'll need an even longer timeout. 随着负载的增加,您需要更长的超时时间。 The drawbacks will be a risk of ever increasing maximum query times for other client queries. 缺点是存在不断增加其他客户端查询的最大查询时间的风险。 You need to look into this, I would suggest using the linux tool mytop to find the long running queries then do an EXPLAIN on them to see how the locks are being used. 你需要调查一下,我建议使用linux工具mytop查找长时间运行的查询,然后对它们执行EXPLAIN以查看锁的使用方式。 Restructure your data and/or query to lock less. 重构您的数据和/或查询以减少锁定。

Finally, MariaDB (a fork of MySQL) has a lot of focus on reducing the amount of locks needed for operations, so moving to that may help you also. 最后,MariaDB(MySQL的一个分支)非常关注减少操作所需的锁定量,因此转向它也可能对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM