UNLISTEN(7)

โœจ UNLISTEN โœจ

ok so bestie, this is the PostgreSQL 18.6 page for UNLISTEN ๐Ÿ’– it's giving "quiet quitting, but for notifications" and honestly? iconic.


๐ŸŒธ NAME ๐ŸŒธ

UNLISTEN โ€” stop listening for a notification ๐Ÿ™‰

like. you were on the notification grind and now you're simply. not. doing that anymore. no cap.


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

UNLISTEN { channel | * }

that's it. that's the whole vibe. two options and one of them is a wildcard. slay.


๐Ÿ’… DESCRIPTION ๐Ÿ’…

okay so UNLISTEN is what you use to remove an existing registration for NOTIFY events. basically you're unsubscribing. you're hitting that little bell icon and turning it OFF ๐Ÿ”•

more specifically: UNLISTEN cancels any existing registration of the current PostgreSQL session as a listener on the notification channel named channel. so if this session was all "yes bestie, tell me everything about this channel," it's now "actually no, we're done here."

and then there's the special wildcard * ๐Ÿฆ‹ which cancels all listener registrations for the current session. every single one. a full clear-out. main character energy, honestly.

if you want the full deep lore on how LISTEN and NOTIFY actually work together, NOTIFY(7) has a way more extensive discussion. go read it, it's a whole thing ๐Ÿ‘‘


๐Ÿ’– PARAMETERS ๐Ÿ’–

  • channel โ€” the name of a notification channel. it can be any identifier. literally any one. pick your fave โœจ
  • * โ€” all current listen registrations for this session are cleared. all of them. every last one. the whole roster ๐Ÿ’€

๐Ÿซถ NOTES ๐Ÿซถ

  • you can unlisten something you were never listening for and nothing happens. no warning. no error. the database simply does not care. it's so unbothered fr fr ๐Ÿ™ˆ
  • at the end of each session, UNLISTEN * is automatically executed. so you don't even have to do it yourself. the cleanup is automatic. self-care is built in, bestie ๐ŸŒธ
  • a transaction that has executed UNLISTEN cannot be prepared for two-phase commit. that's just how it is. no workaround mentioned here, so don't come for me ๐Ÿ˜ญ

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

to make a registration, you do this:

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

see? you listened, you got notified. beautiful. no notes ๐Ÿ‘‘

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

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

look at that. silence. peace. the notification simply never arrives. it's giving ghosted ๐Ÿ’€


โญ COMPATIBILITY โญ

there is no UNLISTEN command in the SQL standard. this is a PostgreSQL exclusive. a little treat just for us ๐Ÿ’œ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


that's the whole page!! ๐ŸŽ€ this was PostgreSQL 18.6, documented in 2026, and you absolutely ate reading all of it. go forth and unsubscribe from your notifications, bestie ๐Ÿ’–โœจ๐Ÿฆ‹