UNLISTEN(7)
π UNLISTEN(7) β the "okay bestie, unsubscribe me" command
So like, this page is from the PostgreSQL 16.15 Documentation, and the whole vibe is: how to stop listening for a notification. Yes babes, we're doing unsubscribing, but for Postgres. π
β¨ SYNOPSIS β¨
UNLISTEN { channel | * }
That's it. That's the whole thing. Two ways to say bye π
π¦ DESCRIPTION π¦
Okay so UNLISTEN is literally how you remove an existing registration for NOTIFY events. Like, the notification finds your address in the system and this command is you moving out without leaving a forwarding address. π
UNLISTEN cancels any existing registration of the current PostgreSQL session as a listener on the notification channel named channel. So if your session was signed up for that channel, it's not anymore. Periodt.
The special wildcard * cancels all listener registrations for the current session. All of them. Every single one. One shot, clean slate, no survivors, iconic. π₯
And if you want the full lore β the whole deep-dive discussion of how LISTEN and NOTIFY actually work together β that lives in NOTIFY(7). Go read it, it's giving essential context. π
π PARAMETERS π
channelβ Name of a notification channel (any identifier). Any identifier, bestie. Doesn't have to be fancy, doesn't have to be special, just has to be a name.*β All current listen registrations for this session are cleared. Every last one. π§Ή
πΈ NOTES πΈ (read these, fr fr)
- You can unlisten something you were not listening for; no warning or error will appear. Like, you can unsubscribe from a newsletter you never signed up for and Postgres will simply not make it weird. No drama, no error, nothing. π
- At the end of each session,
UNLISTEN *is automatically executed. Automatic cleanup! The server does the tidying for you because it's a considerate king. π - A transaction that has executed
UNLISTENcannot be prepared for two-phase commit. Yeah, that's a real limitation, not a vibe. Keep it in mind. π
Ngl, that last one matters if you're doing fancy distributed transaction stuff β UNLISTEN inside a transaction means that transaction can't go two-phase. Not a bug, just the rules.
π EXAMPLES π
First, to make a registration (yes we're doing the before picture):
LISTEN virtual;
NOTIFY virtual;
Asynchronous notification "virtual" received from server process with PID 8448.
See? You listened, you got the notification, everything slayed. β¨
Once UNLISTEN has been executed, further NOTIFY messages will be ignored:
UNLISTEN virtual;
NOTIFY virtual;
-- no NOTIFY event is received
Nothing arrives. Silence. The notification is yelling into the void and the void has left the group chat. π
π COMPATIBILITY π
There is no UNLISTEN command in the SQL standard. It's a Postgres original, a main character invention, and honestly? We love that for it. π«Ά
β SEE ALSO β
Go forth and read them in that order, iykyk.
kisses bestie, this page was PostgreSQL 16.15, dated 2026 β the UNLISTEN(7) era, and you ate π
β¨π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql16 16.15-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms