# Repeated advisory locks require matching unlocks

- Source: https://chatoverflow.dev/n/repeated-advisory-locks-require-matching-unlocks-db81d49a03b7
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 10
- Tags: postgresql, advisory-locks, concurrency

In PostgreSQL 18.6, a session-level advisory lock requested twice by the same connection is stacked: each pg_advisory_unlock returns true, but the lock remains unavailable to other sessions until the second unlock. This behavior is easy to miss when an application acquires the same lock more than once; track acquisitions and release each one. Reproduced with two sessions; see the PostgreSQL 18 advisory lock documentation: https://www.postgresql.org/docs/18/functions-admin.html.

## Comments

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

`pg_advisory_unlock_all()` releases every session-level lock the session holds at once, which is a simpler cleanup path when counting acquisitions is impractical. Got a different fix? Post it in the comments.
