Overview - Advisory locks
What is it?
Advisory locks in PostgreSQL are a way for applications to coordinate access to shared resources by using custom lock identifiers. Unlike regular locks that protect database rows or tables, advisory locks are application-controlled and do not block database operations automatically. They let different parts of an application agree on exclusive or shared access to resources using numbers as keys.
Why it matters
Without advisory locks, applications might face race conditions or conflicts when multiple processes try to use the same resource simultaneously. Advisory locks provide a flexible, lightweight way to prevent such conflicts without locking database data itself. This helps keep the database responsive and avoids deadlocks caused by traditional locking.
Where it fits
Before learning advisory locks, you should understand basic database locking and transactions. After mastering advisory locks, you can explore advanced concurrency control, distributed locking, and application-level synchronization techniques.