Row lock conflicts

There is one tricky part left here. At the point the preceding transaction stopped, the first session has an open transaction trying to update the row WHERE s=1. What happens if we try to do something similar in the second session before that's either been committed or rolled back? Let's try the following:

$ psql -c "UPDATE t SET i=i+1 WHERE s=1;" 

Guess what? This statement will hang! The reason is that we've reached the limit of how many sessions can be isolated from one another safely. Once two sessions are both trying to update the same row, some more complicated rules come into play.

Whenever you try to grab a lock on a specific row, which includes UPDATE, DELETE, and the locks SELECT FOR UPDATE or SELECT FOR DELETE ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.