Skip to content
Advertisement

Is it possible to commit a transaction and start a new one without releasing the row locks?

I have a use case where I need to:

  1. Update a row.
  2. Persist the changes to disk, such that a system crash will not reverse it.
  3. Update the same row that has not been modified by another transaction (a race condition).

How would I achieve this? Is it possible to commit a transaction and start a new one without releasing the row locks?

Advertisement

Answer

Postgres supports Advisory Locks, that can be hold over Session Lifetime.
If all your threads use these locks, you would be safe.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement