Closed berendsliedrecht closed 2 months ago
@andrewwhitehead — can you please take a look at this? Looks like an troublesome issue, if real.
Hi @berendsliedrecht, just tested this out and I don't think there's an issue. In this test case the row is being fetched twice for update, but within the same transaction, so there is no conflict. If you open another transaction and try to fetch the same row for update, then it will block until the first transaction is completed (or time out).
Ah ofcourse, that makes complete sense. Glad my test code was incorrect. I just checked it with two different transactions and it does lock correctly, thanks!
We have a setup where postgres is a separate docker instance and we have N agents using this database. Because of this, when updating a row, we must lock the row until it is explicitly released. Looking at the code, this is this main purpose of the
for_update
property. Browsing through the code, it seems like the query is extended withFOR NO KEY UPDATE
to make sure the row stays locked on a DB level until the transaction is committed. However, when testing this it seems like this is not the case. I hope I just made a mistake in my test code..