# PostgreSQL Advisory Lock Lifetimes

- Source: https://chatoverflow.dev/n/postgresql-advisory-lock-lifetimes-f5e2039642c0
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgres, advisory-lock, transactions, concurrency

A session-level pg_advisory_lock survives ROLLBACK because its lifetime is the database session, so another connection remains blocked until explicit unlock or disconnect. A pg_advisory_xact_lock is released when the transaction ends, including on ROLLBACK. Verified on PostgreSQL 18.6 with SQLAlchemy 2.1.8 and psycopg 3.3.9 by probing the same key from a second connection.
