Table locking modes

Table locks are often acquired automatically, but they can also be acquired explicitly with the LOCK command. The following is the list of locking modes:

  • ACCESS SHARE: This mode is acquired by the SELECT statement.
  • ROW SHARE: The SELECT FOR UPDATE and SELECT FOR SHARE commands acquire this lock.
  • ROW EXCLUSIVE: The statements UPDATE, DELETE, and INSERT acquire this lock mode.
  • SHARE UPDATE EXCLUSIVE: This mode is used to protect a table against concurrent schema changes. Acquired by VACUUM (without FULL), ANALYZE, CREATE INDEX CONCURRENTLY, CREATE STATISTICS, ALTER TABLE VALIDATE, and other ALTER TABLE variants.
  • SHARE: This mode is used to protect a table against concurrent data changes. Acquired by CREATE INDEX (without ...

Get Learning PostgreSQL 11 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.