Row-level lock modes
In older versions, as in PostgreSQL 9.3, there are only two locking modes, which are FOR UPDATE and FOR SHARE. FOR UPDATE is used to acquire an exclusive lock on the row and does not allow other transactions to update or delete it; FOR SHARE is less restrictive, allows other transactions to lock the ROW in FOR SHARE mode, and still does not allow other transactions to delete or update the row. FOR SHARE is used to handle a nonrepeatable read scenario in a READ COMMITTED transaction isolation level. For example, you could lock the row FOR SHARE and this will guarantee that the value will not change until the transaction is committed.
FOR SHARE does not handle the lost update problem, since FOR SHARE allows other transactions ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access