akhil_
akhil_

Reputation: 233

How to perform SELECT FOR UPDATE with SKIP LOCKED on MySQL with Django

I have a Django project which uses a MySQL v5.5 backend with InnoDB storage.
To avoid race condition updates in DB, I'm using select_for_update to lock the rows. Now if this lock stays for a long time, any queries on the locked rows will timeout.
I want to avoid this with one of the following options:

  1. Skip the rows which are locked, similar to SKIP LOCKED option.
  2. Return immediately if some rows you're querying are locked, similar to NOWAIT option.
  3. Reduce the lock wait timeout period for specific queries.

How do I perform any of these with Django ORM?

Upvotes: 7

Views: 5207

Answers (1)

Intey
Intey

Reputation: 71

from Django docs:

You can also ignore locked rows by using select_for_update(skip_locked=True)

Upvotes: 3

Related Questions