Reputation: 4510
I am trying to implement locking via the database using the SELECT FOR UPDATE
psql command https://www.postgresql.org/docs/9.1/static/explicit-locking.html
I can't find much documentation around doing this, besides the fact that the command allows for database row based locking
I am wondering what happens if Thread 1 executes SELECT FOR UPDATE
first, then Thread 2 comes shortly after and tries to execute the same command. Does Thread 2 get blocked, until the database transaction in Thread 1 commits or rollsback?
Upvotes: 0
Views: 107
Reputation: 121474
Yes, Thread2 will be waiting until Thread1 is completed.
You can use NOWAIT
or SKIP LOCKS
to prevent the operation from waiting (see SELECT in the documentation).
Upvotes: 1