UNLISTEN(7)

πŸ“¦ version 13.23, in opensuse-leap 16.0

πŸ’… UNLISTEN(7) β€” the postgres manual, but make it group chat

ok so real quick β€” this is the UNLISTEN page from the PostgreSQL 13.23 documentation, and we're about to make it make sense. no cap. 🫢


✨ NAME ✨

UNLISTEN β€” stop listening for a notification πŸ’€


🌸 SYNOPSIS 🌸

UNLISTEN { channel | * }

πŸ¦‹ DESCRIPTION πŸ¦‹

k so bestie, UNLISTEN is literally how you remove a registration you already made for NOTIFY events. it cancels any existing registration of the current PostgreSQL session as a listener on the notification channel named channel. like, you're unsubscribing. self-care honestly. πŸ’…

and then there's the special wildcard * β€” that one cancels all listener registrations for the current session. every single one. it's giving mass-unfollow. πŸ”₯

if you want the whole extensive discussion of how LISTEN and NOTIFY work together, that lives in NOTIFY(7). go read it. iykyk. πŸ“–


πŸŽ€ PARAMETERS πŸŽ€

  • channel β€” name of a notification channel (any identifier). literally any identifier, she's flexible. ✨
  • * β€” all current listen registrations for this session are cleared. all of them. gone. πŸ‘‘

πŸ’€ NOTES πŸ’€

bestie listen β€” you can UNLISTEN something you were never listening for. no warning. no error. it just… happens. the server does not care and will not tell you. πŸ™ˆ

at the end of each session, UNLISTEN * is automatically executed. so your session cleans up after itself whether you like it or not. 🧚

⚠️ a transaction that has executed UNLISTEN cannot be prepared for two-phase commit. like, that's just how it is. plan accordingly. 😭

πŸ”₯ EXAMPLES πŸ”₯

to make a registration, you do this:

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

and once UNLISTEN has been executed, further NOTIFY messages will be ignored. ignored!! she does not see them. πŸ’€

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

🌈 COMPATIBILITY 🌈

there is no UNLISTEN command in the SQL standard. she's built different. a postgres original. πŸ’œ


⭐ SEE ALSO ⭐

LISTEN(7), NOTIFY(7)


and that's the whole page bestie πŸŽ‰ β€” brought to you by PostgreSQL 13.23, dated 2025, aka the UNLISTEN(7) era. go forth and stop listening to things. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from