0

How would I get a lock on an entire Postgres table, such that no other process can update any row in the table (but can still read rows with SELECT)? I think the lock type I want is EXCLUSIVE, but I am not sure how do acquire such a lock for the entire table using an Ecto query.

Thanks!

apr
  • 154
  • 6

1 Answers1

1

Use LOCK:

LOCK my_table IN EXCLUSIVE MODE;

Note that LOCK TABLE can only be used in transaction blocks.

See also How to use raw sql with ecto Repo

klin
  • 112,967
  • 15
  • 204
  • 232