Learner
Learner

Reputation: 287

Database row level locking in JDBI and postgres

I am using jdbi with postgres. And as i am running application in multiple instances locking is not an option on application code level. So i am using row level locking on database. So i am using select for update. But ideally i don't need any update to the row but i am going a head due to for update. So everytime to release a lock i fire an update query to update last updated time field, Can i just lock it and once the transaction is done release the lock without any update. DO we have such an option?

Upvotes: 1

Views: 626

Answers (1)

user330315
user330315

Reputation:

When you commit or rollback your transaction the lock is automatically released, regardless whether you actually updated the row or not.

There is absolutely no need to UPDATE the row in order for the lock to be released.

Upvotes: 1

Related Questions