Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 - 'Lock wait timeout exceeded; try restarting transaction' and only process on the database

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()
like image 951
user2694306 Avatar asked Nov 10 '15 14:11

user2694306


People also ask

How do I fix MySQL lock wait timeout exceeded?

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.

What is InnoDB lock wait timeout?

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.

What is Lock_wait_timeout in MySQL?

This variable specifies the timeout in seconds for attempts to acquire metadata locks. The permissible values range from 1 to 31536000 (1 year).


1 Answers

It turns out, a different component was making a connection and missing the commit() statement.

like image 54
user2694306 Avatar answered Sep 24 '22 15:09

user2694306