When operating with a relational database like MySQL or PostgreSQL it is sometimes required to use table locks, usually when performing a transaction susceptible to concurrency problems.
As a rule of thumb:
- a WRITE LOCK on a table is needed when writing to that table while performing a transaction susceptible to concurrency issues,
- a READ LOCK on a table is needed when reading from that table while performing a transaction susceptible to concurrency issues,
- when a lock is acquired, all the tables used in the transaction must be locked,
- all locks must be released when a database transaction is completed ...