What is difference between write_lock and read_lock in concurency control? How to implement read_lock in PostgreSQL?

StackOverflow https://stackoverflow.com/questions/22799885

سؤال

What is difference between write_lock and read_lock in concurency? What is allowed in write_lock? What is allowed in read_lock? In PostgreSQL, write_lock can be implemented with FOR UPDATE

SELECT salary 
FROM staff 
WHERE worker_id=1 
FOR UPDATE

How to implement read_lock in PostgreSQL?

هل كانت مفيدة؟

المحلول

SELECT salary 
FROM staff 
WHERE worker_id=1 
FOR SHARE;

There are 4 modes possible here. Per documentation:

UPDATE
NO KEY UPDATE
SHARE
KEY SHARE

All the details in the manual.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top