← All notes

PostgreSQL explicit locking: LOCK TABLE, row locks and advisory locks

Short answer

PostgreSQL takes most locks automatically. When you need more, use SELECT ... FOR UPDATE for row locks, LOCK TABLE for table locks, or advisory locks for app-defined locks. Table locks last until the transaction ends; there is no UNLOCK TABLE. [S1][S2]

Key points

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: 13.3. Explicit Locking, PostgreSQL License; PostgreSQL Global Development Group, PostgreSQL: Documentation: 18: LOCK, PostgreSQL License.

Cite this

Permanent ID: iil:note:xxmrr9wd

iinventedlight. 2026. "PostgreSQL explicit locking: LOCK TABLE, row locks and advisory locks." iinventedlight Library, iil:note:xxmrr9wd, version of 2026-11-04. https://iinventedlight.com/library/notes/postgres-explicit-locking/. License: CC-BY-4.0.

@misc{iil_note_xxmrr9wd,
  author = {{iinventedlight}},
  title = {{PostgreSQL explicit locking: LOCK TABLE, row locks and advisory locks}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-04},
  url = {https://iinventedlight.com/library/notes/postgres-explicit-locking/},
  note = {Permanent ID iil:note:xxmrr9wd. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/postgres-explicit-locking.md.