> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/reference/sql-commands/sql-unlisten.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# UNLISTEN

### UNLISTEN

UNLISTEN — 停止接聽某個通知頻道

### 語法

```

UNLISTEN { channel | * }
```

### 說明

`UNLISTEN` 用來移除既有的 `NOTIFY` 事件註冊。 `UNLISTEN` 會取消目前 PostgreSQL 工作階段 作為指定 *`channel`* 通知頻道的接聽者的既有註冊。特殊萬用字元 `*` 會取消目前工作階段的所有接聽註冊。

[NOTIFY](https://docs.postgresql.tw/19/reference/sql-commands/sql-notify.md) 針對 `LISTEN` 與 `NOTIFY` 的使用方式有更詳盡的討論。

### 參數

*`channel`* : 通知頻道的名稱（任意識別字）。

`*` : 清除此工作階段的所有目前接聽註冊。

### 注意事項

你可以對未曾接聽的頻道執行 unlisten，不會出現任何警告或錯誤。

每個工作階段結束時，都會自動執行 `UNLISTEN *`。

已執行過 `UNLISTEN` 的交易無法被準備用於 兩階段提交。

### 範例

建立一個註冊：

```

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

一旦執行了 `UNLISTEN`，之後的 `NOTIFY` 訊息就會被忽略：

```

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

### 相容性

SQL 標準中沒有 `UNLISTEN` 指令。

### 參見

[LISTEN](https://docs.postgresql.tw/19/reference/sql-commands/sql-listen.md), [NOTIFY](https://docs.postgresql.tw/19/reference/sql-commands/sql-notify.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-unlisten.html)（原文版本：18.6；核對日期：2026-09-28）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/reference/sql-commands/sql-unlisten.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
