1

I've probably killed (-9) somehow process which locked a row in my table. Now whenever I try to:

SELECT * 
FROM my_table 
WHERE id=6 FOR UPDATE NOWAIT;

I get:

ERROR: could not obtain lock on row in relation "my_table"`.

How can I unlock that row?

1 Answer 1

1

Ok, I figured it out somehow.

  • I made select * from pg_locks;,
  • checked pid similar to that which i killed.
  • Then I made ps aux | grep suspicious_pid,
  • i got something like: postgres: q-back my_project ::1(63686) idle in transaction.
  • then kill suspicious_pid, where suspicious_pid is number of PID of course.
Sign up to request clarification or add additional context in comments.

2 Comments

It's better to use pg_cancel_backend(pid) or pg_terminate_backend(pid). But the real question is: why do you have connections that start transactions but never commit?
@a_horse_with_no_name thanks for tip. I had an async worker which locked the row at the start of working and kept it locked until finish download from server and finally commit. I've killed it while it was working and the transaction survived opened. I have no better idea how to explain that..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.