Using Python I am consistently getting an
(1205, 'Lock wait timeout exceeded; try restarting transaction')
error whenever I try to insert into a particular table. However, when I try to insert directly from the MySQL console, it works just fine. Looking into the
SHOW FULL PROCESSLIST
on the database reveals no other active queries. As this is a dev database with no live applications attached I can't envision any problem. However, it is being served on a server which hosts our production databases, so I strongly prefer not to do resets if possible. Any advice on how to debug this?
Note If I view the query being run against the database using SHOW FULL PROCESSLIST, that eventually fails with the above message, and then insert it manually from the MySQL console, it works as expected.
EDIT Here is an example of the query:
INSERT INTO deals (user_ID, store_ID, storeChain_ID, title, dealSaving,
dealDisclaimer, restriction, dealImage, dealURL, submit_ID, userProvider_ID,
createDate, createDateTime, expirationDate, expirationDateTime, ZIP, STATE,
city, businessType, DealType_ID, IP, rating, popular, dealSearchData, tag,
submitName, provider_dealID)
VALUES (NULL,
2651049,
NULL,
'Toronto East Community Arts Program',
'Three-Week Photography Workshop',
NULL,
NULL,
'https://a1.image.net/imgs/8423535b-bd3b-4e1e-afee-ab2869970a4c/700_q60.jpg',
'https://www.exmples.com/deals/1336374',
111,
1,
'2015-11-12',
'2015-11-12 10:01:58.282826',
'2015-11-17 09:59:59',
'2015-11-17 23:59:00',
'M4M 1K7',
'ON',
'Toronto',
NULL,
'1',
'127.0.0.1',
0,
144565,
'Three-Week Photography Workshop',
'Photography Class',
'Partner',
1336374)
Edit An example using the suggestion is as follows:
self.DB['master']['cursor'].execute("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED")
self.DB['master']['con'].commit()
self.DB['master']['cursor'].execute(dealsquery,data)
self.DB['master']['con'].commit()
In summary, if we face a “Lock Wait Timeout Exceeded” error in MySQL, we need to first understand the effects that such an error can have to our infrastructure, then track the offensive transaction and act on it either with shell scripts like track_lockwait.sh, or database management software like ClusterControl.
A lock wait timeout causes InnoDB to roll back the current statement (the statement that was waiting for the lock and encountered the timeout). To have the entire transaction roll back, start the server with --innodb-rollback-on-timeout enabled.
This variable specifies the timeout in seconds for attempts to acquire metadata locks. The permissible values range from 1 to 31536000 (1 year).
It turns out, a different component was making a connection and missing the commit() statement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With