Lock
Locks a table within a transaction.
Synopsis
LOCK [ TABLE ] name LOCK [ TABLE ] name IN lock_mode lock_mode ::= { [ ROW | ACCESS ] { SHARE | EXCLUSIVE } | SHARE ROW EXCLUSIVE } MODE
Parameters
nameThe name of the table you intend to lock.
lock_modeThere are seven valid lock modes that may be combined from the available keywords. Here they are, in order from least restrictive to most restrictive, along with the commands and modes they block:
ACCESS SHARE MODEThe
ACCESS SHARE MODElock is acquired automatically by aSELECTstatement on the table or tables it retrieves from. This mode blocksALTER TABLE,DROP TABLE, andVACUUMcommands on the table on which it is placed.This mode also blocks concurrent
ACCESS EXCLUSIVE MODElocks from being acquired on the same table.ROW SHARE MODEThe
ROW SHARE MODElock is acquired automatically by aSELECTstatement that has aFOR UPDATEclause. It blocksALTER TABLE,DROP TABLE, andVACUUMcommands on the table on which it is acquired.This mode also blocks concurrent
EXCLUSIVE MODEandACCESS EXCLUSIVE MODElocks from being acquired on the same table.ROW EXCLUSIVE MODEThe
ROW EXCLUSIVE MODElock is acquired automatically by anUPDATE,INSERT, orDELETEcommand. This mode blocksALTER TABLE,DROP TABLE,VACUUM, andCREATE INDEXcommands.This mode also blocks concurrent
SHARE MODE,SHARE ROW EXCLUSIVE MODE,EXCLUSIVE MODE, andACCESS EXCLUSIVE MODElocks from being acquired on the same table.SHARE MODEThe
SHARE MODElock is acquired automatically by ...