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

# 13.7. 鎖定與索引 \#

### 13.7. 鎖定與索引 [#](#locking-indexes) <a href="#locking-indexes" id="locking-indexes"></a>

雖然 PostgreSQL 為資料表資料提供非阻擋式的讀寫存取，但目前並不是 PostgreSQL 中實作的每一種索引存取方法都提供非阻擋式的讀寫存取。各種索引類型的處理方式如下：

B-tree、GiST 與 SP-GiST 索引 : 讀寫存取會使用短期的共享／排他頁面層級鎖定。每一筆索引資料列被取出或插入之後，鎖定就會立即釋放。這些索引類型提供最高的並行性，而且不會發生死結。

雜湊索引 : 讀寫存取會使用共享／排他的雜湊桶層級鎖定。整個雜湊桶處理完之後才會釋放鎖定。雜湊桶層級的鎖定比索引層級的鎖定提供更好的並行性，但由於鎖定持有的時間比一次索引操作更長，因此可能發生死結。

GIN 索引 : 讀寫存取會使用短期的共享／排他頁面層級鎖定。每一筆索引資料列被取出或插入之後，鎖定就會立即釋放。但請注意，插入一個以 GIN 建立索引的值，通常會為每一筆資料列產生多次索引鍵的插入，因此 GIN 可能會為單一值的插入做相當多的工作。

目前，B-tree 索引為並行應用程式提供最佳的效能；由於它們也比雜湊索引具備更多功能，因此是需要為純量資料建立索引之並行應用程式的建議索引類型。處理非純量資料時，B-tree 並不適用，應改用 GiST、SP-GiST 或 GIN 索引。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/locking-indexes.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/mvcc/locking-indexes.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.
