HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlModerate

Exactly what error is returned by PostgreSQL `FOR UPDATE NOWAIT` when a selected row cannot be locked immediately?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlcannotreturnederrorupdatewhatlockedforselectedwhen

Problem

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.

Solution

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:


55P03

  • Condition Name:


lock_not_available

Context

StackExchange Database Administrators Q#111176, answer score: 10

Revisions (0)

No revisions yet.