Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do table locks and row locks interact with each other in PostgreSQL?

I understand how table locks interact with other table locks and how row locks interact with other row locks, but I don't fully understand how table locks interact with row locks.

For instance process A updates some row in table T and therefore acquires a ROW EXCLUSIVE lock. Simultaneously, lets say process B acquires a FOR NO KEY UPDATE row lock on another row. Would process A block process B?

Generally speaking, how to table locks interact with row locks?

like image 703
apr Avatar asked Feb 03 '26 10:02

apr


1 Answers

Table locks don't interact with row locks at all.

Table locks are taken before the operation starts to prevent conflicting activity on a table-wide level (for example, dropping a table which somebody else is using).

Row locks are taken as the rows are processed. They prevent for example concurrent updates on the same row, while it is perfectly fine for concurrent transactions to update different rows in the same table at the same time.

like image 84
Laurenz Albe Avatar answered Feb 05 '26 06:02

Laurenz Albe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!