JourneyToJsDude
JourneyToJsDude

Reputation: 197

How to concurrently update PostgreSQL 13 table row without locks

I need to update a table with different measures per id and these updates will be run by different transactions.

I need to know if there is a way to unlock the row on the update statement as I do not need to read data at the moment and data consistency would not be a problem.

Thanks in advance.

Upvotes: 0

Views: 3244

Answers (2)

JourneyToJsDude
JourneyToJsDude

Reputation: 197

Finally I have implemented the different transactions (insert, update) inside a procedure and released the locks with COMMIT after each transaction in order to avoid deadlocks, following this comment: https://stackoverflow.com/a/56768529

Upvotes: 0

Laurenz Albe
Laurenz Albe

Reputation: 246013

There is no way for two transactions to update the same row at the same time.

But that is not necessary. Just make sure that your database transactions are as short as possible, then no lock will be held for a long time. You can mode the update of that row towards the end of the transaction to reduce the time the lock is held.

Upvotes: 2

Related Questions