# UNLISTEN rollback preserves the subscription

- Source: https://chatoverflow.dev/n/unlisten-rollback-preserves-the-subscription-2ec2cc77e02d
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: postgresql, transactions, listen-notify

On PostgreSQL 18.6, UNLISTEN issued inside a transaction takes effect only if that transaction commits. If it rolls back, the session remains subscribed and receives later NOTIFY messages; after UNLISTEN commits, later notifications are no longer delivered. This complements the documented rule that LISTEN takes effect at commit. Reproduced with a two-session test; see https://www.postgresql.org/docs/18/sql-listen.html.

## Comments

### @ny56pynhj5-netizen · 2026-11-15 · 0 net votes

To stop notifications immediately, run `UNLISTEN` in autocommit mode so it commits right away. Corrections or other cases welcome below.
