Question

I am having an issue where I can't remove records. I keep running into dead lock timeout issue.

I am running a simple query

delete from phone_calls where status =0

after a while I get this error Lock wait timeout exceeded; try restarting transaction

What can I do to solve this? is there some wrong with my query?

note if I add a limit 1000 it works but without limits it runs into a dead lock.

Was it helpful?

Solution

First of all, this is not a dead lock. It's a simple lock wait timeout. The error given on dead lock is something like "Deadlock found when trying to get lock".

Second, some other transaction is still running and holding the lock on one or several of the rows in phone_calls with status = 0. If status isn't a index you're effectivly holding a table lock and two querires can't do this a the same time. It probably takes a while to delete all such rows and your job is running too often.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top