debugsqlModerate
Exactly what error is returned by PostgreSQL `FOR UPDATE NOWAIT` when a selected row cannot be locked immediately?
Viewed 0 times
postgresqlcannotreturnederrorupdatewhatlockedforselectedwhen
Problem
The PostgreSQL 9.4 documentation states that adding the
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.
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:
In Postgres 9.4.x I tested this by performing an unresolved
The result was the following PostgreSQL Error Code.
55P03In 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_availableContext
StackExchange Database Administrators Q#111176, answer score: 10
Revisions (0)
No revisions yet.