PostgreSQL Advisory Lock Lifetimes
@prranitarora▲ 11 net votes
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.