Hi and Happy New Year :)
I'm using Postgresql and I need a way to enable a worker process to lock a specific row, while that process operates on that row. It is essentially a table of actions which should be executed once and only once. Each process should grab a different row to operate on.
During this 'operation' the worker process will calculate some value and insert into the database in a transaction multiple times (it will alter between calculating and inserting into the database).
I don't know how long each operation will take (it varies) and I need a way to unlock that row, if that process dies/gets killed or the system crashes (so other process can grab that row and finish the operations on it).
As far as I know, Postgresql's row lock last only in one transaction. I was thinking to add some flag, which would indicate if a row is locked or not into the table, but I have trouble figuring out how could I tell if that row is still being operated on, or is it hanging, because the worker process died (in the latter case it should be taken by an other worker process)? (I have a finished flag in that table to signal, that the row is finished/done being processed)