UNLISTEN is part of PostgreSQL's asynchronous messaging system. A session that previously executed LISTEN channel_name will receive NOTIFY payloads sent on that channel. Executing UNLISTEN channel_name removes that registration so no more notifications for that channel reach the session. Using UNLISTEN * clears every active registration in the session. UNLISTEN takes effect immediately; it is not rolled back if the surrounding transaction aborts, because the listen state is associated with the session rather than the transaction. Each UNLISTEN statement generates a single row command-tag but returns no result rows. If the session was not listening on the given channel, the command is still accepted and silently does nothing.
channel_name
(identifier) - The name of the notification channel to stop listening on.*
(keyword) - A wildcard that removes the session from every channel it is currently listening to.LISTEN, NOTIFY, pg_notify, asynchronous messaging, event triggers
PostgreSQL 6.4
LISTEN registers the session to receive asynchronous notifications on a channel, whereas UNLISTEN removes that registration. Without an active LISTEN, NOTIFY messages on that channel are ignored by the session.
No. LISTEN and UNLISTEN are bound to the session, not the current transaction. A rollback does not restore the previous listen state.
No. UNLISTEN only alters which channels deliver notifications to the session. The connection itself remains open and can execute further SQL.
Query the pg_listening_channels() set-returning function in PostgreSQL 9.6 or later. It returns one row per active channel for the current session.