0

When I use select_for_update on a particular key, the call never returns.

A regular select works:

MyModel.objects.get(pk=pk_1) # Works

But select_for_update doesn't:

with transaction.atomic():
    MyModel.objects.select_for_update().get(pk=pk_1) # Blocks forever

If I change pk_1 to another key, it works. I am not sure why the row would be locked. There are no other connections to the database (to be certain of this I have reset all machines with database access, but the call still blocks for this particular key).

What could be the cause of this?

Flash
  • 15,945
  • 13
  • 70
  • 98
  • Did show processlist in database? Maybe this row is locked by another connection – Xiao Mar 27 '17 at 11:21
  • @Guinner `select * from pg_stat_activity;` doesn't show any other connections. – Flash Mar 27 '17 at 12:04
  • Does `pg_stat_activity` say your session is waiting on a lock? What's in `pg_locks`? Anything in `pg_prepared_xacts`? – Nick Barnes Mar 27 '17 at 12:37
  • @Flash How's it going? – Xiao Mar 30 '17 at 11:47
  • @Guinner I revisited this problem after a few days and the lock appears to be released, so not sure what to do with this question (I am not sure what caused the problem, or if it will happen again). – Flash Mar 31 '17 at 13:38

0 Answers0