Advisory Locks for Application Coordination
Learn how PostgreSQL advisory locks give your application a lightweight, programmer-controlled mutex for coordinating jobs and protecting critical sections without locking table rows.
What Are Advisory Locks?
Advisory locks are locks whose meaning is defined entirely by your application. PostgreSQL does not associate them with any row or table — your code decides what a given lock key represents.
Why Use Them?
They are perfect for coordination that does not map to a single row:
- Ensuring only one worker runs a nightly job
- Serializing access to an external API
- Preventing two processes from importing the same file
All lessons in this course
- Understanding Locks and Deadlocks
- Identifying and Resolving Lock Contention
- Row-Level Locking Strategies
- Advisory Locks for Application Coordination