Postgresql – Insert values into new columns using values from old columns without locking table

postgresql

The premise is simple – a table has a jsonb column; this json value always has three fields, so I decided to split the three fields into three separate columns on the same table.
Since the table is really large (in the ~100m range), I need a way to insert these json values into their own respective columns without locking the table.
Is there a way to achieve this?

Best Answer

You cannot avoid locking. Keep your transactions short and the number of rows locked reasonable by performing the update in batches, e.g. by primary key range. That reduces the danger of deadlocks.