The PostgreSQL 9.4 documentation states that adding the NOWAIT option to a SELECT FOR UPDATE means an error is generated when a row cannot be locked:

To prevent the operation from waiting for other transactions to commit, use the NOWAIT option. With NOWAIT, the statement reports an error, rather than waiting, if a selected row cannot be locked immediately.

Exactly what error would that be?

As this is an acceptable condition, I want my Java code to check for such an expected error and then work around it.


SQLState: 55P03

In Postgres 9.4.x I tested this by performing an unresolved SELECT FOR UPDATE in pgAdmin and then doing a SELECT FOR UPDATE NOWAIT in my Java app. I used the JDBC driver JDBC41 Postgresql Driver, Version 9.4-1201.

The result was the following PostgreSQL Error Code.

  • Message:
    ERROR: could not obtain lock on row in relation "my_table_"
  • Class:
    Class 55 — Object Not In Prerequisite State
  • SQLState:
  • Condition Name:
  • Tip: You can use psql and just \set VERBOSITY verbose first. – Craig Ringer Aug 16 '15 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.