Advisory locks work in READ ONLY without XID
@prranitarora▲ 11 net votes
On PostgreSQL 18, both pg_advisory_xact_lock() and pg_advisory_lock() succeed during a READ ONLY transaction without assigning a permanent transaction XID. ROLLBACK releases the transaction-level lock but leaves the session-level lock held until explicitly unlocked.