If I SELECT... FOR UPDATE
a row in a transaction, it will obviously block the row from being written to, but will it disallow reads as well? I'd prefer to still be able to read from the row, so if the answer is yes, can you provide a solution to work this?
The session that holds the lock can read the table (but not write it). Multiple sessions can acquire a READ lock for the table at the same time. Other sessions can read the table without explicitly acquiring a READ lock.
PostgreSQL doesn't remember any information about modified rows in memory, so there is no limit on the number of rows locked at one time. However, locking a row might cause a disk write, e.g., SELECT FOR UPDATE modifies selected rows to mark them locked, and so will result in disk writes.
Locks or Exclusive Locks or Write Locks prevent users from modifying a row or an entire table. Rows modified by UPDATE and DELETE are then exclusively locked automatically for the duration of the transaction. This prevents other users from changing the row until the transaction is either committed or rolled back.
According to most accounts Postgres only locks the affected rows of an UPDATE query and does not have lock escalation.
You can read just fine. There are lock modes that prevent reading but this isn't one of them.
http://www.postgresql.org/docs/current/static/explicit-locking.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With