> 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/the-sql-language/functions/functions-admin/functions-admin-signal.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 9.28.2. 伺服器訊號函式

## 9.28.2. 伺服器訊號函式 [#](#functions-admin-signal) <a href="#functions-admin-signal" id="functions-admin-signal"></a>

[表 9.96](#functions-admin-signal-table) 所列的函式會向其他伺服器程序傳送控制訊號。這些函式預設只限超級使用者使用，但可以使用 `GRANT` 將存取權授予其他使用者，另有註明的例外情形除外。

這些函式在訊號傳送成功時都會回傳 `true`，傳送失敗時則回傳 `false`。

### 表 9.96. 伺服器訊號函式 [#](#functions-admin-signal-table) <a href="#functions-admin-signal-table" id="functions-admin-signal-table"></a>

| <p>函式</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>pg\_cancel\_backend</code> ( <em><code>pid</code></em> <code>integer</code> ) → <code>boolean</code></p><p>取消其後端程序具有指定程序 ID 之工作階段目前的查詢。如果呼叫的角色是被取消之後端所屬角色的成員，或呼叫的角色具有 <code>pg\_signal\_backend</code> 的權限，也可以執行此操作，但只有超級使用者可以取消超級使用者的後端。例外的是，具有 <code>pg\_signal\_autovacuum\_worker</code> 權限的角色可以取消 autovacuum 工作程序，這些程序在其他情況下會被視為超級使用者的後端。</p>                                                                                                                                                                                                                                                                                                                                |
| <p><code>pg\_log\_backend\_memory\_contexts</code> ( <em><code>pid</code></em> <code>integer</code> ) → <code>boolean</code></p><p>請求將具有指定程序 ID 之後端的記憶體內容記錄到日誌中。這個函式可以將請求傳送給 logger 以外的後端與輔助程序。這些記憶體內容會以 <code>LOG</code> 訊息層級記錄。它們會依照所設定的日誌組態出現在伺服器日誌中（更多資訊請參閱<a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-logging.md">第 19.8 節</a>），但無論 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-client.md#GUC-CLIENT-MIN-MESSAGES">client\_min\_messages</a> 如何設定，都不會傳送給用戶端。</p>                                                                                                                        |
| <p><code>pg\_reload\_conf</code> () → <code>boolean</code></p><p>讓 PostgreSQL 伺服器的所有程序重新載入它們的組態檔案。（這是透過向 postmaster 程序傳送 SIGHUP 訊號來啟動的，postmaster 接著會向它的每個子程序傳送 SIGHUP。）在重新載入之前，你可以使用 <a href="https://docs.postgresql.tw/19/internals/views/view-pg-file-settings.md"><code>pg\_file\_settings</code></a>、<a href="https://docs.postgresql.tw/19/internals/views/view-pg-hba-file-rules.md"><code>pg\_hba\_file\_rules</code></a> 與 <a href="https://docs.postgresql.tw/19/internals/views/view-pg-ident-file-mappings.md"><code>pg\_ident\_file\_mappings</code></a> 檢視表來檢查組態檔案中可能的錯誤。</p>                                                                                               |
| <p><code>pg\_rotate\_logfile</code> () → <code>boolean</code></p><p>向日誌檔案管理程序發出訊號，要求它立即切換到新的輸出檔案。這只有在內建的日誌收集器正在執行時才有作用，因為否則就不會有日誌檔案管理子程序。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| <p><code>pg\_terminate\_backend</code> ( <em><code>pid</code></em> <code>integer</code>, <em><code>timeout</code></em> <code>bigint</code> <code>DEFAULT</code> <code>0</code> ) → <code>boolean</code></p><p>終止其後端程序具有指定程序 ID 的工作階段。如果呼叫的角色是被終止之後端所屬角色的成員，或呼叫的角色具有 <code>pg\_signal\_backend</code> 的權限，也可以執行此操作，但只有超級使用者可以終止超級使用者的後端。例外的是，具有 <code>pg\_signal\_autovacuum\_worker</code> 權限的角色可以終止 autovacuum 工作程序，這些程序在其他情況下會被視為超級使用者的後端。</p><p>如果未指定 <em><code>timeout</code></em> 或其值為零，無論程序是否真的終止，這個函式都會回傳 <code>true</code>，這只表示訊號已成功傳送。如果有指定 <em><code>timeout</code></em>（以毫秒為單位）且大於零，函式會等到程序真正終止或經過指定的時間為止。如果程序已終止，函式會回傳 <code>true</code>。逾時的話，會發出警告並回傳 <code>false</code>。</p> |

<br>

`pg_cancel_backend` 與 `pg_terminate_backend` 會向以程序 ID 指定的後端程序傳送訊號（分別是 SIGINT 或 SIGTERM）。作用中後端的程序 ID 可以從 `pg_stat_activity` 檢視表的 `pid` 欄位查得，或是列出伺服器上的 `postgres` 程序（在 Unix 上使用 ps，在 Windows 上使用工作管理員）。作用中後端的角色可以從 `pg_stat_activity` 檢視表的 `usename` 欄位查得。

`pg_log_backend_memory_contexts` 可用來將某個後端程序的記憶體內容（memory context）記錄到日誌中。例如：

```

postgres=# SELECT pg_log_backend_memory_contexts(pg_backend_pid());
 pg_log_backend_memory_contexts
--------------------------------
 t
(1 row)
```

每個記憶體內容會記錄一則訊息。例如：

```

LOG:  logging memory contexts of PID 10377
STATEMENT:  SELECT pg_log_backend_memory_contexts(pg_backend_pid());
LOG:  level: 1; TopMemoryContext: 80800 total in 6 blocks; 14432 free (5 chunks); 66368 used
LOG:  level: 2; pgstat TabStatusArray lookup hash table: 8192 total in 1 blocks; 1408 free (0 chunks); 6784 used
LOG:  level: 2; TopTransactionContext: 8192 total in 1 blocks; 7720 free (1 chunks); 472 used
LOG:  level: 2; RowDescriptionContext: 8192 total in 1 blocks; 6880 free (0 chunks); 1312 used
LOG:  level: 2; MessageContext: 16384 total in 2 blocks; 5152 free (0 chunks); 11232 used
LOG:  level: 2; Operator class cache: 8192 total in 1 blocks; 512 free (0 chunks); 7680 used
LOG:  level: 2; smgr relation table: 16384 total in 2 blocks; 4544 free (3 chunks); 11840 used
LOG:  level: 2; TransactionAbortContext: 32768 total in 1 blocks; 32504 free (0 chunks); 264 used
...
LOG:  level: 2; ErrorContext: 8192 total in 1 blocks; 7928 free (3 chunks); 264 used
LOG:  Grand total: 1651920 bytes in 201 blocks; 622360 free (88 chunks); 1029560 used
```

如果同一個父內容之下有超過 100 個子內容，就會記錄前 100 個子內容，並附上其餘內容的摘要。請注意，頻繁呼叫這個函式可能會造成顯著的額外負擔，因為它可能產生大量的日誌訊息。

[返回 9.28. 系統管理函式](https://docs.postgresql.tw/19/the-sql-language/functions/functions-admin.md#functions-admin)

***

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


---

# 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/the-sql-language/functions/functions-admin/functions-admin-signal.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.
