Postgres serializable snapshot isolation for jsonb I'm trying to acquire a serializable lock on a JSONB column, but it looks like by default JSONB supports only row level lock on transactions.

Basically I want to store JSON like:

{a:"v1", b:"v2"}


Here I want to acquire lock on my json, so that when two users edit a/b concurrently for me database shouldn't block transactions. However, if both user edit the same key concurrently, I want to stop them. 

My application needs properties that need to be stored and updated that's the reason I went ahead for JSONB. Not sure are there any way to achieve serializable lock on JSONB.

The keys will be fixed. They can edit more than one key. No one can delete the JSON keys according to my design, only update them.
You can't do this with JSONB.  To get this level of separation, you would have to have a parent and child table, where the child table would be something like: 

(parent_id whatever, key text, value text, primary key (parent_id, key))


If your JSON can be nested and not just a flat key-value store, then it is ambiguous at what level you want the locking to occur.  If it always occurs at the first level, then this would still work but the value column would be of type JSONB.

If the locking occurs deeper, then that would really be a mess.  What if someone wants to change a value 4 levels down, and someone else wants to remove the entire sub-tree from the 2nd level?

EAV is the design which fits your desired concurrency/locking model. Obviously there are other considerations than that, but I wouldn't know what those are.  You could always use a single row, block until the other guy commits, then "manually" re-check that the value you want to update wasn't changed by the other guy.