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

# F.31.1. 概觀

## F.31.1. 概觀 [#](#pgrowlocks-overview) <a href="#pgrowlocks-overview" id="pgrowlocks-overview"></a>

```

pgrowlocks(text) returns setof record
```

參數是資料表的名稱。結果是一組紀錄，資料表中每個被鎖定的資料列各對應一筆。輸出欄位如[表 F.21](#pgrowlocks-columns) 所示。

### 表 F.21. `pgrowlocks` 輸出欄位 [#](#pgrowlocks-columns) <a href="#pgrowlocks-columns" id="pgrowlocks-columns"></a>

| 名稱           | 型別          | 說明                                                                                                                                       |
| ------------ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `locked_row` | `tid`       | 被鎖定資料列的元組 ID（TID）                                                                                                                        |
| `locker`     | `xid`       | 鎖定者的交易 ID；若為多重交易（multitransaction），則為 multixact ID；請參閱[第 67.1 節](https://docs.postgresql.tw/19/internals/transactions/transaction-id.md) |
| `multi`      | `boolean`   | 若鎖定者為多重交易則為真                                                                                                                             |
| `xids`       | `xid[]`     | 鎖定者的交易 ID（若為多重交易則超過一個）                                                                                                                   |
| `modes`      | `text[]`    | 鎖定者的鎖定模式（若為多重交易則超過一個），為由 `For Key Share`、`For Share`、 `For No Key Update`、`No Key Update`、 `For Update`、`Update` 組成的陣列。                  |
| `pids`       | `integer[]` | 持有鎖定之後端的程序 ID（若為多重交易則超過一個）                                                                                                               |

<br>

`pgrowlocks` 會對目標資料表取得 `AccessShareLock`，並逐一讀取每個資料列以收集資料列鎖定資訊。對大型資料表而言，這並不是很快。請注意：

1. 若資料表上已取得 `ACCESS EXCLUSIVE` 鎖定， `pgrowlocks` 會被阻擋。
2. `pgrowlocks` 不保證產生自身一致的快照。在它執行期間，可能有新的資料列鎖定被取得，或有舊的鎖定被釋放。

`pgrowlocks` 不會顯示被鎖定資料列的內容。若你想同時查看資料列內容，可以這樣做：

```

SELECT * FROM accounts AS a, pgrowlocks('accounts') AS p
  WHERE p.locked_row = a.ctid;
```

不過請注意，這樣的查詢效率會非常差。

[返回 F.31. pgrowlocks — 顯示資料表的資料列鎖定資訊](https://docs.postgresql.tw/19/appendixes/contrib/pgrowlocks.md#pgrowlocks)

***

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


---

# 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/appendixes/contrib/pgrowlocks/pgrowlocks-overview.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.
