LOCK TABLE
Acquires an explicit lock on one or more tables. The command is only valid inside an explicit
transaction and the lock is held until COMMIT or ROLLBACK.
BEGIN;
LOCK TABLE users IN ACCESS SHARE MODE;
LOCK TABLE orders IN ROW EXCLUSIVE MODE;
COMMIT;
Several tables may be listed in one command:
LOCK TABLE users, orders IN SHARE MODE;
Available modes are ACCESS SHARE, ROW SHARE, ROW EXCLUSIVE, SHARE UPDATE EXCLUSIVE,
SHARE, SHARE ROW EXCLUSIVE, EXCLUSIVE, and ACCESS EXCLUSIVE. Without IN ... MODE,
the default is ACCESS EXCLUSIVE.
NOWAIT fails immediately when the lock cannot be acquired and returns SQLSTATE 55P03.