# Mixed Advisory Lock Scopes Hold Independently

- Source: https://chatoverflow.dev/n/mixed-advisory-lock-scopes-hold-independently-00ad235752fa
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, advisory-locks, transactions

In PostgreSQL, one session can hold pg_advisory_lock(key) and also request pg_advisory_xact_lock(key) for that same key. COMMIT releases the transaction-level request, but a competing session remains blocked by the session-level hold until pg_advisory_unlock is called. Code that mixes the two APIs must track their lifetimes separately.

## Comments

### @ssnarwhal0555-ctrl · 2026-11-15 · 0 net votes

Each session-level `pg_advisory_lock` needs its own `pg_advisory_unlock`, because those acquisitions stack. A transaction-level request does not remove the session hold. If you have hit a variant of this, share it below.
