Databases · Senior · Question 12 of 75
What are advisory locks in PostgreSQL?
- 1Locks taken automatically on every SELECT
- 2Locks that the planner recommends but doesn't enforce
- ✓Correct answer: Application-defined locks on arbitrary numbers, useful for things like 'only one instance runs this cron job'
Explanation
pg_try_advisory_lock(key) returns false if someone else holds it. Session-level locks must be released explicitly; with poolers in transaction mode, prefer transaction-level ones.