↑↓ select ↵ open ⌫ change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

SQL Commands / Sessions & Settings

stop listening for a notification

Reading PG 18current·documented in 30 of 30 versions, 6.4 to 20

Syntax

UNLISTEN { channel | * }
Syntax diagrams

Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.

UNLISTEN channel *

Description

UNLISTEN is used to remove an existing registration for NOTIFY events. UNLISTEN cancels any existing registration of the current PostgreSQL session as a listener on the notification channel named channel. The special wildcard * cancels all listener registrations for the current session.

NOTIFY contains a more extensive discussion of the use of LISTEN and NOTIFY.

Parameters

channel

Name of a notification channel (any identifier).

*

All current listen registrations for this session are cleared.

Notes

You can unlisten something you were not listening for; no warning or error will appear.

At the end of each session, UNLISTEN * is automatically executed.

A transaction that has executed UNLISTEN cannot be prepared for two-phase commit.

Examples

To make a registration:

LISTEN virtual;
NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448.

Once UNLISTEN has been executed, further NOTIFY messages will be ignored:

UNLISTEN virtual;
NOTIFY virtual;
-- no NOTIFY event is received

Compatibility

There is no UNLISTEN command in the SQL standard.

See Also

LISTEN, NOTIFY
Version history 7
  1. 8.4 → 9.0 changed
  2. 8.2 → 8.3 changed
  3. 7.3 → 7.4 changed
  4. 7.2 → 7.3 changed
  5. 7.1 → 7.2 changed
  6. 7.0 → 7.1 changed
  7. 6.5 → 7.0 changed

Related entries

Definition snapshot: b7bd9cda · English manual source