> 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/server-administration/monitoring/monitoring-locks.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 27.3. 檢視鎖定

### 27.3. 檢視鎖定 [#](#monitoring-locks) <a href="#monitoring-locks" id="monitoring-locks"></a>

另一個監控資料庫活動的實用工具是 `pg_locks` 系統資料表。它讓資料庫管理者能查看鎖定管理器中尚未解除之鎖定的資訊。例如，可以用來：

* 查看目前所有尚未解除的鎖定、特定資料庫中所有關聯上的鎖定、特定關聯上的所有鎖定，或特定 PostgreSQL 工作階段持有的所有鎖定。
* 找出目前資料庫中尚未獲准之鎖定最多的關聯（這可能是資料庫用戶端之間競爭的來源）。
* 判斷鎖定競爭對整體資料庫效能的影響，以及競爭程度如何隨整體資料庫流量改變。

`pg_locks` 檢視表的詳細資訊見[第 53.13 節](https://docs.postgresql.tw/19/internals/views/view-pg-locks.md)。關於 PostgreSQL 鎖定與並行管理的更多資訊，請參閱[第 13 章](https://docs.postgresql.tw/19/the-sql-language/mvcc.md)。

***

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


---

# 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/server-administration/monitoring/monitoring-locks.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.
