简体   繁体   中英

High values of innodb_lock_wait_timeout on Mysql

we're trying to get some statistics over our large log tables on MySQL. Some select queries are taking too long to complete and causing exceptions as;
Caused by: java.sql.SQLException: Lock wait timeout exceeded; 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.

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.

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 ). Which changes the way InnoDB locks records.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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