# UNLISTEN

UNLISTEN — 停止監聽通知

### 語法

```
UNLISTEN { channel | * }
```

### 說明

UNLISTEN 用於移除現有已註冊的 NOTIFY 事件。UNLISTEN 取消目前 PostgreSQL 連線的任何現有註冊，名稱為 channel 的通知通道上的監聽器。特殊符號 \* 為取消目前連線已註冊的所有監聽器。

[NOTIFY](/15/reference/sql-commands/notify.md) 包含了對 LISTEN 和 NOTIFY 使用上更廣泛的討論。

### 參數

*`channel`*

通知通道的名稱（任何標識字）。

`*`

清除此連線目前已註冊的所有監聽。

### 注意

你可以取消你不要監聽的東西；不會出現警告或錯誤。

在每個連線結束時，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](/15/reference/sql-commands/listen.md), [NOTIFY](/15/reference/sql-commands/notify.md)


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

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

The question should be specific, self-contained, and written in natural language.
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.
