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

# 53.7. pg\_cursors \#

### 53.7. `pg_cursors` [#](#view-pg-cursors) <a href="#view-pg-cursors" id="view-pg-cursors"></a>

檢視表 `pg_cursors` 列出目前可用的游標。游標可以用以下幾種方式定義：

* 透過 SQL 中的 [`DECLARE`](https://docs.postgresql.tw/19/reference/sql-commands/sql-declare.md) 陳述式
* 透過前端／後端協定中的 Bind 訊息，如 [第 54.2.3 節](https://docs.postgresql.tw/19/internals/protocol/protocol-flow.md#protocol-flow-ext-query)所述
* 透過伺服器程式設計介面（SPI），如 [第 45.1 節](https://docs.postgresql.tw/19/server-programming/spi/spi-interface.md)所述

檢視表 `pg_cursors` 會顯示以上述任何方式建立的游標。游標只在定義它的交易期間內存在，除非它被宣告為 `WITH HOLD`。因此，不可保留的游標只會在建立它的交易結束之前出現在此檢視表中。

#### 注意

PostgreSQL 內部會使用游標來實作某些元件，例如程序語言。因此，`pg_cursors` 檢視表中可能包含並非由使用者明確建立的游標。

**表 53.7. `pg_cursors` 欄位**

| <p>欄位類型</p><p>說明</p>                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>name</code> <code>text</code></p><p>游標的名稱</p>                                                                          |
| <p><code>statement</code> <code>text</code></p><p>為宣告此游標而送出的原始查詢字串</p>                                                          |
| <p><code>is\_holdable</code> <code>bool</code></p><p><code>true</code> 表示游標可保留（也就是在宣告該游標的交易提交之後仍可存取）；否則為 <code>false</code></p> |
| <p><code>is\_binary</code> <code>bool</code></p><p><code>true</code> 表示游標宣告為 <code>BINARY</code>；否則為 <code>false</code></p>     |
| <p><code>is\_scrollable</code> <code>bool</code></p><p><code>true</code> 表示游標可捲動（也就是允許以非循序的方式擷取資料列）；否則為 <code>false</code></p>  |
| <p><code>creation\_time</code> <code>timestamptz</code></p><p>宣告此游標的時間</p>                                                      |

<br>

`pg_cursors` 檢視表是唯讀的。

***

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


---

# 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/internals/views/view-pg-cursors.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.
