In a previous article we wrote data to the database
using atomic update statements, and then using transactions with
SELECT ... FOR UPDATE. In this article we will look
at what happens when we continue doing this, in a more
complicated way. Source code for this article is also available on github.com.
A simple row lock
But first let’s do things manually: We create a table
kris with an integer primary key column and a
secondary unindexed data column. We are filling it with some
records with gaps between the primary keys.
We then START TRANSACTION READ WRITE and
SELECT ... FOR UPDATE a record:
Session1> create table kris ( id serial, …[Read more]