PostgreSQL

Advisory locks enable application-level resource coordination

info
configurationUpdated Jan 21, 2026
Technologies:
How to detect:

Applications need to coordinate access to logical resources (like external API calls or batch jobs) beyond database row-level locking, requiring explicit lock management

Recommended action:

Use pg_advisory_lock() with a hash of the resource name for blocking locks. Use pg_try_advisory_lock() for non-blocking attempts. Always call pg_advisory_unlock() to release locks. Hash resource identifiers with hashtext() for consistent lock IDs