Appearance
PG_ADVISORY_LOCK
Obtain an exclusive session-level advisory lock. If another session already holds a lock on the same resource key, this function will wait until the resource becomes available. The lock is exclusive.
Advisory locks are session-level locks on application-defined resources, identified by a single BIGINT
key value. The system does not enforce the use of advisory locks; the application must handle them correctly. Once acquired, an advisory lock is held until it is explicitly released or the session ends. A lock can be acquired multiple times by its owning process; for each completed lock request there must be a corresponding unlock request before the lock is actually released. If a session already holds a given advisory lock, additional requests by it will always succeed, even if other sessions are waiting for the lock.
PG_ADVISORY_LOCK(key)
where key
is a BIGINT
value.
For example:
premdb=# select pg_advisory_lock(32451239);
pg_advisory_lock
------------------
(1 row)
This function returns a VOID
data type.
Note: Advisory lock functions are not supported in queries with table references in the FROM
clause.
Parent topic:System Functions